...

View Full Version : [Win32/C++] I got stuck while creating menubar wihout resources



hkBattousai
08-14-2007, 03:20 PM
Below is the code I'm working on. I know it is a total mess, there are too many unnecessary repetitions and casting, but they are all temporary.


HMENU hMenu = CreateMenu();
HMENU hsmFile, hsmEdit, hsmView;
hsmFile = CreatePopupMenu();
hsmEdit = CreatePopupMenu();
hsmView = CreatePopupMenu();
MENUITEMINFO mii;
MENUITEMINFO fmii;
MENUITEMINFO emii;
MENUITEMINFO vmii;

/*** FILE *****************************************************************/
memset(&fmii, 0, sizeof(MENUITEMINFO));
fmii.cbSize = sizeof(MENUITEMINFO);
fmii.fMask = MIIM_STRING | MIIM_FTYPE;
fmii.fType = MIIM_STRING;
fmii.dwTypeData = TEXT("New");
fmii.cch = 3;
InsertMenuItem(hsmFile, 0, TRUE, (LPCMENUITEMINFO) &fmii);

memset(&fmii, 0, sizeof(MENUITEMINFO));
fmii.cbSize = sizeof(MENUITEMINFO);
fmii.fMask = MIIM_STRING | MIIM_FTYPE;
fmii.fType = MIIM_STRING;
fmii.dwTypeData = TEXT("Open");
fmii.cch = 4;
InsertMenuItem(hsmFile, 1, TRUE, (LPCMENUITEMINFO) &fmii);

memset(&fmii, 0, sizeof(MENUITEMINFO));
fmii.cbSize = sizeof(MENUITEMINFO);
fmii.fMask = MIIM_STRING | MIIM_FTYPE;
fmii.fType = MIIM_STRING;
fmii.dwTypeData = TEXT("Save");
fmii.cch = 4;
InsertMenuItem(hsmFile, 2, TRUE, (LPCMENUITEMINFO) &fmii);

/*** EDIT *****************************************************************/
memset(&emii, 0, sizeof(MENUITEMINFO));
emii.cbSize = sizeof(MENUITEMINFO);
emii.fMask = MIIM_STRING | MIIM_FTYPE;
emii.fType = MIIM_STRING;
emii.dwTypeData = TEXT("Copy");
emii.cch = 4;
InsertMenuItem(hsmEdit, 0, TRUE, (LPCMENUITEMINFO) &emii);

memset(&emii, 0, sizeof(MENUITEMINFO));
emii.cbSize = sizeof(MENUITEMINFO);
emii.fMask = MIIM_STRING | MIIM_FTYPE;
emii.fType = MIIM_STRING;
emii.dwTypeData = TEXT("Cut");
emii.cch = 3;
InsertMenuItem(hsmEdit, 1, TRUE, (LPCMENUITEMINFO) &emii);

memset(&emii, 0, sizeof(MENUITEMINFO));
emii.cbSize = sizeof(MENUITEMINFO);
emii.fMask = MIIM_STRING | MIIM_FTYPE;
emii.fType = MIIM_STRING;
emii.dwTypeData = TEXT("Paste");
emii.cch = 5;
InsertMenuItem(hsmEdit, 2, TRUE, (LPCMENUITEMINFO) &emii);

/*** VIEW *****************************************************************/
memset(&vmii, 0, sizeof(MENUITEMINFO));
vmii.cbSize = sizeof(MENUITEMINFO);
vmii.fMask = MIIM_STRING | MIIM_FTYPE;
vmii.fType = MIIM_STRING;
vmii.dwTypeData = TEXT("Toolbars");
vmii.cch = 8;
InsertMenuItem(hsmView, 0, TRUE, (LPCMENUITEMINFO) &vmii);

memset(&vmii, 0, sizeof(MENUITEMINFO));
vmii.cbSize = sizeof(MENUITEMINFO);
vmii.fMask = MIIM_STRING | MIIM_FTYPE;
vmii.fType = MIIM_STRING;
vmii.dwTypeData = TEXT("Status");
vmii.cch = 6;
InsertMenuItem(hsmView, 1, TRUE, (LPCMENUITEMINFO) &vmii);

memset(&vmii, 0, sizeof(MENUITEMINFO));
vmii.cbSize = sizeof(MENUITEMINFO);
vmii.fMask = MIIM_STRING | MIIM_FTYPE;
vmii.fType = MIIM_STRING;
vmii.dwTypeData = TEXT("Options");
vmii.cch = 7;
InsertMenuItem(hsmView, 2, TRUE, (LPCMENUITEMINFO) &vmii);

/*** MENU BAR *************************************************************/
memset(&mii, 0, sizeof(MENUITEMINFO));
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU;
mii.fType = MIIM_STRING;
mii.hSubMenu = hsmFile;
mii.dwTypeData = TEXT("File");
mii.cch = 4;
InsertMenuItem(hMenu, 0, TRUE, (LPCMENUITEMINFO) &mii);

memset(&mii, 0, sizeof(MENUITEMINFO));
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU;
mii.fType = MIIM_STRING;
mii.hSubMenu = hsmEdit;
mii.dwTypeData = TEXT("Edit");
mii.cch = 4;
InsertMenuItem(hMenu, 1, TRUE, (LPCMENUITEMINFO) &mii);

memset(&mii, 0, sizeof(MENUITEMINFO));
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU;
mii.fType = MIIM_STRING;
mii.hSubMenu = hsmView;
mii.dwTypeData = TEXT("View");
mii.cch = 4;
InsertMenuItem(hMenu, 2, TRUE, (LPCMENUITEMINFO) &mii);


SetMenu(Main.hWnd, hMenu);
DrawMenuBar(Main.hWnd);

It appears like this when compiled and run :
http://img174.imageshack.us/img174/2222/sillmenubu8.jpg

The gap between the window title and the position where first menu item starts make me think that there's no menu bar associated to the main window. Even if i omit the the function DrawMenuBar(Main.hWnd);, it changes nothing?

What do I have to do to correct this error? Do you have any idea, experiences or a sample code?
Any help will be appreciated.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum