SetForegroundWindow() VB5/NT4 question
Posted on 1998-07-15
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)