The MASM Forum

General => The Campus => Topic started by: xandaz on December 03, 2020, 01:27:32 AM

Title: window subclass failure.
Post by: xandaz on December 03, 2020, 01:27:32 AM
   hey... i put this code along with WM_CREATE in the mdichildproc. the app crashes. What am i doing wrong?
.if uMsg==WM_CREATE
        invoke  MdiCreateWindows,hWnd
        invoke  GetWindowLong,hWnd,GWL_USERDATA
        mov     edi,eax
        invoke  SetWindowLong,[edi.MdiStruct.hEdit],GWL_WNDPROC,addr EditProc
        mov     [edi.MdiStruct.lpfnEditProc],eax
       

and also this:
EditProc    PROC    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .if uMsg==WM_CHAR
        invoke  MessageBeep,MB_OK
        jmp     cwp
    .else
cwp:   

        invoke  SendMessage,hMdi,WM_MDIGETACTIVE,0,0
        invoke  GetWindowLong,eax,GWL_USERDATA
        invoke  CallWindowProc,[eax.MdiStruct.lpfnEditProc],hWnd,uMsg,wParam,lParam
        ret
    .endif
    xor eax,eax
    ret
                   
EditProc    endp

thabks in advance for help
Title: Re: window subclass failure.
Post by: TouEnMasm on December 03, 2020, 02:06:18 AM
I don't understand very well why you need to subclass a mdi windows.
You need subclassing to get an event loop on a control for example.
Creating a subclass for a mdi is not needed because you have already an event loop,the classic WNDProc.
Even without error code,make an attempt to create another event loop could only crash.
Title: Re: window subclass failure.
Post by: xandaz on December 03, 2020, 02:16:15 AM
   the subclass is for the edit control. thanks
Title: Re: window subclass failure.
Post by: TouEnMasm on December 03, 2020, 02:27:22 AM
Here a sample of subclasing for an Hedit (handle of an edit control)
Quote
; Event_Hedit PROTO :DWORD,:DWORD,:DWORD,:DWORD

;.data
; ~~~~~~~~~~~~~~~~~~~~~
Prev_Event_Hedit           dd ?
;
   invoke SetWindowLong,HHedit,GWL_WNDPROC,Event_Hedit
   mov Prev_Event_Hedit, eax       ;retourne l'adresse de la premiere procédure

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Event_Hedit proc hwnd:DWORD, uMsg, wParam, lParam
   Local retour:DWORD
   mov retour,0 ;la plus commune des valeurs de retour
   
   .if uMsg ==
   .elseif uMsg ==
   .else
      invoke CallWindowProc,Prev_Event_Hedit,hwnd,uMsg,wParam,lParam
      mov retour,eax
   .endif
   mov eax,retour
   ret
Event_Hedit endp

Title: Re: window subclass failure.
Post by: xandaz on December 03, 2020, 02:30:04 AM
   Thanks Tout...
Title: Re: window subclass failure.
Post by: xandaz on December 03, 2020, 02:35:26 AM
   works fine with a global variable. The thing is i was trying to put the original lpfnEditProc in a structure pointed by edi. Thanks Tout
Title: Re: window subclass failure.
Post by: hutch-- on December 03, 2020, 06:51:18 AM
The architecture of Windows requires a variable of GLOBAL scope for a subclass return value, just ensure that each global name is unique.
Title: Re: window subclass failure.
Post by: jj2007 on December 03, 2020, 09:07:52 AM
Quote from: xandaz on December 03, 2020, 01:27:32 AM
        invoke  GetWindowLong,eax,GWL_USERDATA
        invoke  CallWindowProc,[eax.MdiStruct.lpfnEditProc],hWnd,uMsg,wParam,lParam

Using GWL_USERDATA instead of a global variable is a funny idea but it works, see attachment :cool:
Title: Re: window subclass failure.
Post by: xandaz on December 03, 2020, 08:17:56 PM
   Thanks All