- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 omitted, the value is determined in this order:
-
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, you have no control over window position of the spawned program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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..
- case (WM_CLOSE)
- ! Free the INFO data that associates with this
- ! window also, reset the menu.
- iret = messagebox(GetForegroundWindow(),'OK to close the file?'//""C, &
- 'TVA'//""C, MB_ICONQUESTION.OR. &
- MB_OKCANCEL)
- if(iret == IDCANCEL) then
- MDIWndProc = 0
- return
- else
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page