I use ShellExecute to do something, and the first parameters is HWND , the documentation on MSDN says:
A handle to the parent window used for displaying a UI or error messages. This value can be NULL if the operation is not associated with a window.
but I find whichever HWND value gets the same result.
for example :
ShellExecute(0, 'open', 'c:\', nil, nil, SW_SHOWNORMAL);
ShellExecute(Self.Handle, 'open', 'c:\', nil, nil, SW_SHOWNORMAL);
ShellExecute(123456, 'open', 'c:\', nil, nil, SW_SHOWNORMAL);
just gets the same thing (Opens disk C), so I wonder what’s the use using different HWND?
by the way, when ‘HWND = 0’ is the DeskTop’s Handle used?
That
HWNDis used as the owner window for any UI that is shown as a result of the call toShellExecute. For example, any error message dialogs will be owned by that window.The implications of a window being owned are described in the MSDN documentation. Key excerpts:
The important one is the first one. If you are calling
ShellExecutefrom a GUI app then you want any windows to be owned by the window that is currently active in your app. So passMyForm.Handle.If you have no GUI in your app then pass 0.
In the code samples, the call to
ShellExecuteis not showing any UI at all. So it makes no difference what you pass. But if your calls resulted in an error dialog being shown, then the window handle that you pass would become relevant.