News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help for newbie

Started by push_pop, October 15, 2007, 12:01:29 AM

Previous topic - Next topic

push_pop

First of all, I'm not really sure this is the right place to ask these questions. If it isn't, I'd like to know, especially if there is a better place to ask.

OK, here goes: I'm just starting to try to use Easy Code. I have a lot of experience w/assembly language (at least 8086 in real mode, not so much any stuff beyond that, like 80x86 programming). Some experience some years ago using Micro$oft's IDE (VB/C++).  But my question is much simpler than that; actually almost embarassed to ask it.

I created a simple test program, as a "Visual Win32 executable file". It has just the one window with nothing else in it.

I tried to add a couple of menus to it; using the Menu editor, I added two, following the examples given in the help, like so:
&File
>> Open
>> Close
&Edit
>> Copy

So far, so good. The menu shows up as an item under "Resources--> Menu" as
IDR_MENU1
.

But the menu doesn't appear in the program window. No matter what I do, I cannot make the menu appear. Even after building the program (w/no errors) and testing it, it still doesn't appear.

Help! What am I doing wrong here? Does the menu have to be programmatically created? Do I need to register it before it appears? I thought that menus would just automatically appear when created as a program resource.

Thanks for any help,

push_pop

gabor

Hi!

Did you assign the menu to the window?
There are 2 ways to do so:

...
mov wc.lpszMenuName,IDR_MENU1
...
invoke RegisterClassEx,addr wc

wc is a WNDCLASSEX struct, IDR_MENU1 is a resource id.
With this solution every window instance derivated from this class will have a menu described by the IDR_MENU resource.


invoke LoadMenu,hInstance,IDR_MENU1
mov hMenu,eax
invoke CreateWindowEx,NULL,offset szClassName,offset AppName,
WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN,
CW_USEDEFAULT,CW_USEDEFAULT,
640,480,NULL,hMenu,
hInst,NULL

This way the window instance only created by this CreateWindowEx call will have the menu.

Since we rarely instantiate a window owning a menu more than once (because this window would probably be the main window) either of 2 method can be used.
I hope this helps you!  :U

Greets, Gábor

Ramon Sala

Hi push_pop,

As gabor says, a menu (from the Resource Editor) is a resource that has to be loaded (LoadMenu) and attached (SetMenu) to the desired window. Anyway, when working with visual projects, Easy Code makes this internally for each window, but the menu has to be designed in the Menu Editor, not in the Resource Editor. To access the Menu Editor (only available in visual projects), select the Tools menu and then the Menu Editor option or just press Ctrl+M when the window which is going to own the menu is the active window. The Menu Editor option is disabled when no window is active as it builds the menu for the active window (to make a window active just click on it and the Menu Editor option will be enabled). I attached a simple example where you can see what I mean (just build it and run it).

Regards and thanks fo using Easy Code.

Ramon


[attachment deleted by admin]
Greetings from Catalonia

push_pop

First of all, thanks to both of you for replying so quickly. Now I remember how much I've forgotten about Windoze programming.

A couple of questions if I may (I take it by your replies that this is indeed the proper forum for this topic):

Gábor, I tried your first example but couldn't get it to "compile" (i.e., assemble): I'm wondering if you didn't make a mistake, since I assume that the member lpszMenuName is a long pointer to a zero-terminated string (I wince every time I see these Simonyi-type names, as I invariably think of the Hungarian "s" sound for "sz"). In that case, you wouldn't be able to properly move a number (IDR_MENU1, the menu ID) into it, would you? Or am I missing something here? (To make it work, I simply made up an equate for the ID:
IDR_MENU1   EQU 102

Ramon, it wasn't clear from your reply whether or not one needs to programatically activate the menus, as Gábor has explained. And I did use the Menu Editor to create the menus. So let me just ask the dumb (or not) question: Should the menus appear "automagically" when I test-run the program, or do I need to initialize them as described?

I think it's time for me to delve into some tutorial material.

Another question that I'll need answered soon: is there an on-line resource that has documentation for all the Win API functions? Or any such resource anywhere that you know of? Books, etc.?

Anyhow, no, thank you for creating this tool!

Mark Jones

Quote from: push_pop on October 15, 2007, 10:52:44 PM
Another question that I'll need answered soon: is there an on-line resource that has documentation for all the Win API functions? Or any such resource anywhere that you know of? Books, etc.?

Hello, just pointed another to the MSDN site, try this:
http://www.masm32.com/board/index.php?topic=8023.msg58729#msg58729
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

gabor

Hi!

Quote from: push_pop on October 15, 2007, 10:52:44 PM
I'm wondering if you didn't make a mistake, since I assume that the member lpszMenuName is a long pointer to a zero-terminated string (I wince every time I see these Simonyi-type names, as I invariably think of the Hungarian "s" sound for "sz"). In that case, you wouldn't be able to properly move a number (IDR_MENU1, the menu ID) into it, would you? Or am I missing something here?

For help about winapi calls I always use the win32.hlp. In this case it reads:
lpszMenuName    Points to a null-terminated character string that specifies the resource name of the class menu, as the name appears in the resource file.
                If you use an integer to identify the menu, use the MAKEINTRESOURCE macro. If this member is NULL, windows belonging to this class have
                no default menu.

That is the parameter is either a zero terminated string or a resource ID. I have to confess that I don't use easyCode and I always create equs for the resources I create in an editor just like you did.

Anyway, the point is that it is working now! Good job! :bg

Greets, Gábor

Ramon Sala

Should the menus appear "automagically" when I test-run the program, or do I need to initialize them as described?

The answer is yes. If the menu was made in the Menu Editor, it appears automatically when testing (or running the window). Otherwise, if it was made in the Resource Editor, you have to load it, Invoke LoadMenu, App.Instance, IDR_MENU1 and attach it, Invoke SetMenu, hWnd, Eax.

IDR_MENU1 has to be the menu IDentifier, while hWnd is the handle to the window where the menu is to be set and Eax is the value returned by LoadMenu API call.

Regards,

Ramon
Greetings from Catalonia