Archived

This topic is now archived and is closed to further replies.

krez

quickie - separator in menus

Recommended Posts

how do you put a separator in a menu using c++ and the win32 API? i am using a resource file for my menus, but i don''t know how to put the little greyed-out separator line in the menu:
ID_MENU MENU
BEGIN
  POPUP "&File"
  BEGIN
    MENUITEM "&New", ID_FILE_NEW
    MENUITEM "&Open", ID_FILE_OPEN
    MENUITEM "&Save", ID_FILE_SAVE
    MENUITEM "Save &As", ID_FILE_SAVEAS
    MENUITEM "??? SEPARATOR ???",ID_FILE_NULL
    MENUITEM "E&xit", ID_FILE_EXIT
  END
END
 
thanks in advance. --- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites
This will do the trick:


ID_MENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New", ID_FILE_NEW
MENUITEM "&Open", ID_FILE_OPEN
MENUITEM "&Save", ID_FILE_SAVE
MENUITEM "Save &As", ID_FILE_SAVEAS
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_FILE_EXIT
END
END

Share this post


Link to post
Share on other sites
ah, here''s another quickie...
how would i put spacing in the menu at the top of the window?
you know, how some programs have the help menu all the way to the right, even though the other menus are left aligned.
hmm... wait a minute, it seems i can''t find an example of this in any programs on my computer... did i dream this? is it from an earlier version of windows? oh well... if anyone knows how to do this (if it is possible, i could have sworn i saw it somewhere) please tell me
gracias!

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites
Don''t worry, I''ve seen it before too (but strangely, not recently. Hmmm...)

Anyway, a quick dip into MSDN reveals the following:
quote:

How to Right-Justify Menu Items in Windows 95


Last reviewed: September 29, 1995
Article ID: Q125675
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:
    - Microsoft Windows 95 version 4.0

SUMMARY


In Windows 95, right-justify (right-align) a menu item by using the MFT_RIGHTJUSTIFY type in MENUITEMINFOSTRUCTURE.

MORE INFORMATION


There is a new menu type in Windows 95, MFT_RIGHTJUSTIFY type, which you can use to right justify a menu item. The Windows version 3.1 method of prefixing the string with "\a" or "\b" will no longer work.

To right justify a menu item in Windows 95:
  1. Get the menu handle of the original menu.

  2. Get the original menu item information stored in the MENUITEMINFO structure.

  3. Change the menu item type to include MFT_RIGHTJUSTIFY by or''ing the original value with MFT_RIGHTJUSTIFY.

  4. Set the new menu item information.


For example, to create a right-justified menu item, add the following code to WM_CREATE:

HMENU hMenu;
MENUITEMINFO mii;
char szBuffer [80];

hMenu = GetMenu (hwnd);

// Get the original value of mii.fType first
// and OR that with MFT_RIGHTJUSTIFY
mii.cbSize = sizeof (MENUITEMINFO);
mii.fMask = MIIM_TYPE;
mii.dwTypeData= szBuffer;
mii.cch = sizeof (szBuffer);

GetMenuItemInfo(hMenu, 1, TRUE, &mii);

// OR in MFT_RIGHTJUSTIFY type
mii.fMask = MIIM_TYPE;
mii.fType = mii.fType | MFT_RIGHTJUSTIFY;

// Right justify the specified item and all those following it
SetMenuItemInfo(hMenu, 1, TRUE, &mii);

return 0;



MSDN rocks.



I wanna work for Microsoft!

Share this post


Link to post
Share on other sites
To do it in the .rc file instead of at runtime try using the "HELP" qualifer on your POPUP line:


POPUP "&Help", HELP


I don''t think Microsoft UI guidelines want you to the right-justified help menu thing anymore though. I always thought it was annoying anyway.

-Mike

Share this post


Link to post
Share on other sites
quote:
Original post by Anon Mike
I don''t think Microsoft UI guidelines want you to the right-justified help menu thing anymore though. I always thought it was annoying anyway.

Well, when that start paying me instead of charging me for their products, I will care about their guidelines.
But thank you for the info!

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites