|
|
Comments and Discussions
|
|
 |

|
Hi,
if I compile the example with old compiler 6 everything is fine.
If I compile it with dev studio 2010, the program runs on Windows 7 also fine, but the same .exe, running on a Windows XP system doesn't work. The menus are too wide or too narrow.
Does anybody know a solution?
[img]http://666kb.com/i/bvzhc6qs3qeuim0j5.gif[/img]
|
|
|
|

|
Hi Dieter,
I've got the very same problem. In Debug mode I also get an Assertion from BCMenu, in function InsertSpaces(), when trying to get the NONECLIENTMETRICS.
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, nm.cbSize, &nm, 0));
SystemParametersInfo() returns false. But I have changed the code to retieve the error by GetLastError(), which returns 0!!
I can only guess of some memory/pointer management problem in the code which is damaging something severe...
Did you find a solution, yet???
Thanks for any hint!
- Harald
|
|
|
|

|
Same problem here, looks fine in Vista and 7 after building with 2010 but all the menu contract down to a very narrow width is the same 2010 built exe is launched on XP. Any ideas at all yet ?
|
|
|
|

|
Hi,
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...
Kind Regards, H@r@ld
|
|
|
|

|
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
#ifndef _WIN64 #define WINVER 0x0502 #define _WIN32_WINNT 0x0502 // Keep XP-Kompatibility! #endif #include <SDKDDKVer.h> // Target OS infos
Regards, H@r@ld
|
|
|
|

|
at void BCMenu::InsertSpaces(void)
insert lines:
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&osvi);
bool bIsWindowsVer6Later = (osvi.dwMajorVersion > 5);
ZeroMemory ((PVOID) &m_lf,sizeof (LOGFONT));
NONCLIENTMETRICS nm;
#if(WINVER >= 0x0600) //*** Note ***
if (bIsWindowsVer6Later)
{
nm.cbSize = sizeof (NONCLIENTMETRICS) - sizeof(nm.iPaddedBorderWidth);
}
else
#endif /* WINVER >= 0x0600 */
{
nm.cbSize = sizeof (NONCLIENTMETRICS);//original line
}
|
|
|
|

|
if you include lines in stdafx.h
#ifndef _WIN64
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501 // Keep XP-Kompatibility!
#define _WIN32_WINDOWS 0x0501
#endif
#include // Target OS infos
then be careful check the WINVER value, since SDKDDKVer.h can change you WINVER to SDK version value. I.E. WINVER maybe bigger than 0x0501
these lines came from Owner Drawn Menu with Icons, Titles and Shading[^]
#if (WINVER < 0x0600)
nm.cbSize = sizeof(NONCLIENTMETRICS);
#else
/*
http://msdn.microsoft.com/en-us/library/ms724506(VS.85).aspx
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.
*/
OSVERSIONINFO OSVersionInfo;
OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
GetVersionEx(&OSVersionInfo);
if (OSVersionInfo.dwMajorVersion < 6)
nm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(int); // nm.iPaddedBorderWidth int
else
nm.cbSize = sizeof(NONCLIENTMETRICS);
#endif
modified 17-Jul-12 20:23pm.
|
|
|
|

|
BCMenu cMenu;
BCMenu cPopUp;
int i=1000;
cMenu.CreatePopupMenu();
cMenu.AppendMenu(MF_STRING, i++, "Test 1");
cMenu.AppendMenu(MF_STRING|MF_CHECKED, i++, "Test 2");
cPopUp.CreatePopupMenu();
cMenu.AppendMenu(MF_POPUP,(UINT)cPopUp.GetSafeHmenu(),"PopUp");
cPopUp.AppendMenu(MF_STRING,i++,"Test 4");
cPopUp.AppendMenu(MF_STRING,i++,"Test 5");
//cPopUp.Detach(); if not comment crash in other function
CRect rect;
GetDlgItem(IDC_BUTTON1)->GetClientRect(&rect);
ClientToScreen(&rect);
cMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON ,
rect.left,rect.bottom,this);
cMenu.DestroyMenu();
/*
if "cPopUp.Detach();" is comment crash in "BOOL BCMenu::DestroyMenu()"
if "cPopUp.Detach();" is not comment crash in "void BCMenu::SynchronizeMenu(void)"
*/
|
|
|
|

|
Hi there,
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
Regards..
Addendum: the menu is implemented as a context menu in an ActiveX control (CListCtrl subclassed), embedded in a dialog based window.
modified on Monday, December 13, 2010 5:29 AM
|
|
|
|

|
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!
|
|
|
|

|
Can't work in VS 2008, crashed when m_menu.LoadMenu(IDR_MYTYPE);
|
|
|
|

|
Hi
this is a very nice class. My icons appear very nicely. However, I want to use icon only, and remove the text, so I use:
menuView.SetMenuText(MY_MENU_COMMAND,"",MF_BYCOMMAND);
There are no more text, but there is a little gap on the right of the icon. How can I get ride of it?
Thanks!
Mat
|
|
|
|

|
I find the menu crops if I am using Russian text (in English windows).
Andrew
|
|
|
|

|
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.
is that a bug or ??
Regards,
KH
good
|
|
|
|

|
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*/ )
{
BOOL returnflag=FALSE;
if(MF_BYPOSITION&nFlags)
{
UINT numMenuItems = m_MenuList.GetUpperBound();
if(id<=numMenuItems){
#ifdef UNICODE
m_MenuList[id]->SetWideString((LPCTSTR)string);
#else
m_MenuList[id]->SetAnsiString(string);
#endif
returnflag=TRUE;
}
<code>//BK: this forces windows to get the menu dimensions again after changing the menu text
int id2 = GetMenuItemID(id); //id in this case is the position
if (id2 != 0 && id2 != -1)
ModifyMenu(id, MF_BYPOSITION, id2, ""); //no text needed as it //BK: end of changes</code>
}
else{
int uiLoc;
BCMenu* pMenu = FindMenuOption(id,uiLoc);
if(NULL!=pMenu) returnflag = pMenu->
|
|
|
|

|
Your code makes my icon to disapear...
Mat
|
|
|
|

|
Hello
I decided I wanted to try try and use the native CMenu objects again for my MDI IDR_MAINFRAME in my project.
So I remmed out the two lines of code in my InitInstance class which indicated would revert it back to normal.
However, when I do this, I find the last but one menu refuses to display. I get no crashes. If I add further menus, then it will display. Only the last but one refuses to show.
If I put the two lines back into InitInstance, the menu fully operations.
I have trie dremoving BCMenu completely from my project and I still get this behavior.
Ideas?
|
|
|
|

|
Hhhmm. If I also rem this out:
//pMainFrame->OnUpdateFrameMenu(pMainFrame->m_hMenuDefault);
I get a complete old style menu again - fully operational.
|
|
|
|

|
Hi,Brent Corkum
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 zhangleibaobaoz@163.com
|
|
|
|

|
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)")
Windows Vista:
#define WINVER 0x0600
Windows Server 2003 SP1, Windows XP SP2
#define WINVER 0x0502
Windows Server 2003, Windows XP
#define WINVER 0x0501
Windows 2000
#define WINVER 0x0500
|
|
|
|
|

|
Yes it does compile with VC++ 2005. I think you may have problems with VC++ 2008 though.
|
|
|
|

|
Thank you for your reply. I do find that I get depracation warnings related to the use of various buffer functions. If I don't want to switch the depracation warnings off it means I have to resolve these issues.
Is it not possible for a "out of the box" VS2005 build to be made available?
Thanks.
|
|
|
|

|
I am working with Greek Unicode characters on Vista. I discovered that on Vista, when the "Current language for the non-unicode programs" is set to English, the Unicode menus with Greek characters appear truncated i.e. the words have been cut at the end, with whole words missing some times.
BCMenu predates the release of MS Vista, and digging into the code I discovered that it has a function with the name
Win32Type IsShellType()
which determines the OS type that is used. As it predates Vista, when is run on Vista it defaults to WINNT3! And this causes all the problems. I have changed the function so when run under MS Vista (or any future versions MS Windows) it returns WINXP as the OS type. This has solved the problem of the truncated menu width.
Now all the tests when run on a 32bit Vista installation. The change most probably will work also for Vist 64-bit.
I include the changed code of the function for your reference:
Win32Type IsShellType()
{
Win32Type ShellType;
DWORD winVer;
OSVERSIONINFO *osvi;
winVer=GetVersion();
if(winVer<0x80000000){/*NT */
osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));
if (osvi!=NULL){
memset(osvi,0,sizeof(OSVERSIONINFO));
osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(osvi);
if(osvi->dwMajorVersion==3L)ShellType=WinNT3;
else if(osvi->dwMajorVersion==4L)ShellType=WinNT4;
else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==0L)ShellType=Win2000;
else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==1L)ShellType=WinXP;
else if(osvi->dwMajorVersion==6L&&osvi->dwMinorVersion==0L)ShellType=WinXP; //- Windows Vista
else ShellType=WinXP; //- For future versions of Windows default to WinXP
free(osvi);
}
}
else if (LOBYTE(LOWORD(winVer))<4)
ShellType=Win32s;
else{
ShellType=Win95;
osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));
if (osvi!=NULL){
memset(osvi,0,sizeof(OSVERSIONINFO));
osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(osvi);
if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==10L)ShellType=Win98;
else if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==90L)ShellType=WinME;
free(osvi);
}
}
return ShellType;
}
|
|
|
|

|
In Demo "BCDialogMenu303".Although the LoadToolbar() function is called , but there wasn't any toolbar show on the dialog. why?
...
m_menu.LoadMenu(IDR_MYTYPE);
m_menu.LoadToolbar(IDR_MAINFRAME);
m_menu.LoadToolbar(IDR_TOOLBAR);
SetMenu(&m_menu);
...
|
|
|
|

|
how to store the data in the database using an mfc AppWizard
vivek rai
|
|
|
|

|
Hello,
Do you know of an web article describing how somebody can imitate the painting of the highlighted menu items background?
1. highlighted menu items in normal applications running on Microsoft Vista (e.g NotePad ) have a nice blue background
2. highlighted menu items in Office 2007 (on Windows XP and Windows Vista, doesn't matter, the menu looks the same) have a nice "reflecting light" orange gradient.
By reading various articles, I've seen two approaches:
- Use themes API functions like DrawThemeBackground(). Is this possible for menus ?
Or
- Use gradient API functions like GradientFill() with GRADIENT_FILL_RECT_V?
In this case, by applying this function twice with different limiting colors for the first half and the second half of the button would produce something aproximating the "reflecting light" gradient we are seeing in Office 2007)
I would like to know how the Microsoft programmers implemented these menus.
Thanks a lot.
-- modified at 19:58 Sunday 1st April, 2007
|
|
|
|

|
Hi
Any idea of how theme support can be added to the menus.
menus looks better on vista & worth utilising them.
Regards
|
|
|
|

|
Any update on this request?
Andy
|
|
|
|

|
I'm not able to append/insert top level menu item using the POPUP flag. This behaviour works fine with CMenu, and when i use ....
BOOL InsertMenu( UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );
with nIDNewItem as 0, BCMenu assumes it as a separator, instead of a top level item.
Please help me with this.
Thanks.
|
|
|
|

|
Hi
Let me say thanks first for this wonderful help .
I am using this code to my SDI application. I am using 3.03 version of bcmenu.
I am facing the problem appling the true color bitmap strip at menubar. My strip background color is RGB(192,192,192) and Even i ve set the function SetBitmapbackground(RGB(192,192,192)). But still it is not showing the transparent background colors of menubar
Thx
ND
|
|
|
|

|
have created an owner drawn menu item and done required drawing in the
DrawItem function. The drawing code works as I expected bu the problems is a
box appearing outside the menu. how can I remove it? please see the following
pictured to see the output.
http://static.flickr.com/98/248788817_5aca6ca4f1_o.jpg[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|

|
Hi,
I set xp_draw_3D_bitmaps=FALSE and xp_drawmode=BCMENU_DRAWMODE_ORIGINAL in BCMenu.cpp . then the backcolor of menu is gray.
ButI set xp_draw_3D_bitmaps=FALSE and xp_drawmode=BCMENU_DRAWMODE_ORIGINAL in BCMenu.cpp of your MDI example ,the backcolor of menu is white.
why the backcolor of menu is different while same set?
how to set backcolor of menu to white. could you help me?
my application is under vc++6.0 + windows xp
Any help will definitely be apprecicated.
|
|
|
|

|
I've resolve this question.
you may change backcolor of menu in BCMenu::DrawItem_Win9xNT2000() or BCMenu::DrawItem_WinXP() function.change the value of m_clrBack variable to change the backcolor of menu.
I'm thankful to the author for supporting us a such good class.
|
|
|
|

|
Hi.
I have some problem in VC++ 2005.
When i use this command, the return value is true:
UNIT rt = menu->GetMenuItemCount();
But when i use these functions(here is some examples):
GetMenuText(pos, tmp, MF_BYPOSITION); //error: Unhandled exception at 0x004788f3 in App.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd. At "string=m_MenuList[id]->GetString();" in your code
GetMenuItemID(pos); // value of this function always is "-1"
GetMenuString(pos, tmp, MF_BYPOSITION);//this function always L""
Why? I am wrong in use params or the library can not work in VC++ 2005?
Please help me.
|
|
|
|

|
Hi,
i think there are 2 possible problems:
- you wrote:
UNIT rt = menu->GetMenuItemCount();
GetMenuText(pos, tmp, MF_BYPOSITION);
GetMenuItemID(pos);
GetMenuString(pos, tmp, MF_BYPOSITION);
but the correct code probably is
UNIT rt = menu->GetMenuItemCount();
menu->GetMenuText(pos, tmp, MF_BYPOSITION);
menu->GetMenuItemID(pos);
menu->GetMenuString(pos, tmp, MF_BYPOSITION);
- probably the 'pos' variable is more bigger than total menu count.
Sorry for my english, but i'm italian.
bye
GianGian (Marco)
-- modified at 4:13 Thursday 29th June, 2006
|
|
|
|

|
I tried using truecolor bitmap. but it is not show image on menu.
Please anwser to me....
Go for it!!
|
|
|
|

|
Hi dalgoo,
for use a truecolor bitmap in the menu is needed to replace all 'ILC_COLORDDB' with 'ILC_COLOR32' in the image list creation.
Sorry if my english is not perfect, but i'm Italian.
bye, ciao
|
|
|
|

|
The trick to true color images is how you create the image list you load. At first it seemed obvious that you would do the following:
m_TrayImages.Create (IDB_TRAY_IMAGES, 16, ILC_COLOR24|ILC_MASK, RGB(255,0,255));
However, this method loads the bitmap using the half-tone palette which reeks havoc on the colors! The solution is to create the imagelist first then add the bitmap:
m_TrayImages.Create (16, 16, ILC_COLOR24|ILC_MASK, 0,0);
CBitmap bmp;
bmp.LoadBitmap(IDB_TRAY_IMAGES);
COLORREF rgbTransparentColor = RGB(255,0,255);
m_TrayImages.Add(&bmp, rgbTransparentColor);
That is it!
|
|
|
|

|
Is there a way to modify the code so that the tops of the menus such as the File, Edit, and Tools menus (for example) to display like the XP sytle?
|
|
|
|

|
Is it possible to set my own disabled image for menu item, like SetDisabledImageList in CToolBarCtrl
|
|
|
|

|
Just checked version 3.03
Looks like its already has what i need (color disable images)
|
|
|
|

|
I currently use the BCMenu system and it shows my 16 x 16 toolbar images against the relevant menu items.
A user has provided me with some 32 x 32 images (256 colours) that he would like me to consider using for my toolbar. I am happy to try but have concerns about what will happen to my menu items.
Has anyone done this kind of thing before?
Please clarify.
Andrew
|
|
|
|

|
I could not make a menu item MF_GRAYED
In dialog mode ,
I use BCMENU as main and single menu ,
It run OK,
but ,
I could not make a menu item grayed while CMenu will do.
I add code as below in InitDialog function
m_menu.LoadMenu(IDR_MYMENU);
m_menu.EnableMenuItem(ID_VLINK_CLOSE,MF_GRAYED);
......
it won't work, why?
or I should change it in other function?
Hello,
pleasure to meet you.
|
|
|
|

|
And I test these code in your example,
edit menu ID as your menu ID,
and tried a submenu mode ,
it still can not work! just as nothing happened?
Hello,
pleasure to meet you.
|
|
|
|

|
I've discover that if I remove the 'ON_COMMAND( ..., ... )' for an menu item, this one will appear disabled, and then do not send any message when clicked etc..
Is there a way to not getting in charge of adding such command in message map ? I explain myself, I buid dynamicly my menu and so i can't add the ON_COMMAND. I resolve this by using ON_COMMAND_EX_RANGE but I dislike that...
I'm pretty new to MFC...
Sorry if this question appear dumb... but ...
Tx,
|
|
|
|

|
I created BCMenu instance with several popup items in main menu and noticed that items with submenu has not the same size as other menu items.
See example screenshoot
How to fix this problem?
Sincerely Yours,
RadioShark
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
This class implements an owner drawn menu class that mimics the menu style used in XP, Office and Visual C++
| Type | Article |
| Licence | CPOL |
| First Posted | 18 Nov 1999 |
| Views | 760,682 |
| Downloads | 13,695 |
| Bookmarked | 263 times |
|
|