Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

MessageBox is hidden

reidar
New User
611 Views

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

 

0 Kudos
5 Replies
Eugene_E_Intel
Employee
612 Views

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.

0 Kudos
Robert_van_Amerongen
New Contributor III
612 Views

Reidar,

Try to use the result of a call to GetDesktopWindow as the first argument of the MessageBox call.

Robert

 

0 Kudos
Steve_Lionel
Black Belt Retired Employee
612 Views

That could still leave the box hidden. Ideally you want the handle of the current window (or the topmost window). GetTopWindow() will do that.

0 Kudos
reidar
New User
612 Views

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

 

0 Kudos
Eugene_E_Intel
Employee
612 Views

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.

0 Kudos
Reply