News:

Masm32 SDK description, downloads and other helpful links

Main Menu

my Basic Window template 64 bit version.

Started by zedd151, October 05, 2022, 05:24:52 AM

Previous topic - Next topic

zedd151

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.
        ; 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
Regards, zedd...

C3

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

Quote from: C3 on October 05, 2022, 07:36:41 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:
Regards, zedd...

C3

QuoteIt'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

Here is my template, for comparison. Plain Masm64 SDK :cool:

zedd151

Quote from: jj2007 on October 05, 2022, 11:22:59 AM
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:
Regards, zedd...

daydreamer

I am trying to make templates for maybe make editor(android)
Good resources  to include few in your editor and use textreplace from what user choice of the usual windows class name,project name,file name.asm
my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

hutch--

Magnus,

I think if you want editors in Android, you willl have to learn how to write softwrae in Android as x86 and x64 code will not work there.
http://www.masm32.com    :biggrin:  :skrewy:

daydreamer

#8
Hutch i had in mind cross Development editor
I have some c skill and knowledge of similar settext and gettext api for edit control
Seen on google play,"quick edit text editor"?
https://play.google.com/store/apps/details?id=com.rhmsoft.edit&hl=en&gl=US
Same name as qe
sue them for using same name? :tongue:
Free, but ads popping up

my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

HSE

Quote from: hutch-- on December 04, 2022, 09:46:17 AM
you willl have to learn how to write softwrae in Android as x86 and x64 code will not work there.

You have to use Java, wich is platform independent (and easy  :biggrin:)

Even if Android is just a flavour of Linux, applications must have some kind of stub in Java.

Quote from: daydreamer on December 05, 2022, 05:08:22 PM
i had in mind cross Development editor

To program directly in tablet or phone you can use Termux. Then you have a terminal in Android, with vi, vim, emacs, micro, nano and all kind of editors and tools usual in Linux. Also you can install C, Java, Python and more.

The true problem is the keyboard  :biggrin: :biggrin: :biggrin:
Equations in Assembly: SmplMath

daydreamer

Hector its crossdevelopment on android for PC
so made useful windows GUI template
I already have posted very old android Java app,only got so far as start with hello android and mod it
http://masm32.com/board/index.php?topic=7084.0
I have very old android sdk and old version of eclipse IDE(also java) which I used to made it
my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

Seems this thread took a left turn.  :tongue:  Glad to have inspired you, daydreamer.
Good luck Magnus with your project, let us know how it turns out. Even post it, if you feel so inclined.  :biggrin:
But it would most likely be better suited in "Miscellaneous Projects"  probably, or "Hardware Corner" maybe".
Regards, zedd...

daydreamer

Thanks zedd :thumbsup:
I have typed in Windows gui from my memory, not finished
Is it good design to have template.asm source file only have main loop and wndproc with most messages only cases and empty beside paint message ? And template. Inc companion file proc's and. Data for register class and a standard createwindow?
Main file could have the only necessary equates window width and window height?
my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

Missing source code files now attached here.  :smiley:
Regards, zedd...