flat assembler
Message board for the users of flat assembler.

Index > Windows > Subclassing and CallWindowProc

Author
Thread Post new topic Reply to topic
mikado3333



Joined: 31 Oct 2015
Posts: 7
Location: Russian Federation
mikado3333 22 Apr 2017, 06:39
Hello! I'm from russia, so sorry for my english!
I created a window "My message box". Working!
Code:
locals
hFont           dd 0
hWindow         dd ?
stMSG           MSG     
stRC            RECT
stWCM           WNDCLASS 0,MyModalProc,0,0,0,0,0,COLOR_BTNHIGHLIGHT,0,.class
stWC            WNDCLASS 0,MyNoModalProc,0,0,0,0,0,COLOR_BTNHIGHLIGHT,0,.class2
endl

styleEdit       equ  WS_CHILD+WS_VISIBLE+ES_AUTOVSCROLL+ES_READONLY+ES_MULTILINE+WS_VSCROLL

                                push    esi edi ebx
                        
                                lea    edi, [stWC]      
                                mov    esi, .class2
                                cmp    [modal], 0
                                jz     @f
                                lea    edi, [stWCM]
                                mov    esi, .class
                                
@@:                             invoke FindWindow, esi, 0
                                cmp    eax,0
                                jnz    @f
                                
                                INVOKE GetModuleHandle,    [edi + WNDCLASS.hInstance], 0
                                INVOKE LoadIcon,             [edi + WNDCLASS.hIcon], 0, IDI_EXCLAMATION
                                INVOKE LoadCursor,           [edi + WNDCLASS.hCursor], 0, IDC_ARROW
                                
                        
                                invoke RegisterClass,    edi
                                cmp    eax,0
                                jz     .error   

@@:                             mov    edx, .title      
                                cmp    [zagalovok], 0
                                cmovne  edx, [zagalovok]
                                INVOKE  CreateWindowEx, [hWindow], 0, esi, edx, WS_VISIBLE+WS_OVERLAPPEDWINDOW,\
                                                                                128, 128, 500, 200, 0, 0, [edi + WNDCLASS.hInstance],0 
                                cmp    eax,0
                                jz     .error                                                   
                                                                
                                lea    ebx, [stRC]                      
                                invoke GetClientRect,     [hWindow], ebx
                                
                                INVOKE CreateWindowEx,          edi, WS_EX_CLIENTEDGE, .edit, [text], styleEdit, 0,\
                                                                                0,[ebx + RECT.right],[ebx + RECT.bottom],[hWindow],0,\
                                                                                [edi + WNDCLASS.hInstance],0
                                cmp    eax,0
                                jz     .error                                                   
                        
                                INVOKE CreateFont,    [hFont], 18, 0, 0, 0, 500, 0, 0, 0,DEFAULT_CHARSET,\      
                                                              OUT_DEFAULT_PRECIS ,CLIP_DEFAULT_PRECIS,\                         
                                                                   PROOF_QUALITY, FIXED_PITCH + FF_DONTCARE, .FontName
                                cmp    eax,0
                                jz     .error
                                                                        
                                invoke SendMessage,    edi, WM_SETFONT, [hFont], 1      
                                
                                cmp    [modal], 0
                                jz    .exit
                                
                                lea             ebx,[stMSG]
.msg_loop:                                                                                                                                                                      
                                invoke  GetMessage,ebx,0,0,0                                                                                                            
                                cmp             eax,0                                                                                                                           
                                je              .exit                                                                                                                                   
                                invoke  TranslateMessage,ebx                                                                                                            
                                invoke  DispatchMessage,ebx                                                                                                             
                                jmp            .msg_loop        

.exit:                          mov             eax, [hWindow]
                                mov             edx, edi
                                pop             ebx edi esi
                                clc
ret
.error:                 invoke  DeleteObject, [hFont]
                                pop             ebx edi esi
                                stc
ret
                                
.title          db "Информация",0
.class          db 1,0
.class2         db 2,0
.edit           db 'EDIT',0     
.FontName       db "Courier New",0
                        
endp

proc    MyModalProc     hwnd,wmsg,wparam,lparam                                                                 

locals
class   db 1,0
edit    db 'EDIT',0
rc              RECT
endl

                                push    ebx esi edi
                                cmp     [wmsg],WM_CLOSE
                                jz              .close          
                                                cmp     [wmsg],WM_SIZE
                                                jz              .size
                                                                cmp     [wmsg],WM_DESTROY
                                                                jz              .destroy
                                
                                invoke  DefWindowProc,          [hwnd],[wmsg],[wparam],[lparam]
                                jmp             .out

.close:                   invoke        GetWindow,              [hwnd], GW_CHILD
                                invoke  SendMessage,            eax, WM_GETFONT, 0, 0
                                invoke  DeleteObject,           eax     
                                invoke  DestroyWindow,          [hwnd] 
                                lea             esi, [class]
                                invoke  FindWindow,             esi, 0
                                cmp             eax,0
                                jnz             .exit
                
                                invoke  GetModuleHandle,        0
                                invoke  UnregisterClass,        esi, eax
                                jmp             .exit
                                
.destroy:                       invoke       PostQuitMessage,   0
                                jmp             .exit                           
                                
.size:                          lea             ebx, [rc]
                                invoke       GetClientRect,             [hwnd], ebx
                                lea             eax, [edit]
                                invoke  FindWindowEx,           [hwnd], 0, eax, 0
                                invoke       MoveWindow,                        eax, 0, 0, [ebx + RECT.right], [ebx + RECT.bottom], TRUE        

.exit:                         mov              eax, 0  
.out:                          pop              edi esi ebx     
ret     
endp
    

Working!

I'm Subclassing Edit Control in my program.
Code:
proc    NewDlgProcEditTb                hwnd,wmsg,wparam,lparam                                                                                         

                        push    ebx esi edi     
                                
                        invoke  GetParent,              [hwnd]
                        invoke  GetParent,               eax
                        mov          ebx, eax
                                                                                                        
                        cmp     [wmsg], WM_CHAR
                        je              .wmchar                                         
                        cmp     [wmsg], WM_KILLFOCUS 
                        je              .wmkillfocus
                                
.def:                   invoke  CallWindowProc, [pOldProcEdit], [hwnd], [wmsg], [wparam], [lparam]
                        jmp        .out
        
.wmchar:                cmp        [wparam], VK_TAB
                        jnz        .def
                        invoke SendMessage,     ebx, WM_EDITTB, [hwnd], [wparam]
                        jmp       .finish       

.wmkillfocus:      invoke SendMessage,  ebx, WM_EDITTB, [hwnd], -1
                        jmp       .finish 

.finish:                xor        eax, eax
.out:                   pop       edi esi ebx
                                
                
ret
endp
    

Working! But I call
Code:
.KillFocus:             invoke  SendMessage,    [wparam], WM_GETTEXTLENGTH, 0, 0            

From DialogProc then "bugs" with Edit Control(Can not close window "MyMessage" and crush font) in "MyMessage Box"
If
Code:
.def:                   invoke  CallWindowProc, [pOldProcEdit], [hwnd], [wmsg], [wparam], [lparam]
                               [b] jmp     .finish[/b]
    
then working, but LENGTH = 0 (xor eax, eax).
Post 22 Apr 2017, 06:39
View user's profile Send private message Reply with quote
mikado3333



Joined: 31 Oct 2015
Posts: 7
Location: Russian Federation
mikado3333 23 Apr 2017, 14:43
It's decided. The reason was in the future code of the program - incorrectly allocated a stack (not a multiple of 4).
Post 23 Apr 2017, 14:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 23 Apr 2017, 14:53
I'm glad you figured it out.

Something I like to recommend is that people post a full example, rather then small snippets where they think the problem is. That way we can assemble and run and see for ourselves exactly what is going on. Help is more forthcoming then.
Post 23 Apr 2017, 14:53
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.