Solved

SetForegroundWindow() VB5/NT4 question

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

726 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