|
Dear Warren Gardner,
Thanks for giving a small and consise code. With this minimal code, I could successful get my menus to display 24 Bit Full Color icons on the menus (I had previously got them working on the toolbars)
Thanks also to;
Brent Corkum
Nikolay Denisov
Best regards and all the best for the future,
Yogesh Dhakad
|
|
|
|
|
this class is very easy to use,but how to change checkmark style?
Any help will definitely be apprecicated.
|
|
|
|
|
The second toolbar always remain visible either click "Add Toolbar" or "Remove Toolbar"; I added some codes to complete the show or hide the toolbar, it also can prevent the srange appears after calling CToolBar::ShowWindow(SW_HIDE).
void CMainFrame::OnViewAddtoolbar()
{
AddToolBar(&m_wndToolBar2);
// These 2 lines added to show toolbar
ShowControlBar(&m_wndToolBar2, TRUE, FALSE);
RecalcLayout();
}
void CMainFrame::OnViewRemovetoolbar()
{
RemoveToolBar(&m_wndToolBar2);
// These 2 lines added to hide toolbar
ShowControlBar(&m_wndToolBar2, FALSE, FALSE);
RecalcLayout();
}
Regards,
Hanney
|
|
|
|
|
If you run an application with BitmapMenu on Windows NT/95 the application will crash when the menu is drawn (it will at least do this on NT). The simple solution to this is to disable bitmaps when running on this system (so a classic menu without bitmaps will be used). The following code will do this. It should be placed in BitmapMenu:OnInitMenuPopup after the base class is called:
static int allowBitmapMenu = -1;
if(allowBitmapMenu == -1)
{
allowBitmapMenu = 1;
OSVERSIONINFO version;
version.dwOSVersionInfoSize = sizeof(version);
GetVersionEx(&version);
if( version.dwMajorVersion <= 4 && version.dwMinorVersion <= 0 )
{
if(version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
TRACE(_T("Running Windows 95. No bitmaps in menus.\n"));
allowBitmapMenu = 0;
}
else if(version.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
TRACE(_T("Running Windows NT. No bitmaps in menus.\n"));
allowBitmapMenu = 0;
}
}
}
if(allowBitmapMenu == 0)
return;
I have tested this code in 95 and NT (no bitmaps), 98 and XP and works as expected.
|
|
|
|
|
How to use this Menu as a Context Menu in a SDI/MDI application's View.
Jayant Mukherjee
|
|
|
|
|
Bitmaps are displayed for menu items which have corresponding toolbar items.
I want to display bitmaps for some menu items which do not have a correspoding tool bar item. Hence I created a hidden toolbar to show the menu bitmaps for such menu items. It works in the release mode but crashes is debug mode before the menu items are displayed, Debug Assertion failure happens due to line 160 in bitmapmenu.cpp. When I comment this ASSERT statement, the menu items are shown (broken display) only if I move the my mouse cursor over them.
Any help to solve this problem will be appreciated.
|
|
|
|
|
I wasn't able to reproduce this problem. I took the example code included in this article and removed the WS_VISIBLE style from the second toolbar (line 65 in MainFrm.cpp). It worked fine in debug mode.
|
|
|
|
|
Hi, in my project, i have simle menu inserted from Microsoft Visual C++ 6 (Insert->Resource->Menu) and i would add to some positions somie icons or bitmaps (now only some small picture next to the one position in my popup menu) I am the begginer and it's too coplicated for me so if somebody could help me please??? You could add only one icon (it's important to do this in the simplest way for me) and i would learn it from the basis. I began my project, it's very simple, and even my teacher doesn't know how to put icon in menu. Our base is "Programming in Windows" - Petzold. My project need to be finished and with such icons i'll get a higher mark. I WOULD LIKE TO SEND IT TO SOMEODY, WHO COULD ADD ONLY A PIECE OF SOURCE TO MY MENU. fenders@interia.pl PLEASEEEEEE
|
|
|
|
|
Great example! This is exactly the stuff that I was looking for, but unfortunately I don't use MFC. I don't suppose you know how to get this work using the pure win32 SDK/API? Thanks.
|
|
|
|
|
Not sure if that can be done, or if it would be worth attempting. This code currently relies entirely on MFC, and if not using MFC you would probably be better off doing it from scratch.
|
|
|
|
|
of course it can be done. There's nothing magical about MFC...it is basically a wrapper around Win32 calls. Just look up the info in Visual Studio help for the MENUITEMINFO structure and InsertMenuItem function. It's pretty easy from there.
things could always be worse...
|
|
|
|
|
No, menu API functions can only be used for black&white bitmaps, it would look strange if color bitmap is used. Read documentation for MENUITEMINFO related functions...
|
|
|
|
|
Hi, Warren.
I would like to know how can I change the style of the checkmarks, which appear together de menu item. For example, how can I put them inside a rectangle.
Thank you.
|
|
|
|
|
I think that you can do this. Take a look at the online documentation (www.msdn.microsoft.com) for MENUITEMINFO. In particular take a look at the hbmpChecked member of the structure.
|
|
|
|
|
I like this BmpMenu, but after including
#include "BitmapMenu.h" I get many errors:
c:\..\vc98\include\new(35) : error C2061: syntax error : identifier 'THIS_FILE'
c:\..\vc98\include\new(35) : error C2091: function returns function
c:\..vc98\include\new(35) : error C2809: 'operator new' has no formal parameters
c:\..\vc98\include\new(37) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,const struct std::nothrow_t &)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl op
erator new(void))(unsigned int)'
c:\..\vc98\include\new(35) : see declaration of 'new'
..
..
c:\..\vc98\include\memory(20) : error C2954: template definitions cannot nest
I'm using VC++ 6.0
Maybe someone knows that to do?
|
|
|
|
|
I don't know what the problem is on initial look. Like I said to others, try to compile with the demo project first, then you have a working version and you can migrate to your code.
It seems to be a template problem. Actually there is no reason the BitmapMenu class needs to be templated. Another way to implement this would be to use the CMenu::Attach function in OnInitMenuPopup. This would remove the templates and make the code slightly more modular. Probably a better method.
|
|
|
|
|
HI, first thanx to you, I have a poject to present to my teacher about the Bitmap menu, i did all steps that you said but i get 6 errors which says :
'messageMap' : cannot access protected member declared in class 'CMDIFrameWnd'
Can you please tell me what should i do?
Sohi
|
|
|
|
|
Hi Sohi,
Well, I am sorry I can't help debug your program. But I know that the code does compile and run on Windows 98/2000/XP and should also work on Windows Me (but haven't talked to anybody that has done it yet). So if you are using one of those OS, it should work.
I would download, compile, and run the demo. Once you have verified that you can run the demo, migrate from the demo to your project.
Warren
|
|
|
|
|
Hi, sohi.
I had the same problem, using MDI. I solve that replacing T_FrameWnd by CMDIFrameWnd in BitmapMenu.h. Try it.
Caranthol.
|
|
|
|
|
Very nice code! I have converted it to a plain win32 API version. A problem:
When the toolbar can be customized, some icons on toolbar may be hided. The code cannot assign bitmaps to menu items whose correspondance ID is hidden on current toolbar...
|
|
|
|
|
Interesting. Did you solve this problem? My applications do not allow customization, and I never tested this.
I think one easy way to solve this problem would be to create a tool bar that does not have any hidden icons and pass it to AddToolBar(). This tool bar could be hidden, so the user would never see it. This is a bit of a hack, but could be done very easily. Would this work?
|
|
|
|
|
This is wuwuli.
I finally sole the problem by a non-MFC way, in the codes, CreateToolbarEx() is used instead of LoadToolbar().
Image list is created directly from bitmap (IDB_TOOLAR) associate with toobar, then customizing of the toolar will not bother again.
//tbButton - button list of toolbar.
//IDB_TOOLAR - bitmap id in resource.
//#define IMAGEWIDTH 18
int imageID = -1;
HIMAGELIST imageList;
for (int i=0; i<sizeof(tbButton)/sizeof(TBBUTTON); i++)
{
if ((UINT)tbButton[i].idCommand == lpDrawItemStruct->itemID)
imageID = tbButton[i].iBitmap;
}
if (imageID == -1) return 0;
imageList = ImageList_LoadImage(g_hinstance, MAKEINTRESOURCE(IDB_TOOLBAR), IMAGEWIDTH, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
Well, another problem still remain: The icons of system menu are all disappeared. (under win98, win2k works well)
Thanks agian for your nice code, which is best way to draw a bitmap menu if one doesn't want to customize menu too much.
|
|
|
|
|
I think that it is a good idea to not owner-draw the system menu. If you look at most applications that owner-draw their menus, they do not owner-draw the system menu. That gives the system menu a consistent look across applications.
If you are having problems with the drawing of the system menu, you can get the default behavior by adding a single line of code to this project:
At the top of the OnInitMenuPopup function (after calling the base class) add this line:
// Do not owner-draw the system menu.
if (bSysMenu) return;
|
|
|
|
|
Is there any wauy to show menu items with different colors and /or fonts?
I need to change menu items color to another color (like WTL)menus, actually I don't know where (in your nice code)to write my OnDrawItem function.
will u help me?
|
|
|
|
|
Unfortunately further customization of the menus using this method would be difficult. The Microsoft menus are not easy to customize, and when you want to do more than what was done in this article, you are better off going with a complete owner-drawn solution.
Owner-drawing the menus is not too difficult, but you are going to be writting a minimum of twice as much code as was shown in this article.
|
|
|
|