- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In a win 32 program I use the MessageBox function to pass information the user. For example:
iret = MessageBox(NULL,'File saved '//""C,'TVA'//" "C,MB_OK)
I apply the function from subroutines and from call-back functions.
Some times it show up in the foreground as intended but in most cases the massage box is hidden behind the application's main window.
Can somebody give me a hint ?
Regards, Reidar
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
If the first parameter to MessageBox() is NULL, then the message box window has no owner window and can really appear anywhere. (See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-messagebox ). In order for the message box to appear in front of a particular window, you need to pass that window's handle as the first parameter of MessageBox() function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Reidar,
Try to use the result of a call to GetDesktopWindow as the first argument of the MessageBox call.
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That could still leave the box hidden. Ideally you want the handle of the current window (or the topmost window). GetTopWindow() will do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I arranged the code as shown below, in most cases it works. I am questioning my use of hwnd in the call to SendMessage, see below.
case (WM_CLOSE) ! Free the INFO data that associates with this ! window also, reset the menu. hclose=GetTopWindow(hWnd) iret = messagebox(hclose,'OK to close the file?'//""C, & ! iret = messagebox(GetDesktopWindow(),'OK to close the file?'//""C, & ! Does not work 'TVA'//""C, MB_ICONQUESTION.OR. & MB_OKCANCEL) if(iret == IDCANCEL) then MDIWndProc = 0 return else iret = SendMessage(GetParent(hwnd), & ! should be hClose rather than hwnd ? WM_MDISETMENU,ghMenu,ghMenuWindow) iret = DrawMenuBar(GetParent(GetParent(hwnd))) hInfo = GetWindowLong(hClose, 0) iret = LocalFree(hInfo) end if
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
reidar wrote:I arranged the code as shown below, in most cases it works. I am questioning my use of hwnd in the call to SendMessage, see below.
WM_MDISETMENU must be sent to the MDI window with a menu. Not knowing, how your windows are structured and their child-parent relationships, it's hard to give advice.
I recommend that when you originally create MDI window, you save its handle somewhere and then use that handle to send WM_MDISETMENU message.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page