Solved

SetForegroundWindow() VB5/NT4 question

Posted on 1998-07-15
3
213 Views
Last Modified: 2012-06-27
I am trying to capture a window of another running program to a bitmap.
I am using the code below to try to create a bitmap of the NT Calculator
accessory. CaptureWindow() is from the Knowlege base article Q161299
and seems to capture the correct part of the screen.
SetForegroundWindow is returning 0 (the error return) and so if my application's
window is in front of the calculator window, I get that in my bitmap.
Anybody used SetForegroundWindow() and have any tips?

Dim hWndActive As Long
Dim hWndOld As Long
Dim blnRet As Boolean
Dim RectActive As RECT
Dim r As Long

hWndOld = GetForegroundWindow()
hWndActive = FindWindow(0&, m_sCaption)

r = GetWindowRect(hWndActive, RectActive)

blnRet = SetForegroundWindow(hWndActive)
Set Picture1 = CaptureWindow(hWndActive, False, 0, 0, _
   RectActive.Right - RectActive.Left, _
   RectActive.Bottom - RectActive.Top)
                             
blnRet = SetForegroundWindow(hWndOld)

0
Comment
Question by:mark_s
  • 2
3 Comments
 
LVL 1

Expert Comment

by:wford
Comment Utility
what error do you get when you call GetLastError after the call:

Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As Long

and is your setforground window declare:

Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long


0
 

Author Comment

by:mark_s
Comment Utility
> Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

I forgot the ByVal - That explains why it doesn't work - thanks wford.

If you're an expert, answer the question and I'll grade you, otherwise I'll delete the question.
0
 
LVL 1

Accepted Solution

by:
wford earned 100 total points
Comment Utility
answered as asked.

it seems 80% of the problem with API's is geting the declare right, the rest is figureing out the option values
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now