?
Solved

SetForegroundWindow() VB5/NT4 question

Posted on 1998-07-15
3
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

741 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