Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Using Menu

meistrv
Beginner
1,022 Views
Hello,

help me, please, with this simple (for you) question: Is it possible to use menus in "A simple dialog Based application"? I can create the menu (I can see it when the application runs) and I can Load it (nonzero return value from the LoadMenu function). But I can't find out how to "link" the action (subroutine) with the menu item.
Thank you

V.Meistr
0 Kudos
7 Replies
Jugoslav_Dujic
Valued Contributor II
1,022 Views
See my MenuDialog sample.

Jugoslav
0 Kudos
meistrv
Beginner
1,022 Views
Thank you very much for the sample, it works fine. I have another question: is it possible to check menu items with the CheckMenuItem routine?
As the first argument I sent there the result from the LoadMenu function. As the second argument the number of the item (from resource.fd) and as the third I tried "MF_CHECKED" and "IOR(MF_BYCOMMAND,MF_CHECKED)" (I got this from the Lawrence book (CVF: A Guide to Creating...)).
None worked.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,022 Views
Yeah, but... the drop-down menus are not considered part of main menu, but they are its submenus with their own handles. Thus, you have to obtain their handles first using GetSubMenu(hParentMenu, Index) API.

Attached is my wrapper module, XFTMenu, which does this for you. The basic idea is to be used as you (wrongly) expected: have one menu & its submenus represented by a single structure, X_MENU, and operate on this structure. Sorry, no reference is written as yet (and comments are sparse as well):
TYPE(X_MENU):: xMenu
xMenu = XLoadMenu(IDR_MENU1)
...
lret = XSetWindowMenu(Dlg%hWnd, xMenu)
lret = XMenuSet(xMenu, ID_FILE_NEW, .FALSE., XMENU_ENABLE)
lret = XMenuSet(xMenu, ID_FILE_NEW, .TRUE., XMENU_STATE) !Checked
etc.

Jugoslav
0 Kudos
meistrv
Beginner
1,022 Views
Sorry but I still can't manage to check the menu item

Here is a part of the code:

hMenu=GetSubMenu(ghmenu,1)
iret=GetMenuItemID(hmenu,0)
IF(something) THEN
iret=CheckMenuItem(hmenu,iret,IOR(MF_BYCOMMAND,&
&MF_UNCHECKED))
ELSE
iret=CheckMenuItem(hmenu,iret,IOR(MF_BYCOMMAND,&
&MF_UNCHECKED))
ENDIF

GetSubMenu returns a number. I use it in GetMenuItemID and it returns correct value of the identifier of the menu item (the same as is in resource.fd). Return values of the CheckMenuItem functions are 0 (unchecked) and 8 (checked).

When I use this function (checkmenuitem) in an SDI Application, everything is ok, but in this dialog-based application it doesn't work.
Thank you for some help

Vit
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,022 Views
Hmmm, the code looks OK to me (except that you have MF_UNCHECKED in both IF branches, but I assume it's just a copypasto). Return values look sensible as well (i.e. as if it works)...

Sorry for a stupid question, but are you aware that menu indices are zero-based -- the code you posted checks the first item (0) of the second (1) submenu? Other than that, I'm running out of suggestions (a cause may be a previous bad call to SetMenuItemBitmaps, but that's a wild shot).

Jugoslav
0 Kudos
meistrv
Beginner
1,022 Views
Yes, MF_UNCHECKED is from copy-paste, it is OK in the program. The second thing is OK too, I realy want to check first item in second submenu (actually the return value from the GetMenuItemID function is exactly the one I want to check).
I put there a static box where the user is told whether it's checked or not. It's really not nice, but it works. ;-)

Thank you for your help Jugoslav.

Vit

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,022 Views
Just added CheckMenuItem it to MenuDialog sample (attached) and it appears to work fine... don't know what went wrong in your app.

Jugoslav
0 Kudos
Reply