Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ShellExecute inconsistency
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00713750
Message ID:
00715314
Views:
16
>Hi Everybody,
>
>I'm writing a very basic stub program that will check if the executable in the server is newer than the executable in the workstation. If the server has a newer file, the file is copied to the workstation and then executed using the ShellExecute windows API function.
>
>Sometimes, however, the application window opens but it's not the ACTIVE window on my desktop (title bar is gray). This happens regardless of the SW parameter I pass to ShellExecute (the last parameter determines how the new window is opened).
>
>How can I ensure that the application will open and BE THE ACTIVE window?
>
>I think I'm missing something, but no idea what...
>
>Thanks!!!!
>
>Alex
>
>PS: following is the code I'm using to start my application. The stub application only has this code as it's main.prg and nothing else.
>
>
* 	This program serves as a stub for automatically updating applications in
>* 	the workstations should the executable file in a specific directory be newer.
>* 	The location of the master executable is supplied as a parameter. Example
>* 	VisualLoader "f:\program files\yTimeClock\yTimeClock.exe"
>
>
>Lparameters tcFileName
>
>local lcExecutable
>local lcMasterExecutable
>local lcCommand
>
>* Warn if source file name and path weren't supplied.
>if empty( tcFilename)
>	MessageBox("You must supply a file name!")
>	return 0
>endif
>
>* Extract just the File Name from the drive:\path\filename string supplied.
>lcExecutable = JustFname( tcFileName)
>
>if file( tcfilename)
>	* Master file exists. Let's determine whether update is warranted.
>	If !File( lcExecutable) .or. Fdate( tcFilename,1) > Fdate( lcExecutable, 1)
>		* Master file is newer or dest file doesn't exist. Let's update
>		If File( lcExecutable)
>			* Dest. executable exists. Delete it
>			Delete File (lcExecutable)
>			MessageBox("Deleted old version")
>		EndIf
>		
>		* update the file:
>		copy file (tcFileName) to (lcExecutable)
>	endif
>endif
>
>*Execute target file once it's been copied
>DECLARE INTEGER ShellExecute ;
>	    IN SHELL32.DLL ;
>	    INTEGER nWinHandle,;
>	    STRING cOperation,;
>	    STRING cFileName,;
>	    STRING cParameters,;
>	    STRING cDirectory,;
>	    INTEGER nShowWindow
>
>lcOperation = "OPEN"
>lcWorkDir = ""
>
>*Command values:
>* 	SW_SHOWNORMAL = 1
>* 	SW_NORMAL = 1
>* 	SW_SHOWMINIMIZED = 2
>* 	SW_SHOWMAXIMIZED = 3
>* 	SW_SHOWNOACTIVATE = 4
>* 	SW_SHOW = 5
>* 	SW_SHOWNA = 8
>* 	SW_SHOWDEFAULT = 10
>
>
>RETURN ShellExecute(0,lcOperation,lcExecutable,"",lcWorkDir,3)
Rather than using the default 0 for the hWnd of relative location, use the return of GetForegroundWindow() to specify the starting location of the ShellExec'd program:
DECLARE INTEGER GetForegroundWindow IN WIN32API
RETURN ShellExecute(GetForegroundWindow(),lcOperation,lcExecutable,"",lcWorkDir,3)
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform