Problems geting control handle ( using CreateDialogParam )

Started by RHL, May 03, 2012, 12:34:19 AM

Previous topic - Next topic

RHL

Hi all  :bg, well, i want ask help, i'm trying get the handle of a control, but i do not cannot and i do not know why... :P
I have the controls within of a RC, I'm creating with CreateDialogParam function, my full code:  :bg

I tried within of WM_INITDIALOG, WM_GETDLGCODE messages and I can not get it


#include "\masm32\include\resource.h"
#define IDC_STATIC1         500
CL1 DIALOG 10, 10, 100, 100
STYLE WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_CLIPCHILDREN
FONT 10, "Courier New"
CLASS "class1"
BEGIN
    CONTROL "BITM1",IDC_STATIC1,"Static",0x5000010E,0, 0, 64, 64,0x00000000
END



include    \masm32\include\masm32rt.inc
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
childProc proto :HWND, :UINT, :WPARAM,:LPARAM
IDC_STATIC1 equ         500
.data
    ClassName db "MainWinClass",0
    AppName  db "Main Window",0
    DLg db "CL1",0
    class db "class1",0
    handlecontrol dd 0
.data?
   hInstance HINSTANCE ?
   CommandLine LPSTR ?
.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 wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov   wc.cbSize,SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,NULL
mov   wc.cbWndExtra,NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground,COLOR_BTNFACE+1
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
mov   hwnd,eax

invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd

.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
push hWnd
call createD

.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp

param1 equ [ebp+08h] ; param1

createD proc
LOCAL wc:WNDCLASSEX
mov    wc.cbSize,SIZEOF WNDCLASSEX
    mov    wc.style, CS_HREDRAW or CS_VREDRAW
    mov    wc.cbClsExtra,NULL
    mov    wc.cbWndExtra,DLGWINDOWEXTRA
mov edx,hInstance
mov    wc.hInstance,edx
mov    wc.hbrBackground,COLOR_BTNFACE+1
mov    wc.lpszMenuName,NULL
    invoke LoadIcon,NULL,IDI_APPLICATION
    mov    wc.hIcon,eax
    mov    wc.hIconSm,eax
    invoke LoadCursor,NULL,IDC_ARROW
    mov    wc.hCursor,eax

mov    wc.lpszClassName,offset class
mov    wc.lpfnWndProc,childProc
    invoke RegisterClassEx,addr wc

invoke CreateDialogParam,hInstance,addr DLg,param1,NULL,NULL
invoke ShowWindow,eax,SW_SHOW
ret 04h
createD endp


childProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
; *************************************
; what message?, tried with WM_INITDIALOG, WM_GETDLGCODE Messages and it not work :/
; +++++++++++++++++++++++++++++++++++++
.ELSEIF uMsg==WM_CREATE
invoke GetDlgItem,hWnd,IDC_STATIC1
mov handlecontrol,eax        ;< ========= HANLDECONTROL = ZERO

.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
childProc endp
end start

dedndave

        invoke  CreateDialogParam,hInstance,addr DLg,param1,NULL,NULL

don't you need to have a DlgProc ?

        invoke  CreateDialogParam,hInstance,addr DLg,param1,DlgProc,NULL

DlgProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
;
;
DlgProc PROC hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

    .if uMsg==WM_INITDIALOG
        INVOKE  GetDlgItem,hWnd,IDC_STATIC1
        mov     hStatic1,eax

    .elseif uMsg==WM_CLOSE
        INVOKE  EndDialog,dWin,0

    .else
        mov     eax,FALSE
        ret

    .endif

    mov     eax,TRUE
    ret

DlgProc ENDP

RHL

it was something simple, but important, and rest of the code works it  :S
thanks a lot, dave :)

dedndave

good job on the rest of it   :U
you are getting better   :bg