Solved

SetForegroundWindow() VB5/NT4 question

Posted on 1998-07-15
3
239 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
ID: 1465792
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
ID: 1465793
> 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
ID: 1465794
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 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