Hi

I have a problem I didn't find a good solution for yet. I need to
bring the application window in foreground in following scenario:

The user double clicks the desktop icon and the launcher kicks in. It
checks if there's a new version, updates the local exe if necessary
then launches the application's exe. Somehow the app's window,
although it has the focus (I mean if you press Alt+F the File menu
opens) it is not the top-most form. The title bar is not blue and if
any other application window was already open on the desktop (such as
Notepad, for example), my application's window is placed underneath.
In other words the keystrokes are sent to my application, it is
active, but it is not the top form. I couldn't find a good solution
for this issue yet and it's driving me crazy.

My current code is shown below. The API calls are wrapped in their own
classes and the names are self explanatory, but I can show the code in
those classes if required. The classes actually just declare the API
functions and call them by passing the parameters along. Can anyone
shed some light, please?

**********************************************************************
* Program....: B-Proceduri.ForceForegroundWindow
* Version....:
* Author.....: Grigore Dolghin
* Date.......: 05 January 2010, 17:44:37
* Notice.....: Copyright © 2010, Class Software
* Compiler...: Visual FoxPro 09.00.0000.5815 for Windows
* Abstract...:
* Changes....: Grigore Dolghin, Created 05 January 2010 / 17:44:37
* Parameters.:
* Called by..:
* Purpose....: Forces the main desktop window in foreground:
**********************************************************************
Local ;
        lnWindowHandle As Integer, ;
        lnForeThread As Integer, ;
        lnAppThread As Integer

With This
        lnWindowHandle = App.ApiMgr.Windows.FindWindow(_Screen.Caption)
        If lnWindowHandle > 0
                lnForeThread =
App.ApiMgr.Windows.GetWindowThreadProcessId(App.ApiMgr.Windows.GetForeGroundWindow(),0)
                lnAppThread = 
App.ApiMgr.ProcessesAndThreads.GetCurrentThreadId()

                If lnForeThread <> lnAppThread
                        
App.ApiMgr.ProcessesAndThreads.AttachThreadInput(lnForeThread,
lnAppThread, .T.)
                        App.ApiMgr.Windows.BringWindowToTop(lnWindowHandle)
                        App.ApiMgr.Windows.ShowWindow(lnWindowHandle, 3)
                        
App.ApiMgr.ProcessesAndThreads.AttachThreadInput(lnForeThread,
lnAppThread, .F.)
                Else
                        App.ApiMgr.Windows.BringWindowToTop(lnWindowHandle)
                        App.ApiMgr.Windows.ShowWindow(lnWindowHandle, 3)
                EndIf
        EndIf
EndWith

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to