Information générale
Catégorie:
Fonctions Windows API
Titre:
Application Does Not Redraw After Restore
I've recently jumped head first into using Windows APIs. I want to keep the user from running multiple instances of a particular application. After searching through other threads, FAQs and the like, I've found the solution that I've implemented in my main program. Here it is:
LOCAL m.AppHandle
* Is program already running?
* Use a Windows API call to see if the application is running
* in another window
DECLARE INTEGER FindWindow IN Win32API ;
STRING ClassName, ;
STRING WindowName
m.AppHandle = FindWindow(0, "PROGRAM TITLE")
IF m.AppHandle > 0
* Restore the application, if it happens to be minimized
#DEFINE SW_SHOWNORMAL 1
#DEFINE SW_SHOW 5
#DEFINE SW_MINIMIZE 6
#DEFINE SW_RESTORE 9
DECLARE INTEGER ShowWindow IN User32 ;
INTEGER hwnd, ;
INTEGER nCmdShow
=ShowWindow(m.AppHandle, SW_SHOWNORMAL)
* Update the Window
DECLARE INTEGER UpdateWindow IN User32 ;
INTEGER HWnd ;
=UpdateWindow(m.AppHandle)
* Set the focus to the existing application
DECLARE SHORT SetForegroundWindow IN User32 ;
INTEGER HWND
SetForegroundWindow(m.AppHandle)
* Now, quit this instance
QUIT
ENDIF
All this appears to work correctly in that the 1st instance is restored from its minimized state and the 2nd instance quits. The 1st instance gets the focus, however, the application is not redrawing. I can see the cursor blinking in the middle of the form. When I click where the cursor is blinking, the application redraws the text box it was sitting in, but the rest of the form appears like a snapshot of what was behind it prior to being restored. I can drag the app around the screen and the background still does not refresh or redraw.
I first tried simply putting a THISFORM.REFRESH in the form's activate method, which didn't fix the problem. I've played around with the ReDrawWindow API as well but haven't gotten it to function properly either.
When I manually minimize the app and restore it, everything looks fine. I've tried running the entire procedure above against "WINDOWS MEDIA PLAYER" (that I was using to listen to some music) and it restores and appears to redraw without being prompted.
What am I doing wrong in my Foxpro App? Any ideas?
Mark
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement