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 version 3 with icon, menu and manifest

Started by hutch--, July 02, 2016, 08:55:38 PM

Previous topic - Next topic

hutch--

I eventually found a form of manifest that works OK on a Win64 executable. The version below has conventional resources of an icon, menu and manifest file. I have added a couple of macros in the macros64.inc file and its starting to read like reasonable code. Note that the icon is a 3 resolution RGB/A version that is 15k in size. The executable is about 5k.


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

    OPTION DOTNAME
    option casemap:none

    include \masm64\include\temphls.inc
    include \masm64\include\win64.inc
    include \masm64\include\kernel32.inc
    include \masm64\include\user32.inc
    include \masm64\include\msvcrt.inc

    includelib \masm64\lib\kernel32.lib
    includelib \masm64\lib\user32.lib
    includelib \masm64\lib\msvcrt.lib

    OPTION PROLOGUE:rbpFramePrologue
    OPTION EPILOGUE:rbpFrameEpilogue

    include macros64.inc

    WNDCLASSEX64 STRUCT QWORD
      cbSize        dd ?
      style         dd ?
      lpfnWndProc   dq ?
      cbClsExtra    dd ?
      cbWndExtra    dd ?
      hInstance     dq ?
      hIcon         dq ?
      hCursor       dq ?
      hbrBackground dq ?
      lpszMenuName  dq ?
      lpszClassName dq ?
      hIconSm       dq ?
    WNDCLASSEX64 ENDS

    .data
      ClassName db "API Window Class",0
      AppName   db "ML64 Example Window",0

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

  .code

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

main proc

    LOCAL wcex:WNDCLASSEX64

    invoke GetModuleHandle,0
    mov hInstance, rax

    invoke LoadIcon,hInstance,10
    mov hIcon, rax

    mov wcex.cbSize,          SIZEOF WNDCLASSEX64
    mov wcex.style,           0
    mrm wcex.lpfnWndProc,     OFFSET WndProc
    mov wcex.cbClsExtra,      0
    mov wcex.cbWndExtra,      0
    mrm wcex.hInstance,       hInstance
    mrm wcex.hIcon,           hIcon
    mov wcex.hCursor,         10003h
    mov wcex.hbrBackground,   COLOR_WINDOW
    mrm wcex.lpszMenuName,    0
    mrm wcex.lpszClassName,   OFFSET ClassName
    mrm wcex.hIconSm,         hIcon

    invoke RegisterClassEx, ADDR wcex

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

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

    invoke GetSystemMetrics,SM_CYSCREEN
    mov r11, rax
    shr rax, 2
    mov top, rax

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

    invoke CreateWindowEx,0,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW or WS_VISIBLE,\
           lft,top,wid,hgt,0,0,hInstance,0
    mov hWnd, rax

    invoke LoadMenu,hInstance,100
    invoke SetMenu,hWnd,rax

    call msgloop

    invoke ExitProcess, rax
    retn

main endp

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

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

msgloop proc

    LOCAL msg   :MSG

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

  @@:
    fn64 TranslateMessage,rdi
    fn64 DispatchMessage,rdi
  gmsg:
    fn64 GetMessage,rdi,0,0,0
    test rax, rax
    jnz @B

    mov rdi, r11                ; restore rdi
    retn

msgloop endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

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

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

WndProc proc

    LOCAL64 hWin
    LOCAL64 uMsg
    LOCAL64 wParam
    LOCAL64 lParam

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

    .if uMsg == WM_COMMAND
      .if wParam == 1000
        fn64 SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL

      .elseif wParam == 10000
        fn64 MessageBox,hWin,txt("Example with icon and menu."),txt("About ML64 Example"),0

      .endif

    .elseif uMsg == WM_CLOSE
      fn64 MessageBox,0,txt("Seeya round like a Rubens."),txt("WM_CLOSE here"),0
      fn64 SendMessage,hWin,WM_DESTROY,0,0

    .elseif uMsg == WM_DESTROY
      fn64 PostQuitMessage,NULL

    .endif

    fn64 DefWindowProc,hWin,uMsg,wParam,lParam

    retn

WndProc endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

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

end

jcfuller

Hutch,
  Good stuff!!
This is what I came up with for a batch file. It should work with any recent 64 bit version of Visual Studio??
It will also detect an rc file with the same name as the asm file,in the same folder or in an res/ folder, and compile and link it to the exe.

James



:: =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
:: batch file for compiling ML64 source
:: usage -> ML_64.BAT MainFile [no extension asm assumed]
:: =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
@setlocal enableextensions enabledelayedexpansion
@ECHO OFF
SET F=%~nx1
IF EXIST "%F%.asm" (
  SET FN="%F%.asm"
  GOTO start
)
GOTO usage
:start

SET XTYPE=x86_amd64
SET MACASM=ML64.EXE


IF DEFINED VS140COMNTOOLS (
  CALL "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" %XTYPE%
  GOTO got_tools
)

IF DEFINED VS120COMNTOOLS (
  CALL "%VS120COMNTOOLS%..\..\VC\vcvarsall.bat" %XTYPE%
  GOTO got_tools
)

IF DEFINED VS110COMNTOOLS (
  CALL "%VS110COMNTOOLS%..\..\VC\vcvarsall.bat" %XTYPE%
  GOTO got_tools
)

IF DEFINED VS100COMNTOOLS (
  CALL "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" %XTYPE%
  GOTO got_tools
)
:got_tools

IF EXIST "res\%F%.rc" (
  ECHO Compiling resources.....
  cd res
  Rc "%F%"
  SET VRES="res\%F%.res"
  cd ..
) ELSE (
  IF EXIST "%F%.rc" (
    ECHO Compiling resources.....
    Rc "%F%"
    SET VRES="%F%.res"
  )
)

%MACASM% /c %FN%
link /SUBSYSTEM:WINDOWS /ENTRY:main /LARGEADDRESSAWARE %F%.obj %VRES%
GOTO done

:usage
ECHO **************************************************************
ECHO  Usage:  ML_64.BAT MainFile [no extension asm assumed]
ECHO **************************************************************
:done
endlocal


jj2007

#2
Works fine :t

Question to the HJWasm & AsmC developers:
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

What do these two macros do now?
Can they be modified in HJWasm/AsmC, so that a simple MyTest proc uses rsi rdi rbx arg1, arg2 does what it should do, using the ABI?

P.S.:
- There was a short thread by Yves here some time ago, with no significant result.
- A very short description of the Prologue macro is attached, excerpt from some \Masm32\Help\*.chm file

Vortex

What's the meaning of those two lines?

OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue

mineiro

Your version of win2 and win3 worked fine simulated on other O.S. You're on the right path.
I think the link below have some copy and paste to manifest files.
https://msdn.microsoft.com/en-us/library/windows/desktop/dn481241(v=vs.85).aspx
Congratulations.

----edited----
emulated to simulated
I'd rather be this ambulant metamorphosis than to have that old opinion about everything