|
|
Comments and Discussions
|
|
 |

|
Hello,
I'm using your source code in a visual C++ 6 application, it'w perfect.
Now I'm trying to migrate from visual 6 to visual 2010 but I have some problem.
I'm using a special frame and on your site I saw :
How to Use the CNewMenu in a Special Frame Window
1. Normally you should overwrite measureitem, menuchar and initmenupopup. For this purpose I use the CNewFrame template class. So you can replace CYourSpecialBase with CNewFrame<CYourSpecialBase> in your project.
so in my code I have :
class CMainFrame : public CNewFrame
...
No problem with visual C++ 6 but with 2010 I have a lot of link error :
error LNK2019: unresolved external symbol "__declspec(dllimport) protected: static struct AFX_MSGMAP const * __stdcall CNewFrame<class SECMDIFrameWnd>::GetThisMessageMap(void)" (__imp_?GetThisMessageMap@?$CNewFrame@VSECMDIFrameWnd@@@@KGPBUAFX_MSGMAP@@XZ) referenced in function "protected: static struct AFX_MSGMAP const * __stdcall CMainFrame::GetThisMessageMap(void)" (?GetThisMessageMap@CMainFrame@@KGPBUAFX_MSGMAP@@XZ)
error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall CNewFrame<class SECMDIFrameWnd>::~CNewFrame<class SECMDIFrameWnd>(void)" (__imp_??1?$CNewFrame@VSECMDIFrameWnd@@@@UAE@XZ) referenced in function "public: virtual __thiscall CMainFrame::~CMainFrame(void)" (??1CMainFrame@@UAE@XZ)
Could somebody help me?
thanks Carbone
ps I found a forum about Using it in a dll and the answer was :
Do you use my latest version 1.22? Second your class VCMDIFrameWnd should not use the template as baseclass. It should use CNewMDIFrameWnd as baseclass.
but I can't change the frame base class so I'm using the template with it.
|
|
|
|

|
Hi Carbone
You need the latest (old) version 1.25 from my homepage, and then it is possible to use it with vs2010. Do not forget to define the right platform version _WIN32_WINNT or include #include <SDKDDKVer.h> from the stdafx.h.
But I suggest using the new version of MFC (VS2010), there you have the build in support of different menu-style. CMDIFrameWndEx, CWinAppEx, CMFCVisualManager etc... so you do not need CNewMenu
Sincerely
Bruno
|
|
|
|

|
Thanks for the answer;
I'm already using the latest version from your website, but I still have this link probleme with the template
_WIN32_WINNT is on 0x0501
modified 24-Apr-12 8:11am.
|
|
|
|

|
Hello, very nice and helpful.
My question is so : How can I use in a MDI project in App::InitInstance() when I load some resource of DLL? The LoadFrame didn't work!!
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
Thanks
Samuel Gerber
|
|
|
|

|
Hi,
I would like to know if reusing this piece of codes in commercial product will have any licensing issue ?
Please help...
Thank you
|
|
|
|

|
May I know is there any version of NewMenu which compatible with VS 2008. (MFC 9.0). I have used NewMenu version 1.25. But I can't compile it in debug session. It cause to crash on CNewMenu::OnMeasureItem() line number 6363. :(
|
|
|
|
|

|
Result is same with this version also.
|
|
|
|

|
Hello
It's strange, it fix some problem for me. What line caused problem now?
|
|
|
|

|
Hi all,
Do you know how to get Left and Right mouse click event on Popup menu?
|
|
|
|

|
If we compile with #define WINVER 0x0600 and run it under XP we get several assertions and visual problem with menu font...
Does anybody have solution for this problem?
|
|
|
|

|
It is probably the problem of getting the NONCLIENTMETRICS, because on Windows Server 2003 and Windows XP/2000, iPaddedBorderWidth member is not supported. So you need to fix the size.
//nm.cbSize = sizeof (NONCLIENTMETRICS);
nm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(nm.iPaddedBorderWidth);
There are several places in code. See also in the MSDN documentation:
http://msdn.microsoft.com/en-us/library/ms724506(VS.85).aspx[^]
|
|
|
|

|
Yes, you are right. but
nm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(nm.iPaddedBorderWidth);
is wrong code! I am working at fixin now and hope I can testing it today. If you want I can send you modified code, maybe you will updated this greate code!
|
|
|
|

|
I have created a modified version of CMenu, you can download it at http://softvoile.com/development/NewMenuModifiedBySoftvoile.zip[^]
I have found one problem: if we compile with #define WINVER 0x0600 and run it under XP we get several assertions and visual problem with menu font...
So, I made some modifications in order to fix this problem, + some optimization and code refactoring. You can use diff tool to see the differences.
Hope this help and you can add this changes to main package.
Thanks for your work! I use this menu a few years and happy with it
|
|
|
|

|
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 Softvoile modified code:
#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:22pm.
|
|
|
|

|
now i want remove border shadding effect, how i can do it?
tks so murch.
modified on Monday, October 26, 2009 6:36 PM
|
|
|
|

|
One possibility is to change the class style
You can remove the class style in CMenuTheme::OnInitWnd(HWND hWnd)
LONG_PTR oldClassStyle = GetClassLongPtr(hWnd, GCL_STYLE);
if(oldClassStyle&CS_DROPSHADOW)
{
pData->m_dwData |= 16;
SetClassLongPtr (hWnd, GCL_STYLE, oldClassStyle & (~CS_DROPSHADOW ) );
}
but you have to set back the class style in BOOL CMenuTheme::OnUnInitWnd(HWND hWnd)
if(pData->m_dwData&16)
{
LONG_PTR oldClassStyle = GetClassLongPtr(hWnd, GCL_STYLE);
SetClassLongPtr (hWnd, GCL_STYLE, oldClassStyle | CS_DROPSHADOW );
}
|
|
|
|

|
It so good.
Thanks you verry murch.
|
|
|
|

|
This function worked on my pc, winxp. Color of menu is black and dn't see any text.
|
|
|
|

|
This is a nice piece of work. However, I found a little problem with the accelerator texts. When the accelerator key for a command is, say, HOME or END, you'll see NUM-7 or something similar in the menu instead. Also, the texts for Ctrl, Alt and Shift should not be hard-coded, since they vary by locale (Strg in German for Ctrl - Bruno should know that! and Mayúsculas for Shift in Spanish, etc).
Jörgen Sigvardsson's code fixes this (http://www.codeproject.com/KB/tips/getacceltext.aspx[^]).
Here are my modifications in NewMenu.cpp:
void Capitalize(CString& str)
{
LPTSTR lpszBuf = str.GetBuffer();
CharUpperBuff(lpszBuf, 1);
if(str.GetLength() > 1)
CharLowerBuff(lpszBuf + 1, str.GetLength() - 1);
str.ReleaseBuffer();
}
bool GetKeyName(UINT nVK, CString& str)
{
UINT nScanCode = MapVirtualKeyEx(nVK, 0, GetKeyboardLayout(0));
switch(nVK)
{
case VK_INSERT:
case VK_DELETE:
case VK_HOME:
case VK_END:
case VK_NEXT: case VK_PRIOR: case VK_LEFT:
case VK_RIGHT:
case VK_UP:
case VK_DOWN:
nScanCode |= 0x100; }
BOOL bResult = GetKeyNameText(nScanCode << 16, str.GetBuffer(20), 19);
str.ReleaseBuffer();
return bResult != FALSE;
}
CString CNewMenuItemData::GetString (HACCEL hAccel)
{
...
CString sKeyName;
if (pAccel [n].fVirt & FALT && GetKeyName(VK_MENU, sKeyName))
{
Capitalize(sKeyName);
sAccel += sKeyName + _T("+");
}
if (pAccel [n].fVirt & FCONTROL && GetKeyName(VK_CONTROL, sKeyName))
{
Capitalize(sKeyName);
sAccel += sKeyName + _T("+");
}
if (pAccel [n].fVirt & FSHIFT && GetKeyName(VK_SHIFT, sKeyName))
{
Capitalize(sKeyName);
sAccel += sKeyName + _T("+");
}
if (pAccel [n].fVirt & FVIRTKEY)
{
if (GetKeyName(pAccel [n].key, sKeyName))
{
Capitalize(sKeyName);
sAccel += sKeyName;
}
}
...
}
|
|
|
|

|
P.S. I had to make a couple of changes with respect to my compiled version. I hope no mistakes crept in. Let me know.
|
|
|
|

|
After insert menu item in popup menu, the program detected memory leaks. Like:
Detected memory leaks!
Dumping objects ->
C:\menutest\menutest\newmenu.cpp(7008) : {2651} client block at 0x017B3BB8, subtype c0, 36 bytes long.
a CNewMenuItemData object at $017B3BB8, 36 bytes long
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\array_p.cpp(67) : {2512} normal block at 0x017B36C0, 56 bytes long.
Data: < ,{ -{ .{ .{ > C0 2C 7B 01 D0 2D 7B 01 88 2E 7B 01 E8 2E 7B 01
{2502} normal block at 0x017B63D8, 26 bytes long.
Data: <d ~ > 64 88 7E 00 04 00 00 00 04 00 00 00 01 00 00 00
......
C:\menutest\menutest\newmenu.cpp(7558) : {2310} client block at 0x017B1D50, subtype c0, 120 bytes long.
a CNewMenu object at $017B1D50, 120 bytes long
Object dump complete.
How can I correct this bug?
VS2008, CNewMenu 1.25, Win2003.
|
|
|
|

|
I'm not sure if this has been mentioned before but does the fact that a dialog derives from CNewDialog break the add memmber wizard in VS 2005 need addressing?
To test this right click on the dialog sample and choose "add variable"
"control variable" is disabled.
Anybody experienced this or know of a way around it other than adding control variables manually?
|
|
|
|

|
Check the project property with whether the property "Use of MFC" was set to "Use MFC in a Shared DLL".
|
|
|
|

|
Just wondering how hard you think it would be to implement a chevron like Word 2003 has? Does anyone have any tips for how I would go about achieving this?
|
|
|
|

|
I am using VS2008 and I have noticed a little glitch.
When I run my app I call myMenuItem.AddMenuTitle("Text");
This is displayed fine, until I log in to my application and add more menu items, the MenuTitle dissapears.
I have called myMenuItem.AddMenuTitle("Text"); again once I have logged in but this does not resolve the issue I am seeing!
I have had no issues on VS2003 and was wondering if there is something I need to call, or not setting up correctly at present.
Kind Regards,
Apiercy
|
|
|
|

|
Well Bruno,
There's a bug in dialog based menu. On the dialog there's a button you've placed with caption "Menu" and on clicking it you display a popup menu which dsiplays further menus. The Menu displayed by the second menu i.e. Menu 2 is not at all accessible and pops out from the left side of the screen.
Can you please help me regarding this matter ???
Otherwise you've made a brilliant effort with this kind of creation, which I was searching from a long time.
Thanking you in anticipation....
|
|
|
|

|
I am modifying the main program menu (MDI application) in my application (deleting and adding/inserting new menu items) but when I do that the size of the boxes do not adapt to the new size of the menu items (e.g. if I had 2 menu items 'Nice to have' and ' Funny' and I delete the 'Nice to have' then after redrawing the 'Funny' would be drawn with the box size of the original 'Nice to have'). Is there a way to get the main menu to resize all items after they have been changed?
By the way, the same happens when I use ModifyODMenu on the Main Menu to change the text. It does not resize the box either.
I am using version 1.25 under XP SP2 with Visual Studio 2005.
|
|
|
|

|
I am using NewMenu with the owner-drawn menus functions, for reasons that I don't remember off-hand. I had some trouble getting things to work right with the non-owner-drawn functions.
Unfortunately, owner-drawn menus with icons are not supported in MS Vista (http://msdn2.microsoft.com/en-us/library/bb757020.aspx[^]) and the spot for the bitmaps is just blank.
I downloaded the source code zip file, and the files are from 2003. Do you have any updates to transparently work on Vista, or do you suggest just not using NewMenu when the application determines that it's running on Vista?
Thanks,
John
|
|
|
|

|
The ownerdrawn menu are still supported on windows Vista. My samples still runs. You need to download the latest version 1.25 from my homepage. Icons seems no longer supported in the normal menu (Not owner drawn), so you have it to convert to a bitmap.
|
|
|
|

|
Curious. I have version 1.25 and am using bitmaps, and none of the menu pictures display. I'll do some debugging and see if I can't find out why. It could be because the pictures are all 256-color bitmaps, and I think that Vista article said that it wanted 32-bit RGB bitmaps instead...
Thanks,
John
|
|
|
|

|
Bruno, I have tried the following, all with no luck:
1) I went to a lot of trouble to write code that auto-converts all our 256-color bit maps to 32-bit bitmaps with alpha masking. These display correctly in XP and do not display at all in Vista (same as the original 256-color bit maps).
2) I then looked at the NewMenu code, and thought I saw some problems (based on my assumption from the MS article that seems to say that 32-bimaps with alpha masking are required):
a) Every use of m_IconsList.Create uses ILC_COLORDB. I changed this ILC_COLOR32. I was not sure whether ILC_MASK was a problem or not, so I tried removing that, but nothing changed.
b) I found that the CopyImage call should use LR_CREATEDIBSECTION, but that did not help.
c) I found that the CopyImage call is returning NULL, so I tried just using the original bitmap rather than trying to use the NULL handle from the failed CopyImage call. This changed the symptoms from not having ANY icons, to having icons that are all BLACK.
I am really stuck here, so any help or advice is appreciated.
Meanwhile, I will download your sample program and see if I can figure out what is different from my application.
Thanks,
John
|
|
|
|

|
Is it possible that you can make a small sample and send it to me for that I have the possibility to look for the problem?
|
|
|
|

|
When I run application with CNewMenu under release mode that's work OK. But under debug mode i've got an error in NewMenu.cpp at 6363 line. How can I fix this problem? P.S. I use Windows XP SP2, VS 2008.
|
|
|
|

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

|
tnkx but i'm going to use standart toolbar. There are less problems with it
|
|
|
|

|
i creat an new project based on dialog and follow the steps from 1 to 4 you writed "How to Use the CNewMenu in a Dialog-based Application" ,then i built the program it makes 14 errors about CImageList .
the definition " #include " have included in the file "stdafx.h" already but there still are 14 errors "syntax error : identifier 'CImageList' " .....
my questions is "
what kind of mistake in steps 1 to 4 i have done may result in the errors ? "
i do not kown if i have made myself understand .....
can you help me with this problem?
|
|
|
|

|
Did you realy make a C++ MFC project? (Not managed code, not .NET project)
|
|
|
|

|
yes,,
and i have got the answer in the before FAQ
"compile errors...thoughts? -----elbo_chew ----9:42 7 Dec '02" .
the problem is i have too much replaced, thank you all the same !!!
|
|
|
|

|
void CNewToolBar::PaintTBButton(LPNMTBCUSTOMDRAW lpNMTBCustomDraw)
{
//...
// error!!! => CFont* pOldFont = (CFont*)pDC->SelectStockObject(ANSI_VAR_FONT);
// If toolbar buttons have (BTNS_SHOWTEXT | TBSTYLE_AUTOSIZE) style, then this error will be significant...
CFont* pOldFont = pDC->SelectObject(GetFont()); // <= this is ok
//...
}
|
|
|
|

|
You have right; I forgot to publish this correction.
|
|
|
|

|
hello,
thanks for you job,i like it,but i use VC8.
this code:
static const AFX_MSGMAP_ENTRY* GetMessageEntries()
{
static const AFX_MSGMAP_ENTRY Entries[] =
{
ON_WM_MEASUREITEM()
ON_WM_MENUCHAR()
ON_WM_INITMENUPOPUP()
ON_WM_ENTERMENULOOP()
ON_WM_EXITMENULOOP()
ON_WM_TIMER()
ON_WM_CREATE()
ON_WM_NCHITTEST()
ON_WM_DESTROY()
ON_WM_SYSCOLORCHANGE()
#ifdef USE_NEW_DOCK_BAR
ON_WM_NCPAINT()
ON_WM_PAINT()
ON_WM_ACTIVATEAPP()
ON_WM_ACTIVATE()
#endif //USE_NEW_DOCK_BAR
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 }
};
return Entries;
}
Error:
error C2653: 'ThisClass' : is not a class or namespace name
while compiling class template member function 'const AFX_MSGMAP_ENTRY *CNewFrame<baseclass>::GetMessageEntries(void)'
with
[
baseClass=CMiniDockFrameWnd
]
see reference to class template instantiation 'CNewFrame<baseclass>' being compiled
with
[
baseClass=CMiniDockFrameWnd
]
...........
why?
thanks again</baseclass></baseclass>
|
|
|
|

|
Did you use the latest verson 1.25 from my homepage?
|
|
|
|

|
I am currently using 1.25 and getting the same issues, I found commenting them out allowed me to compile my code at least, however this is not a valued method.
Do I have to add a header or define to run these files?
Kind Regards,
Alisdair
|
|
|
|

|
I have no problem to compile it with the new studio VS2008, my samples and the CNewMenu with the version 1.25 still works. Did you tried to compile it too?
|
|
|
|

|
I have the very same problem as well.
Can you please post a download for the VC2008 ( VS9 ) version ?
|
|
|
|

|
If you use VC8 or later,you should add this code in here ,like this...
typedef CNewFrame<baseclass> ThisClass; //....Add in here
typedef CNewFrame<baseclass> MynewFrame;
...
static const AFX_MSGMAP_ENTRY* GetMessageEntries()
{
static const AFX_MSGMAP_ENTRY Entries[] =
{
ON_WM_MEASUREITEM()
....
};
return Entries;
}
Because of after the maro is extended,The ThisClass have not definded in here;
And if you have more error about call xxx lost argument..you may also modify these code in here ..
AddTheme(new CMenuTheme(CNewMenu::STYLE_ICY,
CNewMenu::MeasureItem_Icy,
CNewMenu::DrawItem_Icy,
CNewMenu::DrawMenuTitle,TRUE));
you must add the char '&' in front of CNewMenu:: like this...
AddTheme(new CMenuTheme(CNewMenu::STYLE_ICY,
&CNewMenu::MeasureItem_Icy,
&CNewMenu::DrawItem_Icy,
&CNewMenu::DrawMenuTitle,TRUE));
Do what want to do,Go where want to go ,nothing is impossible!
modified on Monday, May 25, 2009 4:47 AM
|
|
|
|

|
Hello ,
I want to add a custom icon to a newly added menu item.Please let me know how i can do it.
Thanks,
Sunil kumar verma
Software Engineer
|
|
|
|

|
In the same way as described in the article above or you insert the Icon into an CImageList and modify the menuitem like the samples.
|
|
|
|

|
Hi, I am vb .net programmer and i want to change the background color of vb .net MAINMENU. I can able to change menuitem's backcolor, i can put images in menuitems and everything its very easy anyone can do it. But what about mainmenu's background color.
If anyone has an answer of my query please write me.
Thank you in advance.
Rajesh Champaneria
PROGRAMMER
CELLCOMM SOLUTIONS LTD.
BANGALORE
champaneria@cellcommsolutions.com
(+91)9902269852
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
An easy use of owner drawn menu with variable styles like new Office products with titles, shading and icons.
| Type | Article |
| Licence | CPOL |
| First Posted | 28 May 2002 |
| Views | 1,121,250 |
| Bookmarked | 515 times |
|
|