![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
I'm trying to use SetForegroundWindow API to show the main window of my application when it is not in foreground. It doesn't work! The applications flashes in the taskbar but doesn't go in foreground. The call works only if my application is first minimized. (System: VFP7 SP1 + Win2000 Pro SP3) -- Andrea Mariottini |
#2
| |||
| |||
|
|
The following is C code to set the foreground window (I know, this is a foxpro newsgroup, but this is pretty simple C). You need to attach your message queue to the current foreground window, if you want to FORCE focus to your app, even if another app is active. Normally, you are not allowed to "steal" focus, but you may have good reason to, so this method will always work. Let me know if you need clarification: // Force a window to front, ripping them away from any current application // Even works on Win98 and up static void ForceWindowToFront(HWND hwndForce) { DWORD nMyProcessId, nCurProcessId; WINDOWPLACEMENT wp; int nShowType; // Maintain "maximized" status when showing ZeroMemory(&wp, sizeof(wp)); wp.length = sizeof(wp); GetWindowPlacement(hwndForce, &wp); switch (wp.showCmd) { case SW_SHOWMAXIMIZED: nShowType = SW_MAXIMIZE; break; default: ShowWindow(hwndForce, SW_RESTORE); break; } // Get process ID of the window and the foreground window nMyProcessId = GetWindowThreadProcessId(hwndForce, 0); nCurProcessId = GetWindowThreadProcessId(GetForegroundWindow(), 0); // Do I need to do the AttachThreadInput trick? if (nMyProcessId != nCurProcessId) { AttachThreadInput(nCurProcessId, nMyProcessId, TRUE); SetForegroundWindow(hwndForce); AttachThreadInput(nCurProcessId, nMyProcessId, FALSE); } if (GetForegroundWindow() != hwndForce) SetForegroundWindow(hwndForce); } "Andrea Mariottini" <a.mariottini (AT) libero (DOT) it> wrote in message news:BA926770.7C0C%a.mariottini (AT) libero (DOT) it... I'm trying to use SetForegroundWindow API to show the main window of my application when it is not in foreground. It doesn't work! The applications flashes in the taskbar but doesn't go in foreground. The call works only if my application is first minimized. (System: VFP7 SP1 + Win2000 Pro SP3) -- Andrea Mariottini |
![]() |
| Thread Tools | |
| Display Modes | |
| |