NO

Author Topic: Static control demo  (Read 1724 times)

Online Vortex

  • Member
  • *
  • Posts: 858
    • http://www.vortex.masmcode.com
Static control demo
« on: November 02, 2023, 07:26:53 PM »
Simple static control demo :

Code: [Select]
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...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2107
Re: Static control demo
« Reply #1 on: November 03, 2023, 01:30:08 PM »
Nice to have an asm code example for further testing.
May the source be with you

Offline Robert

  • Member
  • *
  • Posts: 247
Re: Static control demo
« Reply #2 on: November 03, 2023, 08:57:05 PM »
Hi Vortex:

Thanks for the demo.

What has to be changed to compile as 64 bit?

Online Vortex

  • Member
  • *
  • Posts: 858
    • http://www.vortex.masmcode.com
Re: Static control demo
« Reply #3 on: November 03, 2023, 09:01:57 PM »
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...

Online Vortex

  • Member
  • *
  • Posts: 858
    • http://www.vortex.masmcode.com
Re: Static control demo
« Reply #4 on: November 08, 2023, 06:46:30 PM »
Hi Robert,

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

Offline Robert

  • Member
  • *
  • Posts: 247
Re: Static control demo
« Reply #5 on: November 10, 2023, 12:09:27 AM »
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.