Solved

SetForegroundWindow() VB5/NT4 question

Posted on 1998-07-15
3
223 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help in WHSCRIPT 9 47
Determine Range to Select 5 42
How to Add / Edit Windows Menu 4 51
Protecting vb6 & .Net code Obfuscation 18 95
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

910 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

24 Experts available now in Live!

Get 1:1 Help Now