INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site
(Download This Button Today!)
"...My thanks to the contributors who freely share their knowledge and enthusiasms. This forum restores some
measure of my faith in human nature..."
Where in the world do Tek-Tips members come from?
Force Window to Front (not blink in taskbar)
Posted: 4 Oct 03 (Edited 18 Feb 05)
Slighthaze = NULL
You may have noticed that when you try and bring your application's window to the front using API calls (SetForeGroundWindow and BringWindowToTop) that it just blinks down in the taskbar. This applies to Windows 2000 and later Microsoft OS's (see MS Documentation below). Well, if you would rather have your applicaiton's window truly come to the front (and I'm sure you do) then here's a VFP workaround using API calls.
MS Documentation for SetForegroundWindow reads as follows:
"Windows NT 5.0 and later: An application cannot force a window to the foreground while the user is working with another window. Instead, SetForegroundWindow will activate the window (see SetActiveWindow) and call the FlashWindowEx function to notify the user."
...and it appears that the same is true for BringWindowToTop.
The only way Windows 2000 and Windows XP let you bring your application's window up to the front is if the thread it is running on is the thread of the foreground window at the time. So, you have to attach the thread of your application to the thread of the foreground window and then bring your application's window to the front. After that you need to detach your thread (this all only happens if the user has another application's window as the foreground active window). It looks like a lot, but really we are just tricking Windows into thinking that our application window is part of the foreground application so that it will let us bring our window up to the front rather than having it just blink in the taskbar. The key to this whole thing is the AttachThreadInput API calls.
DECLARE Long FindWindow In Win32API String, String
nHWND = FindWindow(Null,_screen.caption)
If nHWND >0
LOCAL nForeThread, nAppThread
nForeThread = GetWindowThreadProcessId(GetForegroundWindow(), 0)
nAppThread = GetCurrentThreadId()
IF nForeThread != nAppThread
AttachThreadInput(nForeThread, nAppThread, .T.)
AttachThreadInput(nForeThread, nAppThread, .F.)
*!* DECLARE INTEGER SetForegroundWindow IN user32 INTEGER hwnd
DECLARE Long BringWindowToTop In Win32API Long
DECLARE Long ShowWindow In Win32API Long, Long
DECLARE INTEGER GetCurrentThreadId;
DECLARE INTEGER GetWindowThreadProcessId IN user32;
INTEGER @ lpdwProcId
DECLARE INTEGER GetCurrentThreadId;
DECLARE INTEGER AttachThreadInput IN user32 ;
INTEGER idAttach, ;
INTEGER idAttachTo, ;
DECLARE INTEGER GetForegroundWindow IN user32
Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close