I have found in my company's codebase a code to open default mail program using ShellExecute
. The code is written long time ago, but I've notice strange behavior on it, the problem only occurs when the debugger is not attached.
if ShellExecute(Handle, PChar('open'), PChar('mailto:donotreply@nonono.com'), nil, nil, SW_SHOWDEFAULT) <= 32 then
begin
//...
end;
Above is the relevant part of the code. Handle
is the Form handle.
To reproduce the problem, simply create a new project, add a button on it and call this code on the button onClick
event handler. It is also necessary to not have a default mail installed, so windows will display an message warning about that.
When debugging, the message Z order is higher than the application, so the message box is properly displayed and the user can close this message. When not debugging, the message Z order is lower than the application, so the user has to alt+tab to see that message.
I don't have enough knowledge to understand what is happening nor to state if that behavior is correct or not.
Is there anything I can do to properly display the message box in a higher Z order than my application?
Is this code deprecated? Should I move forward to a different way of doing this, if so, how?