When my application opens a dialog box, it is usually hidden by other windows--both that of my own app and other apps that just happen to be open and occupy an unfortunate area of my screen. Is there any way to force my dialog to be on top? This is wreaking havoc with my customers who don't know that the dialog is there because they can't see it.
In the other thread about starting an editor, you mentioned that you were throwing dialog boxes up from a console application. Is this the same application?
Assuming that you are not deliberately creating the dialog in the background (not likely), what I suspect is happening is that the console application is not considered the "foreground window" process at the time that it throws up the dialog box (it can't be the foreground window process - as it has no windows - the process that will be considered having the foreground window will be the process that provides the console support). The windowing system restricts processes that are not the foreground window from grabbing the focus without the user's involvement.
To confirm my suspicions, perhaps experiment with, and read the documentation, on the SetForegroundWindow API. If my suspicions are right, then you will at least get a flashing title bar for your dialog box.
This is a complication that arises from having a console program throw up windows.
You could use the result of a GetForegroundWindow() call as the hWnd argument when putting up the dialog box. This works well in console applications. If you use NULL, then the desktop is considered the parent window.
I use just this IVF Fortran call to activate the dialogs:
lret = DLGMODAL (dlg)
i.e. the optional 2nd argument, hwndParent, is missing. According to the IVF documentation, then "the Windows desktop window is the parent window." I suppose this is what Steve means by "If you use NULL, then the desktop is considered the parent window."
I don't understand how the "parent window" affects the focus, or stack order, of the subject window. Is it logical that parent = desktop has a different effect from parent = MyConsoleApp?
I will experiment with Ian's and Steve's suggestion and report back.
Yes, you need to pass the second argument. The default is that the desktop background is the parent, so the dialog appears above that. If your console window has focus, then it could obscure the dialog. Here's what the documentation says:
If DLGMODAL is called from the callback of a modal or modeless dialog box, then that dialog box is the parent window.
If it is a QuickWin or Standard Graphics application, then the frame window is the parent window.
The Windows* desktop window is the parent window.
OK, progress. By opening the dialog window using
lret = DLGMODAL ( dlg, GetForegroundWindow() )
The window will be on top of my program window. And, I can locate the dialog w.r.t. the upper left corner of my program window. Now, if only I could control the location of the program window w.r.t. the desktop. Is there a way to do that? (I kow how to locate the project frame when using a Quickwin project, but this is a console project.)
Further, the dialog my still be hidden by other app windows. In this case, my program launches a pdf viewer using ShellExecute, and that appears on top of everything else on the desktop. Then, my program launches a dialog, and that shows up on top of my program (thanks for the solution Steve!) but it is still under the pdf viewer. So, is there a way to control the location of a window launched by ShellExecute? Perhaps by tweaking the lpParameters structure (which is currently null)?
I think this is a bit similar to a problem I have with a MDI application as the message box sometimes poop up, other times not. Please see code fragment below.
So I the tried the GetForegroundWindow() (I used to have NULL),. However, the problem was not solved in my case..