RE: [Dev-C++] CreateMenu + InsertMenuItem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Marc H. <ma...@e-...> - 2003-09-01 17:47:18
|
Doing just a quick scan of the code, I can tell you that you should be
using:
NMI.fMask=3DMIIM_STATE|MIIM_ID|MIIM_TYPE|MIIM_STRING;
Don't use || and add the MIIM_STRING.
Hope this helps.
__________________________________
Marc Heiligers
=A0
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of leb123
Sent: 29 August 2003 18:51
To: dev...@li...
Subject: [Dev-C++] CreateMenu + InsertMenuItem
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).
What=92s wrong with this code=A0?=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]=A0;
<read szBuffer from file> // the buffer content is OK
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;
}
}
SetMenu(hwnd, hMyMenu); // no menu displayed=A0!!
return TRUE;
|