Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

MessageBox is hidden

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
Highlighted
Employee
1 View

Hello,

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.

Eugene Epshteyn
0 Kudos
Highlighted
New Contributor II
1 View

Reidar,

Reidar,

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

Robert

 

0 Kudos
Highlighted
Black Belt
1 View

That could still leave the

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

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
1 View

I arranged the code as shown

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
Highlighted
Employee
1 View

Quote:reidar wrote:

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.

Eugene Epshteyn
0 Kudos