Delphi: SW_HIDE doesn't work anymore?
I have to run some other application from my program and hide it's form. In Windows XP it was easy:
ShellExecute(开发者_StackOverflow社区Handle, 'open', 'foo.exe', nil, nil,SW_HIDE);
But it seems that it doesn't work anymore in Vista and win7.
Well, at least
ShellExecute(Handle, nil, 'C:\WINDOWS\notepad.exe', nil, nil, SW_SHOWMINIMIZED);
appears to work as one would expect. I do not have a Windows XP machine available, but exactly what happened on XP? If i run
ShellExecute(Handle, nil, 'C:\WINDOWS\notepad.exe', nil, nil, SW_HIDE);
in Windows 7, a notepad.exe process is created, but no window is shown. I guess that the window is created but now shown, as is what one might expect, actually. You can probably show the window later on by using the FindWindow and ShowWindow functions.
Update:
I just confirmed my hypothesis:
var
h: hWnd;
ShellExecute(Handle, nil, 'C:\WINDOWS\notepad.exe', nil, nil, SW_HIDE);
sleep(100);
h := FindWindow(nil, 'Namnlös - Anteckningar');
if IsWindow(h) then
ShowWindow(h, SW_SHOW)
displays the newly created window (with title "Namnlös - Anteckningar", i.e. "New file - Notepad" in Swedish).
Update 2:
Notice that
- I could have used 'open' as verb instead of nil.
- My code does not work if I replace the full path of notepad.exe with simply 'notepad.exe'.
Not all applications respect the SW_... flags correctly in their startup info.
精彩评论