6-26-2015
Have a program that uses an rsrc file.
The screen shows 2 programs. The rsrc data shows the same
for both programs. It should not be the same. It would be
nice if I could have 2 different rsrc files or be able to grey
out the items not needed in either program.
I don't think it is possible to use 2 different rsrc files in
the same program. Greying out an item might be possible.
How to do this is the problem. Point me where to read or give
an example how to accomplish this Please.
hi Jack
could you please be a little clearer in explaining exactly what you are trying to do ?
Ok Dave I will give it a whirl.
Program A uses an RSRC file to do things such as Cut, Paste, Find etc.
Program A calls in two programs B and C.
Programs B and C are then listed on the screen.
The same RSRC file is listed above programs B and C and they are identical.
I would like to be able to select a different combination of cut, paste, find etc.
for programs B and C. Or at least be able to grey out ones that don't apply
to program B or C.
Hope this helps....
Hello shankle,
I believe you're talking about the menus, which are defined in the resource file. You want to change the menus for B and C. What you need are dynamic menu commands like loadmenu, createmenu, showmenu, modifymenu, enablemenuitem. dedndave in a recent thread (which I'm 2 lazy to find at the moment) posted a program that does dynamic menu mods based on file inputs, sounds like exactly what you want.
6-29-2015
I have been trying for days to get EnableMenuItem to work.
I would suspect the handle I am using is incorrect.
My problem is that I don't know how to find the handle.
I have defined hMenu using LOCAL in Winmain and Wndproc.
This RSRC script is from an old MASM32 program that I have
linked in a GoAsm 64-bit program. It works in the GoAsm
program but I need to grey out various fields occasionally.
There are about 100 instructions on using menus on the
Microsoft site so it is a tad bewildering.
These are 2 lines of code that do not work in the GoAsm
program:
invoke EnableMenuItem, 600,1010,[MF_GRAYED]
invoke EnableMenuItem, [hMenu],1101,[MF_BYPOSITION | MF_GRAYED]
#define IDM_CUT 1101
#define IDM_COPY 1102
#define IDM_PASTE 1103
#define IDM_FIND 1104
#define IDM_UNDO 1105
#define IDM_EXIT 1010
600 MENUEX MOVEABLE IMPURE LOADONCALL DISCARDABLE
BEGIN
POPUP "&File", , , 0
BEGIN
MENUITEM "&Exit", IDM_EXIT
END
POPUP "&Edit", , , 0
BEGIN
MENUITEM "C&ut", IDM_CUT
MENUITEM "COPY", IDM_COPY
MENUITEM "PASTE", IDM_PASTE
MENUITEM "&FIND", IDM_FIND
MENUITEM "UNDO", IDM_UNDO
END
END
.const
menuname equ 600
IDM_CUT equ 1101
IDM_COPY equ 1102
IDM_PASTE equ 1103
IDM_FIND equ 1104
IDM_UNDO equ 1105
IDM_EXIT equ 1010
IDOK equ 1
IDCANCEL equ 2
I would appreciate it if someone could enlighten me.
sorry i didn't get back sooner, Jack
EnableMenuItem uses a handle for the menu - and a number for the menu item
so, let's say you have an Main menu, with File, Edit, View, Help submenus
typically, you will have the handle for the Main menu
either when you load it or attach it
if not, use GetMenu to get the Main menu attached to a window
now, you want a handle for the submenus, File, Edit, View, Help
these menus are attached to the Main menu, in the order created
but, you can get the handles by using numbers 0, 1, 2, 3
File = 0
Edit = 1
View = 2
Help = 3
if they were created in that order (also the order they appear)
use GetSubMenu for to get the handle(s)
INVOKE GetSubMenu,hmenuMain,1 ;get the handle for the Edit menu
mov hmenuEdit,eax
your submenus may have submenus below them, as well
in that case, use the handle for the submenu, and the item number to get the sub-sub-menu handle
now, you can use EnableMenuItem
if you use the MF_BYPOSITION flag, it again wants a zero-based number of the item
if you use the MF_BYCOMMAND flag, you use the ID number (1101, etc), typically in the form of an EQU like IDM_CUT
you can only use one of those flags - not both together
MF_BYCOMMAND is the default (=0)
INVOKE EnableMenuItem,hmenuEdit,IDM_CUT,MF_BYCOMMAND or MF_GRAYED or MF_DISABLED
INVOKE EnableMenuItem,hmenuEdit,0,MF_BYPOSITION or MF_GRAYED or MF_DISABLED
both calls do the same thing
Thanks Dave. Will give it a try after more study.
I use the SetMenuItemInfo function because you can change all the attributes with it. Seems to be deprecated, though? - but it works. It's actually a little more complex than EnableMenuItem but if you continue to have problems, it may be an alternative
Quote from: shankle on June 30, 2015, 01:11:08 AM
These are 2 lines of code that do not work in the GoAsm
program:
invoke EnableMenuItem, 600,1010,[MF_GRAYED]
invoke EnableMenuItem, [hMenu],1101,[MF_BYPOSITION | MF_GRAYED]
You should not put constants in brackets. That way they will be treated as memory addresses.
6-30-2015
Details of the .const and RSRC script are in post #4
Trying to make this msg smaller.
hMenuMain dq 0
hMenuSub1 dq 0
Local HWND
This code is placed in Winmain after the Createwindowex,
Showwindow and Updatewindow.
invoke GetMenu, [HWND]
mov [hMenuMain],rax
invoke EnableMenuItem, [hMenuMain],600,MF_BYCOMMAND or MF_ENABLED
invoke GetSubMenu, [hMenuMain],5 ; idm_exit
mov [hMenuSub1],rax
invoke EnableMenuItem, [hMenuSub1],5,MF_BYPOSITION or MF_GRAYED ; idm_exit
The RSRC script is loaded at compile time and I have no idea
what the handle is. I suspect why the above code is not working is that
the main handle is invalid.
Could this statement in the RSRC script be invalid?
600 MENUEX MOVEABLE IMPURE LOADONCALL DISCARDABLE
yah - that's not working because the window has no menu when you call GetMenu
a better way to do it is to use LoadMenu, before CreateWindowEx
then, you have a menu handle to pass to CreateWindowEx - and the menu is "automatically" attached to the window
and - you have the handle - no need to use GetMenu
another advantage is that you don't have to DestroyMenu because DestroyWindow takes care of it for you
INVOKE LoadMenu,[hInstance],600
mov [hmenuMain],eax
INVOKE CreateWindowEx,..,..,..,..,..,..,..,....,[hmenuMain],[hInstance],lParam
notice that EAX could be used to replace [hmenuMain] in CreateWindowEx, if it hasn't been altered
(lParam is often NULL)
i guess it's RAX for 64-bit code :P
6-30-2015 2:36
Details of the .const and RSRC script are in post #4
Trying to make this msg smaller.
hMenuMain dq 0
hMenuSub0 dq 0
hMenuSub5 dq 0
; load the Rsrc menu here
invoke LoadMenu,[hInstance],600
mov [hMenuMain],rax
; puts Pane 1 to screen
invoke CreateWindowEx, NULL,addr szDisplayName1,addr AppName,\
WS_VSCROLL | WS_OVERLAPPEDWINDOW,[RR.left],[RR.top],[RR.right],\
[savemiddleofY],NULL,[hMenuMain],[hInst],NULL
^
; this is now working:)
invoke GetSubMenu, [hMenuMain],5 ; idm_exit
mov [hMenuSub5],rax
invoke EnableMenuItem, [hMenuSub5],5,MF_BYPOSITION or MF_GRAYED
; This is not working
invoke GetSubMenu, [hMenuMain],0 ; idm_cut
mov [hMenuSub0],rax
invoke EnableMenuItem, [hMenuSub0],0,MF_BYPOSITION or MF_GRAYED
; If you notice in post #4 the RSRC script has 2 popups
&file and &edit
The one for &file is working and the one for &edit is not.
i made an example
1) it's MASM syntax
2) it's 32-bit code
i think you can handle those :P
i put the menu item stuff in the WM_CREATE handler code
the EQU's are in the project INC file
Thanks is hardly adequate Dave, but I do thank you.
The Menu code is now working beautifully.
Hope you didn't spend to much of your time creating the zip file.
Seems like a good subject for a book with lots of examples and
assuming people aren't familiar with the subject. In other words
"Menus for Dummies".
no problem, Jack :t
the SmallWindow program was already written
it only took 10 minutes or so to add the menu stuff :P
Same program - trying to finalize as a production program.
Link is having a hissy:
'menu64.obj' is not recognized as an internal or external command,
operable program or batch file.
I originally made a copy for testing called B from program A.
I had no problems compiling program B when testing.
I now have to rename program B to program A.
When I did this the linker gave the above error.
I used the same RSRC script file - no changes were made to it.
I think I am on the latest Golink - V. 1.0.2.0
Thanks for any guidance.
Check your GoRC command line. If you have the /r option, the output file from the assumed input file menu64.rc would be menu64.res instead, so you could try menu64.res on the GoLink command line. Switching the GoRC command line option to /o should output menu64.obj (you get both OBJ and RES without these options).
Thank you WJR for responding.
Problem is now solved.