News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Window 8 example

Started by hutch--, July 16, 2016, 08:58:15 PM

Previous topic - Next topic

hutch--

I have added as much of the new stuff as possible specifically testing for the minimum size of a bare window with a menu, icon and manifest. It comes in at 6k which is OK for a 64 bit file. I have tweaked a number of macros from the 32 bit macro file to work with 64 bit with the format of "void" for procedures that don't want a return value and "function" for those that return a value. As normal any return is in RAX.

I am sorry not to post the developing library and macros but I am adding to them continuously at the moment.

This is the source for the attached example.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm64\include\masm64rt.inc

    .data
      classname db "ML64_Window_Class",0
      appname db "ML64 Example Window",0
      pClass dq classname
      pAppnm dq appname

    .data?
      hInstance dq ?
      hWnd      dq ?
      sWid      dq ?
      sHgt      dq ?
      lft       dq ?
      top       dq ?
      wid       dq ?
      hgt       dq ?
      hIcon     dq ?
      hCursor   dq ?
      hMnu      dq ?

  .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    .stack

    LOCAL wc:WNDCLASSEX

    mov hInstance, function(GetModuleHandle,0)
    mov hIcon,     function(LoadIcon,hInstance,10)
    mov hCursor,   function(LoadCursor,0,IDC_ARROW)

    mov wc.cbSize,          SIZEOF WNDCLASSEX
    mov wc.style,           0
    mrm wc.lpfnWndProc,     OFFSET WndProc
    mov wc.cbClsExtra,      0
    mov wc.cbWndExtra,      0
    mrm wc.hInstance,       hInstance
    mrm wc.hIcon,           hIcon
    mrm wc.hCursor,         hCursor
    mov wc.hbrBackground,   COLOR_WINDOW
    mrm wc.lpszMenuName,    0
    mrm wc.lpszClassName,   pClass
    mrm wc.hIconSm,         hIcon

    void(RegisterClassEx,ADDR wc)

  ; ------------------------------------
  ; centred half height and width window
  ; ------------------------------------
    void(GetSystemMetrics,SM_CXSCREEN)
    mov r11, rax
    shr rax, 2
    mov lft, rax

    mov rax, r11
    shr rax, 1
    mov wid, rax

    void(GetSystemMetrics,SM_CYSCREEN)
    mov r11, rax
    shr rax, 2
    mov top, rax

    mov rax, r11
    shr rax, 1
    mov hgt, rax

    invoke CreateWindowEx,0,pClass,pAppnm,\
           WS_OVERLAPPEDWINDOW or WS_VISIBLE,\
           lft,top,wid,hgt,0,0,hInstance,0
    mov hWnd, rax

    void(LoadMenu,hInstance,100)
    void(SetMenu,hWnd,rax)

    call msgloop

    void(ExitProcess,rax)

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

msgloop proc

    .stack

    LOCAL msg   :MSG
    LOCAL .rdi  :QWORD

    mov .rdi, rdi               ; preserve rdi
    lea rdi, msg                ; load structure address
    jmp gmsg

  @@:
    void(TranslateMessage,rdi)
    void(DispatchMessage,rdi)
  gmsg:
    void(GetMessage,rdi,0,0,0)
    test rax, rax
    jnz @B

    mov rdi, .rdi               ; restore rdi
    ret

msgloop endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

WndProc proc

    LOCAL hWin      :QWORD
    LOCAL uMsg      :QWORD
    LOCAL wParam    :QWORD
    LOCAL lParam    :QWORD

    mov hWin, rcx
    mov uMsg, rdx
    mov wParam, r8
    mov lParam, r9

    .switch uMsg

      .case WM_COMMAND
        .switch wParam
          .case 1000
            void(SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL)

          .case 10000
            void(MessageBox,hWin,"Example with icon, menu and manifest.","About ML64 Example",MB_OK)

        .endsw

      .case WM_CLOSE
        void(MessageBox,0,"Seeya round like a Rubens.","WM_CLOSE here",MB_OK)
        void(SendMessage,hWin,WM_DESTROY,0,0)

      .case WM_DESTROY
        void(PostQuitMessage,NULL)

    .endsw

    void(DefWindowProc,hWin,uMsg,wParam,lParam)

    ret

WndProc endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end