2 RegisterClassEx in same WNDCLASSEX, how does this work?

Started by rogerio, April 13, 2009, 02:34:27 PM

Previous topic - Next topic

rogerio

How do the 4 lines indicated below work? I understand the part about causing messages to be sent to 2 procedures, but seems that the last RegisterClassEx would overwrite the first one. Is this a form of superclassing? Thanks...


WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
INVOKE LoadBitmap,hInstance,IDB_BUTTONDOWN
mov hbmpdown,eax
INVOKE LoadBitmap,hInstance,IDB_BUTTONUP
mov hbmpup,eax
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_WINDOW+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

; How do the next 4 line work
invoke RegisterClassEx, addr wc
mov   wc.lpfnWndProc, OFFSET MyButtonProc
mov   wc.lpszClassName,OFFSET ClassMyButton
invoke RegisterClassEx, addr wc
;------------------------------
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,500,\
           350,200,200,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

xmetal

The lpszClassName member is modified before the second call, hence a different class is registered (assuming of course that ClassName and ClassMyButton are pointers to two different strings).

rogerio

Thanks xmetal. This came from a working program that I found, but this was a whole different concept than I had ever seen. Can this be considered as superclassing since it follows the pattern?

xmetal

Well, that depends on the MyButtonProc procedure. Simply registering a new class with properties common to another class does not necessarily imply superclassing. If the window procedure of the "derived" class passes some messages to the "base" class, then it could be considered superclassing.

rogerio

MyButtonProc is receiving WM_CREATE and a couple of  WM_LMOUSExxx so that should be a superclass. The way that the class was registered with the WinMain WNDCLASS doesn't follow windows guidelines for superclassing and I had not seen that style before. Thanks xmetal.