News:

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

Use resource files with WNDPROC?

Started by RHL, April 15, 2012, 11:31:13 PM

Previous topic - Next topic

RHL

Hello guys, i want ask something simple... I want to subclassing use (WINPROC procedure - right? )
but, i want not create controls with createwindowex function, i want use the resource files...
I did this code:

start:
invoke GetModuleHandle, NULL
mov    hInstance,eax

invoke GetCommandLine
mov    CommandLine,eax

invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL msg:MSG

    invoke  InitCommonControls
    invoke   DialogBoxParam,hInst,IDD_DIALOG1,NULL,addr WndProc,NULL ; IDD_DIALOG1 = dialog( resource file)

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW

mov     eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
; ...
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp
end start


this code is right? thanks :)

Gunner

No, DialogBoxParam does not need a message loop, the OS provides it.  You just point it to your WndProc.  Sub classing controls on a dialog is the same as a normal window, you use SetWindowLong with GWL_WNDPROC to point to the new window proc for the control.

In your subclass proc, for any messages you do not want to handle, you pass those on with CallWindowProc
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

also - with a dialog box, handle WM_INITDIALOG instead of WM_CREATE

when you subclass a control inside a dialog box, you will have a DlgProc for the dialog box and a WndProc for the subclassed control

MichaelW

RHL,

DialogBoxParam creates a modal dialog, so as Gunner stated the system provides the message loop. To create a modeless dialog, where you provide the message loop, you would use CreateDialogParam. You could use the same dialog resource for either function, but there is an important, non-obvious difference between modal dialogs and modeless dialogs. If a modal dialog has an owner window, specified in the DialogBoxParam hWndParent parameter, then that owner window is disabled until the dialog is destroyed. And since the function that created the modal dialog does not return until the dialog is destroyed, the message loop in your code would serve no useful purpose.

Most of the GUI examples I have posted recently (for years actually) use the MASM32 in-memory dialog macros to create the dialog template in allocated memory. This template in memory serves the same purpose as a dialog template resource, and the API provides a pair of functions to create dialogs from templates in memory, DialogBoxIndirectParam and CreateDialogIndirectParam.

BTW, the parameters for a window procedure (WNDPROC), a dialog box procedure (DLGPROC), a subclass procedure, or DefWindowProc are all the same.



eschew obfuscation

dedndave

here you go
i have created a dialog box with a static control, which is subclassed

RHL

#5
thanks u dave! for u example, :|... I was lost :S
thanks u Gunner, MichaelW

I now understand as work :)
:red

MichaelW

This is an example of a modeless dialog based on Dave's resource definition. One difference between modal and modeless dialogs that I previously forgot to mention is that a modeless dialog must include the WS_VISIBLE style for the dialog to be visible, where a modal dialog will be visible even without the style. Because Dave included this style in his resource definition, no changes were required.

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
IDW_DLG     EQU 100
IDC_STATIC  EQU 101
IDI_ICON    EQU 127
;==============================================================================
    .data
        hInstance HANDLE  0
        hDlg      HWND    0
        msg       MSG     <>
    .code
;==============================================================================

DlgProc proc uses esi edi hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    SWITCH uMsg

        CASE WM_COMMAND

            SWITCH wParam
               
                ;----------------------------------------------------------
                ; This allows the user to close the window by pressing the
                ; Escape key. This behavior depends on the messages being
                ; processed by IsDialogMessage.
                ;----------------------------------------------------------

                CASE IDCANCEL

                    invoke DestroyWindow, hwndDlg

            ENDSW

        CASE WM_CLOSE

            invoke DestroyWindow, hwndDlg

        CASE WM_DESTROY

            invoke PostQuitMessage, NULL

    ENDSW

    return 0

DlgProc endp

;==============================================================================
start:
;==============================================================================

    invoke GetModuleHandle, NULL
    mov   hInstance, eax

    invoke CreateDialogParam, hInstance, IDW_DLG, 0, DlgProc, 0
    mov hDlg, eax

    ;--------------------------------------------------------------
    ; The IsDialogMessage function translates and dispatches all
    ; messages for the dialog. TranslateMessage and DispatchMessage
    ; are included for applications where they are required, to
    ; process tool tips, for example, and will be called only if
    ; IsDialogMessage does not process the message.
    ;--------------------------------------------------------------

  msgLoop:

    invoke GetMessage, ADDR msg, 0, 0, 0
    .IF eax != 0
      invoke IsDialogMessage, hDlg, ADDR msg
      .IF eax == 0
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
      .ENDIF
      jmp msgLoop
    .ENDIF
    exit
;==============================================================================
end start

eschew obfuscation

dedndave

WS_VISIBLE and WS_CLIPCHILDREN are becoming habit   :P

i should make my own flag
WS_WS EQU WS_VISIBLE or WS_CLIPCHILDREN
save some typing   :bg