Author Topic: my Basic Window template 64 bit version.  (Read 425 times)

zedd151

  • Member
  • *****
  • Posts: 1579
my Basic Window template 64 bit version.
« on: October 05, 2022, 05:24:52 AM »
Here is my basic window template coverted to 64 bit MASM. It has been quite some time that I had written anything in 64 bit, I had forgotten many of the differences between 32 and 64. But luckily some programs can be *almost* directly converted. Others need some 'adjustments' to be done to the code.  :biggrin: 
A couple of features here. Automatic centering of window, About box, Menu.
Code: [Select]
        ; This source code written by swordfish @ masm32.com  :D
        include \masm64\include64\masm64rt.inc
   
        wwidth      equ 1024
        wheight     equ 768
        cwidth      equ 960
        cheight     equ 640
        ws          equ WS_BORDER or WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU
        menuid      equ 600
        iconid      equ 500
       
    .data?
        hWnd        dq ?
        hInstance   dq ?
        hAlready    dq ?
       
    .const
        wclass      db "BasicWindowClass", 0
        dname       db "Basic", 0
        about       db "Basic Window with Menu", 0
        smscr       db "Screen size must be at least 1024 x 768", 0
       
    .code
   
    start proc
        invoke FindWindow, addr wclass, 0
        cmp rax, 0
        je notanother
        mov hAlready, rax
        invoke ShowWindow, hAlready, SW_RESTORE
        invoke SetForegroundWindow, hAlready
        mov rax, 0
        jmp twoinst
      notanother:
        invoke GetSystemMetrics, SM_CXSCREEN
        cmp rax, wwidth
        jb smallscr
        invoke GetSystemMetrics, SM_CYSCREEN
        cmp rax, wheight
        jb smallscr
        invoke GetModuleHandle, 0
        mov hInstance, rax
        invoke RegWindow, hInstance, addr wclass
        invoke WinMain, hInstance, addr wclass, addr dname
        jmp overit
      smallscr:
        invoke MessageBox, 0, addr smscr, addr dname, 0
      twoinst:
      overit:
        invoke ExitProcess, rax
    start endp
       
    WinMain proc hi:qword, cn:qword, dn:qword
    local msg:MSG, Wtx:qword, Wty:qword
        invoke CreateWindowEx, 0, cn, dn, ws, 0, 0, 0, 0, 0, 0, hi, 0
        mov hWnd, rax
        invoke LoadMenu, hi, menuid
        invoke SetMenu, hWnd, rax
        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd
      StartLoop:
        invoke GetMessage, addr msg, 0, 0, 0
        cmp rax, 0
        je ExitLoop
        invoke TranslateMessage, addr msg
        invoke DispatchMessage, addr msg
        jmp StartLoop
      ExitLoop:
        mov rax, msg.wParam
        ret
    WinMain endp
   
    WndProc proc hWin:qword, uMsg:qword, wParam:qword, lParam:qword
      .if uMsg == WM_CREATE
        invoke CenterMain, hWin, wwidth, wheight
      .elseif uMsg == WM_COMMAND
        .if wParam == 1000
          invoke SendMessage, hWin, WM_SYSCOMMAND, SC_CLOSE, 0
        .elseif wParam == 1900
          fn MessageBox, hWin, addr about, addr dname, MB_OK
        .endif
      .elseif uMsg == WM_CLOSE
      .elseif uMsg == WM_DESTROY
        invoke PostQuitMessage, 0
        xor rax, rax
        ret
      .endif
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp
   
    RegWindow proc hi:qword, cn:qword
    local wc:WNDCLASSEX, icn:qword
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        lea rax, WndProc
        mov wc.lpfnWndProc, rax
        mov wc.cbClsExtra, 0
        mov wc.cbWndExtra, 0
        mrm wc.hInstance, hi
        mov wc.hbrBackground, COLOR_BTNFACE+6
        mov wc.lpszMenuName, 0
        mrm wc.lpszClassName, cn
        invoke LoadIcon, hi, iconid
        mov wc.hIcon, rax
        mov icn, rax
        invoke LoadCursor, 0, IDC_ARROW
        mov wc.hCursor, rax
        mrm wc.hIconSm, icn
        invoke RegisterClassEx, addr wc
        ret
    RegWindow endp
   
    CenterMain proc hWin:qword, wd:qword, ht:qword
    local rct:RECT, h:qword, w:qword, x:qword, y:qword
      aa:
        invoke MoveWindow, hWin, x, y, wd, ht, 0
        invoke GetClientRect, hWin, addr rct
        mov eax, rct.right
        sub eax, rct.left
      .if eax } 872 ; desired client rect width
        dec wd
        jmp aa
      .elseif eax { 872
        inc wd
        jmp aa
      .endif
      bb: ; dynamically adjusting height of the window for proper client rect size
        invoke MoveWindow, hWin, x, y, wd, ht, 0
        invoke GetClientRect, hWin, addr rct
        mov eax, rct.bottom
        sub eax, rct.top
      .if eax } 604 ; desired client rect height
        dec ht
        jmp bb
      .elseif eax { 604
        inc ht
        jmp bb
      .endif
        invoke GetSystemMetrics, SM_CYMENU
        add ht, rax
        invoke SystemParametersInfoA, SPI_GETWORKAREA, 0, addr rct, 0
        xor rax, rax
        mov eax, rct.right
        sub rax, wd
        sar eax, 1
        mov x, rax
        xor rax, rax
        mov eax, rct.bottom
        sub rax, ht
        sar eax, 1
        mov y, rax
        invoke MoveWindow, hWin, x, y, wd, ht, TRUE
        ret
    CenterMain endp


    end
« Last Edit: October 08, 2022, 10:51:38 PM by zedd151 »
Nugget and Gypsy Youtube channel. New videos twice a week or so. If you like the videos, please subscribe and comment.  :biggrin:

C3

  • Regular Member
  • *
  • Posts: 14
Re: my Basic Window template
« Reply #1 on: October 05, 2022, 07:36:41 AM »
Hi zedd151,

I keep also templates for to start new ideas developement faster. I also use Git and GitLab on my own Docker. The history in GitLab Project is also great to look backwards what has changed. 64bit is easy as 32bit is too.

I managed to read thru Intel Architectures Software Developer Manual, big book over 4800 pages. Now I'm doing research of Windows API's with Microsoft Docs and some good books.

Also I'm gonna now be more active here.

Cheers. Petter!

zedd151

  • Member
  • *****
  • Posts: 1579
Re: my Basic Window template
« Reply #2 on: October 05, 2022, 07:43:45 AM »
Also I'm gonna now be more active here.
It's good to hear that. We need more members here that are enthusiastic about coding in assembly.  :biggrin:
Nugget and Gypsy Youtube channel. New videos twice a week or so. If you like the videos, please subscribe and comment.  :biggrin:

C3

  • Regular Member
  • *
  • Posts: 14
Re: my Basic Window template
« Reply #3 on: October 05, 2022, 07:50:37 AM »
Quote
It's good to hear that. We need more members here that are enthusiastic about coding in assembly.  :biggrin:

Yeah, in my case, it's only assembly, nothing else. Jump to deep world of machine language...

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: my Basic Window template
« Reply #4 on: October 05, 2022, 11:22:59 AM »
Here is my template, for comparison. Plain Masm64 SDK :cool:
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

zedd151

  • Member
  • *****
  • Posts: 1579
Re: my Basic Window template
« Reply #5 on: October 05, 2022, 12:40:46 PM »
Here is my template, for comparison.
lol I was expecting MB_Win_Skel or something like that.  :toothy:
Okay, plain and simple window template. Thank you for your contribution.
Your program window needs a little centering.    :tongue:
Nugget and Gypsy Youtube channel. New videos twice a week or so. If you like the videos, please subscribe and comment.  :biggrin: