The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: iytbihc on April 05, 2008, 04:11:36 AM

Title: messagebox
Post by: iytbihc on April 05, 2008, 04:11:36 AM
in the msdn :
int MessageBox(
  HWND hWnd,
  LPCTSTR lpText,
  LPCTSTR lpCaption,
  UINT uType
);  hWnd
[in] Handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.
but why in the masm32 show this :
invoke MessageBox, NULL, addr szCaption,  addr szTitle, MB_OK       the first parameter is NULL and it can show window ,if another value
it has no owner window        explain crossly?
Title: Re: messagebox
Post by: hutch-- on April 05, 2008, 04:46:42 AM
Feed MessageBox() a zero "0" handle as the parent and the system is the parent.
Title: Re: messagebox
Post by: MichaelW on April 05, 2008, 05:32:28 AM
Here is an example to play with. When a message box with the default MB_APPLMODAL (application modal) behavior has an owner (parent) window, its behavior is tied to the owner window, so it always appears above the owner in the Z order and retains the keyboard focus (for the application) while it is open. When a message box with this behavior has no owner window (or at least no application window as an owner), its behavior is not tied to any application window.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hInst dd  0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DlgProc proc uses ebx hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    SWITCH uMsg

      CASE WM_COMMAND

        SWITCH wParam

          CASE IDCANCEL

            invoke EndDialog, hDlg, NULL

          CASE 100

            MsgBox hDlg,0,"With owner",0

          CASE 101

            MsgBox 0,0,"Without owner",0

        ENDSW

      CASE WM_CLOSE

        invoke EndDialog, hDlg, NULL

    ENDSW

    return 0

DlgProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetModuleHandle, NULL
    mov hInst, eax

    Dialog  "Test", \                         ; caption
            "FixedSys", 12, \                 ; font,pointsize
            WS_OVERLAPPED or WS_SYSMENU or \  ; window style
            WS_MINIMIZEBOX or DS_CENTER, \
            2, \                              ; number of controls
            0,0,120,90, \                     ; x, y, width, height
            1024                              ; memory buffer size

    DlgButton "MsgBox with owner",0,15,15,90,15,100

    DlgButton "MsgBox without owner",0,15,40,90,15,101

    CallModalDialog hInst, 0, DlgProc, NULL

    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

Title: Re: messagebox
Post by: iytbihc on April 06, 2008, 01:07:11 AM
now i know the reason, thanks