Static control demo

Started by Vortex, November 02, 2023, 07:26:53 PM

Previous topic - Next topic

Vortex

Simple static control demo :

include     StaticControl.inc

.data

ClassName   db "WndClass",0
AppName     db "Window",0
CtrlName    db 'Static',0
text1       db 'This is a static control.',0

.data?

hInstance   dd ?

.code

start:

    invoke  GetModuleHandle,0
    mov     hInstance,eax
   
    invoke  GetCommandLine
    invoke  WinMain,hInstance,0,eax,SW_SHOWDEFAULT
    invoke  ExitProcess,eax

WinMain PROC hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD

LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:DWORD

    xor     eax,eax
    mov     wc.cbSize,SIZEOF WNDCLASSEX
    mov     wc.style, CS_HREDRAW or CS_VREDRAW
    mov     wc.lpfnWndProc, OFFSET WndProc
    mov     wc.cbClsExtra,eax
    mov     wc.cbWndExtra,eax
    push    hInstance
    pop     wc.hInstance
    mov     wc.hbrBackground,COLOR_WINDOW+1
    mov     wc.lpszMenuName,eax
    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
    invoke  RegisterClassEx,ADDR wc
   
    xor     eax,eax
    mov     ecx,100
    invoke  CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
            WS_OVERLAPPEDWINDOW or WS_VISIBLE,ecx,\
            ecx,500,400,eax,eax,\
            hInst,eax
    mov     hwnd,eax
    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

WndProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .IF uMsg==WM_DESTROY
   
        invoke  PostQuitMessage,NULL

    .ELSEIF uMsg==WM_CREATE

        mov     eax,20
        invoke  CreateWindowEx,0,ADDR CtrlName,ADDR text1,\
                WS_CHILD or WS_VISIBLE or SS_LEFT,\
                eax,eax,240,160,hWnd,0,hInstance,0
    .ELSE
   
        invoke  DefWindowProc,hWnd,uMsg,wParam,lParam       
        ret
       
    .ENDIF
   
    xor     eax,eax
    ret

WndProc ENDP

END start
Code it... That's all...

TimoVJL

Nice to have an asm code example for further testing.
May the source be with you

Robert

Hi Vortex:

Thanks for the demo.

What has to be changed to compile as 64 bit?

Vortex

Hi Timo,

Many thanks.

Hi Robert,

I will rewrite the code to create a 64-bit version of the same application. The 32-bit and 64-bit assembly are different worlds.

Code it... That's all...

Vortex

Hi Robert,

Here is the 64-bit version.
Code it... That's all...

Robert

Quote from: Vortex on November 08, 2023, 06:46:30 PM
Hi Robert,

Here is the 64-bit version.

Thank you Vortex. It is going to be interesting and educational for me to compare the 32 and 64 bit versions.

I really appreciate your kindness.