Author Topic: How to create a WinAPI menu in MASM32 without using rc resource files  (Read 610 times)

0 Members and 1 Guest are viewing this topic.

Offline ViL

  • Avocado lover 🥑
  • C= 64
  • **
  • Posts: 52
  • Karma: 1
    • View Profile
Helloo! i've been looking for a way to add a menu using WinAPI within the same .asm file, without using resource (.rc) files

It can be done in C, like explained in this tutorial http://zetcode.com/gui/winapi/menus/

MASM32's User.lib has the same function prototypes in there (CreateMenu, AppendMenuW, SetMenu)

This is for two reasons, one is because i'd like them not to be edited/spoted using Resource Editors, the other is that i want to keep everything on one .asm source file (as what i want to do is small enough)

I've not seen anyone documenting how to do this before in MASM32 (or even other Win32-targeted compilers) and ran out of ideas trying, any kind of help is very appreciated!

thanks beforehand! :D

Offline Knurz

  • C= 64
  • **
  • Posts: 99
  • Karma: 24
    • View Profile
Helloo! i've been looking for a way to add a menu using WinAPI within the same .asm file, without using resource (.rc) files

It can be done in C, like explained in this tutorial http://zetcode.com/gui/winapi/menus/

MASM32's User.lib has the same function prototypes in there (CreateMenu, AppendMenuW, SetMenu)

This is for two reasons, one is because i'd like them not to be edited/spoted using Resource Editors, the other is that i want to keep everything on one .asm source file (as what i want to do is small enough)

I've not seen anyone documenting how to do this before in MASM32 (or even other Win32-targeted compilers) and ran out of ideas trying, any kind of help is very appreciated!

thanks beforehand! :D

I'm not that big assembly crack..but.. you can use the same functions as you use them in C, if you take a look at MessageBox function you can call it in two ways:

Code: [Select]
push HWND
push offset MsgText
push NULL
push NULL
call MessageBox

If you want to use a Macro, use INVOKE which does the stack-operations for you:
Code: [Select]
INVOKE MessageBox, HWND, offset MsgText, NULL, NULL
This should work for every win32 Function too.

 :cheers:

Remember what the dormouse said: Feed your head

Offline ViL

  • Avocado lover 🥑
  • C= 64
  • **
  • Posts: 52
  • Karma: 1
    • View Profile
Hii Knruz and thanks for the tips!, i didn't knew about the first way! :D

After a lot of research i could figure it out and ported everything that tutorial shows to MASM32, i hadn't cleaned the source nor commented it but i think it is readable enough, though, if anyone got a question please tell me in a comment!

All options emit a sound (except exit :) ) This is how it looks like:



it's all just one .asm file:

https://pastebin.com/raw/Sx2NJHr6

you can download it, save it as main.asm, and compile it in MASM32 with these both commands (assuming you have MASM32 installed in C:\):

    C:\masm32\bin\ml.exe /c /coff /nologo main.asm

to assemble and

    C:\masm32\bin\link.exe /nologo /subsystem:windows main.obj

to link

i hope it may be of help to anyone! = 3

edit: attached exe and asm file in if that's better :D
« Last Edit: June 22, 2018 by ViLXDRYAD »

Offline Siekmanski

  • ZX 81
  • *
  • Posts: 8
  • Karma: 3
    • View Profile
Hi ViLXDRYAD,

Did you know there is also a Masm Forum ( it has even a new Game Development section )

http://masm32.com/board/index.php

Offline ViL

  • Avocado lover 🥑
  • C= 64
  • **
  • Posts: 52
  • Karma: 1
    • View Profile
hii, Siekmanski! and nope, i didn't knew about the forums!, seems like a huge source! x3

i'll be around to check some posts there, thanks for sharing it! :D

Offline Knurz

  • C= 64
  • **
  • Posts: 99
  • Karma: 24
    • View Profile
Hii Knruz and thanks for the tips!, i didn't knew about the first way! :D

i hope it may be of help to anyone! = 3

edit: attached exe and asm file in if that's better :D

Well, worked out fine for me too because I needed some asm frame to work with, now I'm capturing yours *evil laugh* :)

Edit: Thanks for sharing the source
« Last Edit: June 22, 2018 by Knurz »
Remember what the dormouse said: Feed your head

Offline ViL

  • Avocado lover 🥑
  • C= 64
  • **
  • Posts: 52
  • Karma: 1
    • View Profile
lol, and you are welcome! = D

Offline Siekmanski

  • ZX 81
  • *
  • Posts: 8
  • Karma: 3
    • View Profile
Hi Knurz,

Code: [Select]
push HWND
push offset MsgText
push NULL
push NULL
call MessageBox

The push order should be reversed.

Code: [Select]
push NULL
push NULL
push offset MsgText
push HWND
call MessageBox



Offline Knurz

  • C= 64
  • **
  • Posts: 99
  • Karma: 24
    • View Profile
Hi Knurz,

Code: [Select]
push HWND
push offset MsgText
push NULL
push NULL
call MessageBox

The push order should be reversed.

Code: [Select]
push NULL
push NULL
push offset MsgText
push HWND
call MessageBox

Hi!

Thanks, as I said, I'm not really an assembler guy =).

 :cheers:
Remember what the dormouse said: Feed your head