Hi everyone ! Great forum indeed. Needless to mention I am fairly new to this, so any help on the following will be greatly appreciated: I try to make a dialog box with 2 buttons appear when an item from a menu in the main window is chosen. Depending on the button from the dialog box clicked, an appropriate action is implemented. I create the main window in the main window procedure (using CreateWindowEx) and after the required menu item is chosen I try to create the dialog box from a template in a resource file by invoking CreateDialogParam (in the WndProc procedure !?!?). The dialog box messages are supposed to be processed by a DlgProc procedure. Can this be done at all? The exe file only displays the main window and menu, but when that menu item is clicked the dialog box is not displayed. As I mentioned I know this can be done in a better way, but I wanted to try this as well. Thanx for any suggestions.
Posted on 2001-02-28 02:46:00 by matz
Hi if i understand you right ,you want to create a small message box with two buttons(like for YES and NO). you can simply insert a MESSAGEBOX (call messagebox.....)and modify it like you need. i mean you can change the buttons or the icon of the message. so there is no neednes of a extra dialogfield ;) just check out the first tutorials found on this page. cu
Posted on 2001-02-28 03:48:00 by WH¥
Thanks for the suggestion mate. As I said, I am aware of various ways for doing it, but I was really experimenting to see if I can use CreateDialogParam this way.
Posted on 2001-02-28 06:15:00 by matz
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM . . .IF uMsg==WM_COMMAND mov eax, wParam .if ax==IDM_CREATE_DIALOG_BOX invoke CreateDialogParam,hInstance, addr DlgboxName,hWnd,OFFSET DlgboxProc,NULL . . DlgboxProc proc hDlg:HWND,iMsg:DWORD,wParam:WPARAM, lParam:LPARAM . . .if iMsg==WM_COMMAND mov eax,wParam .if ax==IDOK . .elseif ax==CANCEL . .endif DlgboxProc endp hth vesa
Posted on 2001-02-28 06:45:00 by vesa
Matz, This is basically how its done from inside an app. Regards, hutch@pbq.com.au

invoke DialogBoxParam,hInstance,ADDR dlgname,hParent,ADDR WndProc,0



; ############################################################

WndProc proc hWin   :DWORD,
             uMsg   :DWORD,
             wParam :DWORD,
             lParam :DWORD

      .if uMsg == WM_INITDIALOG
    ; -----------------------------
    ; other message processed here
    ; -----------------------------
      .elseif uMsg == WM_CLOSE  ; for system close button
        GetOutaHere:
        invoke EndDialog,hWin,0

      .endif

    xor eax, eax    ; this must be here in NT4
    ret

WndProc endp

; ############################################################
Posted on 2001-02-28 06:55:00 by hutch--
Vesa, good on ya, precisely what I have done. It still wouldn't show the dialog box. So, at least I know if that should work, it must be something about the styles I have used or....some trivial stuff (I made sure I put WS_VISIBLE in the template; also tried ShowWindow...). Anyway, I'll keep poking around until it's working. Hutch, Thanx for the suggestion, I'll play around a bit with that as well. Regards
Posted on 2001-03-01 06:48:00 by matz
Pretty sure i got this one pegged, Since your have assigned a DialogProc Fucntion when creating the dialog box, i assume you have only handled for a button events. All other events, like PAINTING your dialog box, thus have not been handled by the proc given above. You must provide:

    if uMsg == WM_COMMAND
       ...
    .elseif ...
       ...
    .else
       invoke DefDlgProc, hDlg, uMsg, wParam, lParam
    .endif
Default Dialog Proc, is handled by windows and will take care of any message passed to your function that didnt get handled (by the nature of the if-elseif stucture). Add this extra line of code, and the your dialog box should apprear as i understand your problem. NaN
Posted on 2001-03-01 16:39:00 by NaN
To matz: Try adding ".if lParam == 0" after "mov eax, wParam" and before ".if ax==IDM_CREATE_DIALOG_BOX". To NaN: I think for dialog procedure we should not "invoke DefWindowProc", we should "mov eax,FALSE" and then "ret". For window procedure, we should do right the opposite. Please verify...
Posted on 2001-03-02 12:05:00 by zhanghz
Run the program and then minimize the main window to see if the dialog is hiding behind it.
Posted on 2001-03-02 20:55:00 by tank
I would at this time like to decline in my first thoughts... (doh!) ;P Zhanghz, is totaly right... I should have looked it up befor i jumped the gun... Here is an little quote from the win32 API:
DefDlgProc must not be called by a dialog box procedure; doing so results in recursive execution.
Thanx for pointing that out. NaN
Posted on 2001-03-02 22:05:00 by NaN
I nailed it !! I had a "CLASS" in my template for the dialog box which was trying to create it as a window class ...:D So I got rid of it and it works:) Thanx everyone for the suggestions;) In reply to zhanghz, tank and NaN (and the others)I post some excerpts from the API reference. Regards, p.s. tank, I thought of peeking behind the windows myself so I included "TOPMOST" window style in the template just in case (:
Remarks - DialogProc You should use the dialog box procedure only if you use the dialog box class for the dialog box. This is the default class and is used when no explicit class is given in the dialog box template. Although the dialog box procedure is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog box window procedure.
Remarks - CreateDialogParam The CreateDialogParam function uses the CreateWindowEx function to create the dialog box. CreateDialogParam then sends a WM_INITDIALOG message….. After CreateDialogParam returns, the application displays the dialog box (if it is not already displayed) by using the ShowWindow function. The application destroys the dialog box by using the DestroyWindow function.
Windows does not send a WM_CREATE message to the dialog box procedure. Instead, it sends a WM_INITDIALOG message when it creates the dialog box and all its controls but before it displays the dialog box. The procedure should carry out any initialization required to ensure that the dialog box displays the current settings associated with the command or task. The WM_INITDIALOG message is sent to the dialog box procedure immediately before a dialog box is displayed. Return Value The dialog box procedure should return TRUE to direct Windows to set the keyboard focus to the control given by hwndFocus. Otherwise, it should return FALSE to prevent Windows from setting the default keyboard focus.
An application must destroy all modeless dialog boxes before terminating. It can destroy a modeless dialog box by using the DestroyWindow function. Dialog boxes created by the DialogBox, DialogBoxParam, DialogBoxIndirect, and DialogBoxIndirectParam functions must be destroyed using the EndDialog function. An application calls EndDialog from within the dialog box procedure; the function must not be used for any other purpose...
:cool:;);):P:P:P
Posted on 2001-03-03 12:27:00 by matz