flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > Subclassing and CallWindowProc

Author
Thread Post new topic Reply to topic
mikado3333



Joined: 31 Oct 2015
Posts: 6
Location: Russian Federation
Subclassing and CallWindowProc
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 FindWindowesi0
                                cmp    eax,0
                                jnz    @f
                                
                                INVOKE GetModuleHandle,    [edi + WNDCLASS.hInstance], 0
                                INVOKE LoadIcon,             [edi + WNDCLASS.hIcon], 0IDI_EXCLAMATION
                                INVOKE LoadCursor,           [edi + WNDCLASS.hCursor], 0IDC_ARROW
                                
                        
                                invoke RegisterClass,    edi
                                cmp    eax,0
                                jz     .error   

@@:                             mov    edx.title      
                                cmp    [zagalovok], 0
                                cmovne  edx, [zagalovok]
                                INVOKE  CreateWindowEx, [hWindow], 0esiedxWS_VISIBLE+WS_OVERLAPPEDWINDOW,\
                                                                                12812850020000, [edi + WNDCLASS.hInstance],0 
                                cmp    eax,0
                                jz     .error                                                   
                                                                
                                lea    ebx, [stRC]                      
                                invoke GetClientRect,     [hWindow], ebx
                                
                                INVOKE CreateWindowEx,          ediWS_EX_CLIENTEDGE.edit, [text], styleEdit0,\
                                                                                0,[ebx + RECT.right],[ebx + RECT.bottom],[hWindow],0,\
                                                                                [edi + WNDCLASS.hInstance],0
                                cmp    eax,0
                                jz     .error                                                   
                        
                                INVOKE CreateFont,    [hFont], 18000500000,DEFAULT_CHARSET,\      
                                                              OUT_DEFAULT_PRECIS ,CLIP_DEFAULT_PRECIS,\                         
                                                                   PROOF_QUALITYFIXED_PITCH + FF_DONTCARE.FontName
                                cmp    eax,0
                                jz     .error
                                                                        
                                invoke SendMessage,    ediWM_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             edxedi
                                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,            eaxWM_GETFONT00
                                invoke  DeleteObject,           eax     
                                invoke  DestroyWindow,          [hwnd
                                lea             esi, [class]
                                invoke  FindWindow,             esi0
                                cmp             eax,0
                                jnz             .exit
                
                                invoke  GetModuleHandle,        0
                                invoke  UnregisterClass,        esieax
                                jmp             .exit
                                
.destroy:                       invoke       PostQuitMessage,   0
                                jmp             .exit                           
                                
.size:                          lea             ebx, [rc]
                                invoke       GetClientRect,             [hwnd], ebx
                                lea             eax, [edit]
                                invoke  FindWindowEx,           [hwnd], 0eax0
                                invoke       MoveWindow,                        eax00, [ebx + RECT.right], [ebx + RECT.bottom], TRUE        

.exit:                         mov              eax0  
.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          ebxeax
                                                                                                        
                        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,     ebxWM_EDITTB, [hwnd], [wparam]
                        jmp       .finish       

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

.finish:                xor        eaxeax
.out:                   pop       edi esi ebx
                                
                
ret
endp



Working! But I call

Code:
.KillFocus:             invoke  SendMessage,    [wparam], WM_GETTEXTLENGTH00        


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]
                               [bjmp     .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: 6
Location: Russian Federation
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: 14794
Location: Lost in translation
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.