News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Second Dialog?

Started by Mark Jones, July 22, 2005, 02:30:45 PM

Previous topic - Next topic

Mark Jones

How do you add (and use) a second dialog in an existing dialog-as-main app? Is it possible? Thanks.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Mark Jones

Okay, Project --> Add New --> Dialog. Got that much. How do you utilize it, must it be created with CreateWindow? Then do you handle its messages alongside the main dialog's messages? i.e., would the DlgProc receive messages for BOTH dialogs, and the code must determine that from hWin?


.code
start:
    invoke GetModuleHandle,0
    mov    hInstance,eax
    invoke InitCommonControls                   ; needed for xp theme
    invoke DialogBoxParam,hInstance,IDD_DIALOG1,0,addr DlgProc,0
    invoke ExitProcess,0

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
    mov eax,uMsg
    .if eax==WM_INITDIALOG
    .elseif eax==WM_COMMAND
    .elseif eax==WM_CLOSE
; etc...
DlgProc endp


Or can a DlgProc2 be made?
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Mark Jones

Adding this results in ERR_INVALID_WND_CLASS :


.data
    szClassName   db  'DLGCLASS',0
    szDlgName     db  'My 2nd Dialog Window',0
    hWnd2         dd  0

.code
    invoke CreateWindowEx,000000008h,addr szClassName,addr szDlgName,\
           0D0000000h,100,100,50,50,hWnd,0,hInstance,0
    mov [hWnd2],eax


Is DLGCLASS supposed to indicate a WNDCLASSEX or something?

Maybe if I keep messing with it, the answer will eventually reveal itself... we really need a reference document on dialog construction in MASM!
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

petezl

Mark,

the procedure is decribed well in Iczillions tutorials! If I can remember correctly you use the class template in conjunction with a win_proc which you register with RegisterClassEx call. In this case, the dialog box behaves like a "normal" window: it receives messages via a window procedure referred to by lpfnWndProc member of the window class, not via a dialog box procedure.

You can create as many dlg boxes as you want by dropping the  CLASS "DLGCLASS" from the resource file and use separate Dlg_proc for each Dlg. These of course don't use a message loop.

Peter
Cats and women do as they please
Dogs and men should realise it.

Mark Jones

Hi Pete! Glad to see you are still around. :)

Yes this should be a trivial task but it's turning out not to be. Following Iczelion tutorial 11-1, I tried several variations of this in place of CreateWindow:


DlgProc           PROTO   :HWND,:UINT,:WPARAM,:LPARAM
MyDlgProc2        PROTO   :DWORD,:UINT,:DWORD,:DWORD

.data
    hWnd2         dd  0
    szMyDlgProc   db  'IDD_DIALOG2',0

.code
    invoke CreateDialogParam,hInstance,addr szMyDlgProc2,hWnd,offset MyDlgProc2,NULL
    mov [hWnd2],eax

MyDlgProc2 proc hWndM:HWND,iMsg:DWORD,wParam:WPARAM,lParam:LPARAM
    .if iMsg==WM_INITDIALOG
        invoke SetFocus,eax
    .elseif iMsg==WM_COMMAND
        mov eax,wParam
        mov edx,eax
        shr edx,16
        .if dx==BN_CLICKED
            invoke Beep,800,100   ; hello mom!
        .endif    
    .elseif iMsg==WM_CLOSE
        invoke EndDialog,hWndM,NULL
    .else
        mov eax,FALSE
        ret
    .endif
    mov  eax,TRUE
    ret
MyDlgProc2 endp


And the second dialog resource script is:


#define IDD_DIALOG2 102
IDD_DIALOG2 DIALOGEX 0,61,200,123
CAPTION "IDD_DLG2"
FONT 8,"MS Sans Serif",400,0
STYLE 0xD0000000
EXSTYLE 0x00000008
BEGIN
END


But I keep getting "ERROR_RESOURCE_NAME_NOT_FOUND (00000716)" ... I'll keep plugging away at it. :P
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Mark Jones

Oh sheesh. Forgot to include:

    IDD_DIALOG2     equ 102     ; second dialog


Then this works:

    invoke CreateDialogParam,hInstance,IDD_DIALOG2,hWnd,offset MyDlgProc2,NULL


:bg
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

petezl

Hi Mark,
I usually use a number for the dialog id
700 DIALOGEX MOVEABLE etc
Saves having to define the name and repeat it in the asm file! just use
invoke DialogBoxParam,hInstance,700,0,ADDR DlgProc,0

Yes, I still look in from time to time, hope to get back to it when winter returns!
Peter.
Cats and women do as they please
Dogs and men should realise it.