[Dev-C++] CreateMenu + InsertMenuItem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: leb123 <le...@wa...> - 2003-08-29 16:49:34
|
I have to create dynamically a menu from a file. From the win32
documentation and several web sites, I tried the following code, based
on InsertMenuItem. This function returns a nonzero value=3DOK, but no =
menu
is displayed. If I try a static menu with LoadMenu and SetMenu, instead
of this code, the menu is displayed correctly (but is static).
=20
What=92s wrong with this code ?=20
=20
=20
HMENU hMyMenu=3DCreateMenu();
if (!hMyMenu)
{
MessageBox(NULL, "Unable to create Menu", "Internal error", 0);
return FALSE;
}
DWORD IDCurrentItem=3D1;
int iPosition=3D0;
while (<not end of file>) //it loops several times
{
char szBuffer[BUFFER_SIZE] ;
=20
<read szBuffer from file> // the buffer content is OK
=20
MENUITEMINFO NMI;
ZeroMemory(&NMI, sizeof NMI);
NMI.cbSize=3Dsizeof NMI;
NMI.fMask=3DMIIM_STATE||MIIM_ID||MIIM_TYPE;
NMI.fType=3DMFT_STRING;
NMI.fState=3DMFS_ENABLED;
NMI.wID=3DIDCurrentItem++;
NMI.dwTypeData=3D(LPTSTR)szBuffer;
NMI.cch=3Dstrlen(szBuffer);
if (!InsertMenuItem(hMyMenu, iPosition++, TRUE, &NMI))
{
MessageBox(NULL, szBuffer, "Internal Error: unable to create
menu item=94, 0);
return FALSE;
}
}
=20
SetMenu(hwnd, hMyMenu); // no menu displayed !!
return TRUE;
|