the reason is: Win7 knows how to handle dufferent versions of struct "nm" in the call SystemParametersInfo(SPI_GETNONCLIENTMETRICS, nm.cbSize, &nm, 0). But XP is not able to handle the new size used in the Windows 7 SDK . I have decided to compile my app for Windows XP (setting WINVER, _WIN32_WINNT, etc). The result works fine for Win 7 and XP. If you need special enhancements for Win 7 and must compile with Win 7 SDK and WINVER, _WIN32_WINNT set to Window 7 you should change the code in bcmenu to use the old struct if running under XP. You would need to define the old structure from the XP SDK in your code and use it in SystemParametersInfo() if you detect XP as running OS (you have to check this with GetVersionEx()). Else use the standard structure for Win 7. That should work...
Thanks for this, tried it but no joy - I did notice however that all my menus have the correct width on both Win7 and XP as long as there are no sub-menus in there. Could this be something to do with the problem ?
Hi, this is my change that worked. Please try this. And make sure your solution builds against the Win 7 SDK. It worked for me. If this doesn't resolve your problem, I have no glue what else could be the solution...
Use this in your precompiled header (stdafx.h) or in targetver.h
#if (WINVER < 0x0600)
nm.cbSize = sizeof(NONCLIENTMETRICS);
If the iPaddedBorderWidth member of the NONCLIENTMETRICS structure is present, this structure is 4 bytes larger than for an application that is compiled with _WIN32_WINNT less than or equal to 0x0502. For more information about conditional compilation, see Using the Windows Headers.
Windows Server 2003 and Windows XP/2000: If an application that is compiled for Windows Server 2008 or Windows Vista must also run on Windows Server 2003 or Windows XP/2000, use the GetVersionEx function to check the operating system version at run time and, if the application is running on Windows Server 2003 or Windows XP/2000, subtract the size of the iPaddedBorderWidth member from the cbSize member of the NONCLIENTMETRICS structure before calling the SystemParametersInfo function.
first of all thanks for your contribution.
But I have a problem I can't handle.
In Debug-mode the menu works fine, but delivers X messages in the output box like
"Warning: unknown WM_MEASUREITEM for menu item 0xYYYY", with X being the number of menu items.
If I compile in Release-mode, the menu is just a vertical stripe of about 15px width, so the width could not be estimated correctly.
What I did:
I overrode OnMeasureItem in my class and did an explicit MeasureItem, which doesn't fail (while debugging, I see values, that should be correct), but the menu is still just a vertical stripe.
So I debugged a little more and got to the OnMeasureItem of CWnd, where the warning is generated (wincore.cpp#1297).
Noteworthy is that the method is called twice for each item-id. First, the item is not recognized as menu in #1316 (_AfxFindPopupMenuFromID delivers NULL). Then, the second time, it is recognized, and gets through the MeasureItem call (#1318).
I don't know what to do now...
Any help would be appreciated
Addendum: the menu is implemented as a context menu in an ActiveX control (CListCtrl subclassed), embedded in a dialog based window.
Problem is more or less solved..
I still get the warnings that confuse me, but the visualisation error is gone.
What went wrong: mixing release-mode compilation of my application with a debug-mode compilation of the OCX-control doesn't do any good
After registering the release-mode comp. everything works fine..
Hmm... Well, the problem is still existant, but vice versa:
I compiled the ocx in release mode and gave it for implementation to a colleague. He - of course - compiles his program in debug mode. But if he tries to open the context menu, he gets a debug assertion..
Any hint would be appreciated!
Hi, when i tried this owner draw menu, why did the DrawItem function are not being triggered??
Because when i tried other owner draw menu, even if i did not click the menu item[on the menu bar] it will trigger the DrawItem.
I'm trying to change the font's color of the menu item text[on the menu bar]
I already succeeded to change the font color of the submenu items.. which it will trigger DrawItem function when i click it.
I used the BCMenu in my application, and it worked great. That was until I changed the menu text. My application can change languages on the fly.
I start my application in one language and set all the menu text. OnMeasureItem gets called to get the size of each menu as I use it. It will never be called again. I then change languages and change all the menu text. The problem is the menu sizes don't fit the new text.
I figured a way to fool windows into thinking that the menu text changed. It requires three extra lines in BCMenu.cpp:SetMenuText function. I'm using BCMenu 3.036
Hopefully this will help if anyone else is having trouble with this problem.
BOOL BCMenu::SetMenuText(UINT id, CString string, UINT nFlags/*= MF_BYPOSITION*/ )
UINT numMenuItems = m_MenuList.GetUpperBound();
<code>//BK: this forces windows toget the menu dimensions again after changing the menu text
int id2 = GetMenuItemID(id); //id in this caseis the position
if (id2 != 0 && id2 != -1)
ModifyMenu(id, MF_BYPOSITION, id2, ""); //no text needed as it's owner-drawn
//BK: endof changes</code>
BCMenu* pMenu = FindMenuOption(id,uiLoc);
if(NULL!=pMenu) returnflag = pMenu->
Thank you for your work.I can not add a icon int the menuitem,can you help me?of course i could convert a bitmap to icon,but you know ,it is not easy ,I was a beginner of vc 6.0,your answer is important to me,could you give me a complete reference of BCMenu if you have . I think I could learn more easy than before .Thank You!!Email firstname.lastname@example.org
I compiled the demo program in vs2008 and there is no error.
However, when I execute the program, there is one problem occurred.
The program cannot be executed on the following line in void BCMenu::InsertSpaces().
VERIFY (SystemParametersInfo (SPI_GETNONCLIENTMETRICS,nm.cbSize,&nm,0));
I answer by myself.
The problem is the same as NewMenu.
I should assign the correct WINVER.
Please see below.
Probably you did not set the right WINVER versionsnumber and the size of NONCLIENTMETRICS will be wrong for XP (Vista will be ok)
=> If the function fails, the return value is zero. To get extended error information, call GetLastError.
Check this output!
#pragma message(" WINVER not defined. Defaulting to 0x0600 (Windows Vista)")
#define WINVER 0x0600
Windows Server 2003 SP1, Windows XP SP2
#define WINVER 0x0502
Windows Server 2003, Windows XP
#define WINVER 0x0501