flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Iczelion's Win32 Assembly Tutorial: 20 - Window Subclassing

Author
Thread Post new topic Reply to topic
Beowulf



Joined: 10 Jul 2003
Posts: 5
Location: Germany
Code:
format PE GUI 4.0
entry main

;-------------------------------------------------------------------------------------
;Include
;-------------------------------------------------------------------------------------

include '%fasminc%\win32a.inc'

;-------------------------------------------------------------------------------------
;Data Section
;-------------------------------------------------------------------------------------

section '.data' data readable writeable

        ClassName  db "SubclassWinClass",0
        AppName    db "Subclassing Demo",0
        EditClass  db "EDIT",0
        Message    db "You pressed Enter in the text box!",0

        hInstance  dd ?
        hwndEdit   dd ?
        OldWndProc dd ?

        wc         WNDCLASSEX
        msg        MSG
        hwnd       dd ?

;-------------------------------------------------------------------------------------
;Code Section
;-------------------------------------------------------------------------------------

section '.code' code readable executable

        ;----Entry Point and 'main' Procedure--------------
        proc main
        enter
                mov   [wc.cbSize],48
                mov   [wc.style], CS_HREDRAW or CS_VREDRAW
                mov   [wc.lpfnWndProc],WndProc
                mov   [wc.cbClsExtra],NULL
                mov   [wc.cbWndExtra],NULL

                invoke  GetModuleHandle ,0
                mov   [hInstance],eax
                mov   [wc.hInstance],eax
                mov   [wc.hbrBackground],COLOR_APPWORKSPACE
                mov   [wc.lpszMenuName],NULL
                mov   [wc.lpszClassName],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, wc
                invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
                                      ClassName,\
                                      AppName,\
                                      WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,\
                                      CW_USEDEFAULT, CW_USEDEFAULT,350,200,\
                                      NULL,\
                                      NULL,\
                                      hInstance,\
                                      NULL

                mov   [hwnd],eax

                Message_Loop_Start:

                        invoke  GetMessage,msg,NULL,0,0
                        or      eax,eax
                        jz      Message_Loop_End
                        invoke  TranslateMessage,msg
                        invoke  DispatchMessage,msg
                        jmp     Message_Loop_Start

                Message_Loop_End:

                        invoke  ExitProcess,[msg.wParam]
        return

        ;----Window Procedure-----------------
        proc WndProc, hWnd,uMsg,wParam,lParam
        enter
                cmp     [uMsg], WM_CREATE
                je      .wmcreate
                cmp     [uMsg], WM_DESTROY
                je      .wmdestroy

                .defwndproc:
                        invoke  DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
                        return

                .wmcreate:
                        invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
                                              EditClass,\
                                              NULL,\
                                              WS_CHILD+WS_VISIBLE+WS_BORDER,\
                                              20,20,300,25,\
                                              [hWnd],\
                                              NULL,\
                                              hInstance,\
                                              NULL
                        mov [hwndEdit],eax
                        invoke SetFocus,eax

                        ;-----------------------------------------
                        ; Subclass it!
                        ;-----------------------------------------

                        invoke SetWindowLong,[hwndEdit],GWL_WNDPROC,EditWindowProc
                        mov [OldWndProc],eax
                        return

                .wmdestroy:
                        invoke  PostQuitMessage,0
                        xor     eax,eax

        return

        ;----Edit Window Procedure--------------------
        proc EditWindowProc, hEdit,uMsg,wParam, lParam
        enter
                cmp     [uMsg], WM_CHAR
                je     .wmchar
                cmp     [uMsg], WM_KEYDOWN
                je     .wmkeydown

                .defwndproc:
                        invoke CallWindowProc,[OldWndProc],[hEdit],[uMsg],[wParam],[lParam]
                        xor eax,eax
                        return

                .wmchar:
                        mov eax, [wParam]
                         cmp al, VK_BACK
                         je  .CallOrginalWindowProc
                         cmp al, "0"
                         jb .finish
                         cmp al, "9"
                         jbe .CallOrginalWindowProc
                         cmp al, "A"
                         jb .finish
                         cmp al, "F"
                         jbe  .CallOrginalWindowProc
                         cmp al, "a"
                         jb .finish
                         cmp al, "f"
                         jbe .LowToUp
                         jmp .finish

                        .LowToUp:
                                sub al,20h
                                mov [wParam], eax

                        .CallOrginalWindowProc:
                                invoke CallWindowProc,[OldWndProc],[hEdit],[uMsg],[wParam],[lParam]

                        .finish:
                                xor eax,eax

                        return

                .wmkeydown:
                        mov eax, [wParam]
                        cmp eax, VK_RETURN
                        jne @f

                                invoke MessageBox,[hEdit],Message,AppName,MB_OK+MB_ICONINFORMATION
                                invoke SetFocus,[hEdit]

                        @@:
                                invoke CallWindowProc,[OldWndProc],[hEdit],[uMsg],[wParam],[lParam]
                                xor eax,eax

                        return

;-------------------------------------------------------------------------------------
;Imports
;-------------------------------------------------------------------------------------

section '.idata' import data readable writeable

        library kernel32,'KERNEL32.DLL',\
                user32,'USER32.DLL',\
                gdi32,'GDI32.DLL',\
                advapi32,'ADVAPI32.DLL',\
                comctl32,'COMCTL32.DLL',\
                comdlg32,'COMDLG32.DLL',\
                shell32,'SHELL32.DLL',\
                wsock32,'WSOCK32.DLL'

        include '%fasminc%/apia/kernel32.inc'
        include '%fasminc%/apia/user32.inc'
        include '%fasminc%/apia/gdi32.inc'
        include '%fasminc%/apia/advapi32.inc'
        include '%fasminc%/apia/comctl32.inc'
        include '%fasminc%/apia/comdlg32.inc'
        include '%fasminc%/apia/shell32.inc'
        include '%fasminc%/apia/wsock32.inc'          
    
Post 17 Jan 2004, 11:16
View user's profile Send private message ICQ Number 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-2018, Tomasz Grysztar.

Powered by rwasa.