|
I work on an SDI application project. The XP-style menu works fine in main menu. Popups in the main view look perfect too. However, I haven't managed to get it working in dialogs. In this case, context menus are created and maintained by dialog controls in our project. I inserted the CMenuXP macros to such a control and added the SetXPLookNFeel call. The result was quite poor. The menu didn't have any shading (it had the old-style frame instead) and submenus couldn't be opened. Only menu items were displayed correctly and highlighting worked. I would be grateful if anyone can help me to solve this issue.
|
|
|
|
|
I solved the problem with shading. The solution is quite simple. The procedure hooking loaded windows (CWndMenuXP::WindowsHook) automatically returns if the window is not a foreground window (frame or dialog window) and no hook is registered. It causes the messages for controls are not processed by CWndMenuXP::SubClassMenuProc and the menu border is therefore painted in the old style. To overcome it, just register the foreground window to have XP style enabled, most likely in the PreSubclassWindow handler:
CMenuXP::SetXPLookNFeel(GetForegroundWindow(),true);
This solution can however cause problems if you mix original and XP style menus on the same dialog. To avoid that, you can activate the XP-style just when the context menu is displayed and deactivate the style after it:
CMenuXP::SetXPLookNFeel(GetForegroundWindow(),true);
pPopup->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
CMenuXP::SetXPLookNFeel(GetForegroundWindow(),false);
|
|
|
|
|
Does this all work OK on win NT and 98? Are there any problems on these systems.
|
|
|
|
|
I tested the code under XP and it looks like for the toolbar, there is an rectangular contour about the toolbar that is not rendered.
This seems to occur on starting up the dialog, MDI or SDI app.
A very minor issue, but I wanted to mention it.
It works fine in Win2000.
I'm wondering if people have tested on Win98, Me?
Very fine work.
|
|
|
|
|
Hi, i'm using CMenuXP in all of my applications.
It is one of the best classes i ever found in CodeProject.
No other tool is as easy to integrate.
Now the question:
Do you plan to add support for the new Office XP 2003 style?
If you do, what is the time line?
thanks in advance!
...and it works!
FPF
|
|
|
|
|
1000 answers and no response from our Jean
so what?
write-forget that
|
|
|
|
|
|
I'm using dialog based application. Till now i can change state to ENABLED or GRAYED by using MFS_ENABLED and MFS_GRAYED. (i was tryin with MF_GRAYED but no effect). However MFS_CHECKED AND MFS_RADIOCHECK have no effect using this code. I don't understand why?
CWnd* pWnd = AfxGetMainWnd();
CMenu *pMenu = pWnd->GetMenu();
pMenu->EnableMenuItem ( ID_MODE_BLACKNWHITE,MFS_CHECKED);
I do check item but using Visual Property Form. Pls help
|
|
|
|
|
PLEASE HELP!!!!
my popup menu dosent get the XP style no matter what... please tell me how to get my Popup Menu get the XP effect..... 
|
|
|
|
|
Hi,
i think you mean popup menus using TrackPopupMenu.
You have to set the hWnd parameter to the main window handle.
So the menu messages are routed through the main window message handler containing ON_MENUXP_MESSAGES().
TrackPopupMenu(pContextPopup->GetSafeHmenu(), TPM_LEFTALIGN, ptCursor.x, ptCursor.y, 0, AfxGetMainWnd()->GetSafeHwnd(), NULL);
...and it works!
FPF
|
|
|
|
|
Thnks ... it works.. but when i pass the main WND as u told ...the Menu Items Get Disabled.... 
|
|
|
|
|
When you use the TrackPopupMenu method, the HWND passed in argument must have the MENUXP macros declared for it. (not only for the main window)
|
|
|
|
|
See Jean.. I have Declared the macros in MainFrm... OK now i an doing the TrackPopupMenu in My View Class's RButtonDown... n passing "GetParentFrame()" in it looks like this
l_RSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y,GetParentFrame());
now when i do this the menu is displayed properly in XP style...but then all the items get disabled.. i fail to understand.. if i pass "this" insted of GetParentFrame().. the menu does not get XP style looks .. but Menu Items r properly enabled.... PLZ help
|
|
|
|
|
I REPEAT: If you pass 'this' in the TrackPopupMenu, 'this' MUST HAVE the MENUXP macros. So simply declare MENUXP for your view class !
|
|
|
|
|
The current implementation draws the 'selected' triangles (chevrons) white and I would like to have them drawn black. I've searched and searched and cannot find where they are drawn.
Thanks.
|
|
|
|
|
The submenu arrows are drawn by the system/menu/Windows (whatever you want to call it). There is a way you can draw it yourself and stop the system from drawing it. Basically, you have to add code to your OnDrawItem function to draw the arrow when needed, then call ExcludeClipRect with the rect where the arrow shows up to stop the system from drawing it. I've done this in my modified version of CMenuXP. Let me know if you are interested.
-Frank
|
|
|
|
|
Good site, good member!
by scroll_lock
of Brazil
|
|
|
|
|
I'm using dialog based application. Till now i can change state to ENABLED or GRAYED by using MFS_ENABLED and MFS_GRAYED. (i was tryin with MF_GRAYED but no effect). However MFS_CHECKED AND MFS_RADIOCHECK have no effect using this code. I don't understand why?
CWnd* pWnd = AfxGetMainWnd();
CMenu *pMenu = pWnd->GetMenu();
pMenu->EnableMenuItem ( ID_MODE_BLACKNWHITE,MFS_CHECKED);
I do check item but using Visual Property Form Pls help
|
|
|
|
|
I am seeing on Win2k where a faint image of the selected menu option is left on the screen if I select a menu option and move the cursor immediately after the selection. I don't see the problem on XP. Has anyone seen this problem? Is there a fix?
|
|
|
|
|
How may I have CheckBox and RadioButton looking as nice as XP Button object?
|
|
|
|
|
I still seem to have problems with this. I did see in a couple of comments from the author that this has been taken care of in the latest fix.
But I am working in W2K, compiling in .NET VS but I am still not able to get the (File, Edit...) Menu headers to be highlighted in the blue box as in XP products...
Please tell me what I am doing wrong here.
Tons of thanks to this code....
Mike
Austin
|
|
|
|
|
|
Its not clear what you ask to do.Can you please explain in bit detail?It will be quite helpful.
|
|
|
|
|
I have included the changed source from menuxp.h.
Notice the FrameRect and FillRect replacement for Rectangle. Just search your code for 'Rectangle(' and replace that section with the one from this file.
Smae enhancements regarding Multi MRU Support and Office2003 Look-N-Feel have been excluded to eliminate confusion.
Let me know if there is a better way to comunicate the change.
LRESULT OnCustomDraw (int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
TCHAR sClass[128];
GetClassName (pnmh->hwndFrom, sClass, 128);
if ( _tcscmp (sClass, _T("WTL_CommandBarXP")) )
{
return CDRF_DODEFAULT;
}
NMCUSTOMDRAW* pCustomDraw = (NMCUSTOMDRAW*)pnmh;
if ( pCustomDraw->dwDrawStage == CDDS_PREPAINT )
{
// Request prepaint notifications for each item
return CDRF_NOTIFYITEMDRAW;
}
if ( pCustomDraw->dwDrawStage == CDDS_ITEMPREPAINT )
{
CDCHandle dc (pCustomDraw->hdc);
CRect rc = pCustomDraw->rc;
TCHAR sBtnText[128];
//[kwh] Mimiced base class for getting text
//
//::SendMessage (pnmh->hwndFrom, TB_GETBUTTONTEXT, pCustomDraw->dwItemSpec, (LPARAM)sBtnText);
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(TBBUTTONINFO);
tbbi.dwMask = TBIF_TEXT;
tbbi.pszText = sBtnText;
tbbi.cchText = sizeof(sBtnText) / sizeof(TCHAR);
GetButtonInfo((int)pCustomDraw->dwItemSpec, &tbbi);
if ( pCustomDraw->uItemState & CDIS_HOT )
{
COLORREF crHighLight = ::GetSysColor (COLOR_HIGHLIGHT);
CBrush brush, brushFrame;
brush.CreateSolidBrush ((pCustomDraw->uItemState & CDIS_SELECTED) ? HLS_TRANSFORM (crHighLight, +50, -50) : HLS_TRANSFORM (crHighLight, +70, -57));
brushFrame.CreateSolidBrush (crHighLight);
dc.FillRect(&rc, brush);
dc.FrameRect(&rc, brushFrame);
dc.SetTextColor ( (pCustomDraw->uItemState & CDIS_SELECTED) ? ::GetSysColor (COLOR_HIGHLIGHTTEXT) : RGB(0,0,0) );
}
else
{
// dc.FillSolidRect (rc, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), +20, 0));
dc.FillSolidRect (rc, ::GetSysColor (COLOR_3DFACE));
dc.SetTextColor ( ::GetSysColor (m_bParentActive ? COLOR_BTNTEXT : COLOR_3DSHADOW) );
}
dc.SetBkMode (TRANSPARENT);
HFONT hOldFont = dc.SelectFont ((HFONT)GetStockObject (DEFAULT_GUI_FONT));
dc.DrawText (sBtnText, _tcslen (sBtnText), rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
dc.SelectFont(hOldFont);
return CDRF_SKIPDEFAULT;
}
bHandled = FALSE;
return CDRF_DODEFAULT;
}
#define IMGPADDING 6
#define TEXTPADDING 8
// From <winuser.h>
#define OBM_CHECK 32760
void DrawItem (LPDRAWITEMSTRUCT lpDrawItemStruct)
{
_MenuItemData* pmd = (_MenuItemData*)lpDrawItemStruct->itemData;
const RECT& rcItem = lpDrawItemStruct->rcItem;
CDCHandle dc = lpDrawItemStruct->hDC;
const BOOL bDisabled = lpDrawItemStruct->itemState & ODS_GRAYED;
const BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
const BOOL bChecked = lpDrawItemStruct->itemState & ODS_CHECKED;
const COLORREF clrFace = HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), +75, 0);
COLORREF crBackImg = CLR_NONE;
const COLORREF crHighLight = ::GetSysColor (COLOR_HIGHLIGHT);
CRect rc (rcItem);
rc.right = m_szBitmap.cx+IMGPADDING;
crBackImg = HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), +20, 0);
dc.FillSolidRect (rc, crBackImg);
rc.left = rc.right;
rc.right = rcItem.right;
dc.FillSolidRect (rc, clrFace);
if ( bSelected )
{
crBackImg = bDisabled ? HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), +73, 0) : HLS_TRANSFORM (crHighLight, +70, -57);
CBrush brush, brushFrame;
brush.CreateSolidBrush (crBackImg);
brushFrame.CreateSolidBrush (crHighLight);
dc.FillRect(&rcItem, brush);
dc.FrameRect(&rcItem, brushFrame);
}
if ( pmd->fType & MFT_SEPARATOR )
{
CPenDC pen (dc, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -18, 0));
dc.MoveTo (rcItem.left+m_szBitmap.cx+IMGPADDING+TEXTPADDING, (rcItem.top+rcItem.bottom)/2);
dc.LineTo (rcItem.right-1, (rcItem.top+rcItem.bottom)/2);
}
else
{
CRect rc (rcItem);
LPTSTR pszTab = _tcschr(pmd->lpstrText,_T('\t'));
TCHAR szCaption[200];
if ( pszTab)
{
*pszTab = _T('\0');
_tcscpy(szCaption, pmd->lpstrText);
*pszTab = _T('\t');
}
else
{
_tcscpy(szCaption, pmd->lpstrText);
}
dc.SetTextColor (bDisabled ? HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -18, 0) : ::GetSysColor (COLOR_MENUTEXT));
dc.SetBkMode (TRANSPARENT);
CBoldDC bold (dc, (lpDrawItemStruct->itemState & ODS_DEFAULT) != 0);
rc.left = m_szBitmap.cx+IMGPADDING+TEXTPADDING;
dc.DrawText (szCaption, _tcslen(szCaption), rc, DT_SINGLELINE|DT_VCENTER|DT_LEFT);
if ( pszTab )
{
pszTab = CharNext(pszTab);
rc.right -= TEXTPADDING+4;
dc.DrawText (pszTab, _tcslen (pszTab), rc, DT_SINGLELINE|DT_VCENTER|DT_RIGHT);
}
if ( bChecked )
{
CBrush brush, brushFrame;
brush.CreateSolidBrush (crBackImg = bDisabled ? HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), +73, 0) :
(bSelected ? HLS_TRANSFORM (crHighLight, +50, -50) : HLS_TRANSFORM (crHighLight, +70, -57)));
brushFrame.CreateSolidBrush (crHighLight);
CRect rc (rcItem.left+1, rcItem.top+1, rcItem.left+m_szButton.cx-2, rcItem.bottom-1);
dc.FillRect(&rc, brush);
dc.FrameRect(&rc, brushFrame);
}
if ( m_hImageList != NULL && pmd->iButton != -1 )
{
bool bOver = !bDisabled && bSelected;
if ( bDisabled || (bSelected && !bChecked) )
{
HICON hIcon = ImageList_ExtractIcon (NULL, m_hImageList, pmd->iButton);
CBrush brush;
brush.CreateSolidBrush (bOver ? HLS_TRANSFORM (::GetSysColor (COLOR_HIGHLIGHT), +50, -66) : HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -27, 0));
dc.DrawState (CPoint (rcItem.left + ( bOver ? 4 : 3 ), rc.top + ( bOver ? 5 : 4 )),
CSize (m_szBitmap.cx, m_szBitmap.cx), hIcon, DSS_MONO, brush);
DestroyIcon (hIcon);
}
if ( !bDisabled )
{
::ImageList_Draw (m_hImageList, pmd->iButton, dc.m_hDC,
rcItem.left+( (bSelected && !bChecked) ? 2 : 3 ), rc.top+( (bSelected && !bChecked) ? 3 : 4 ), ILD_TRANSPARENT);
}
}
else if ( bChecked )
{
// Draw the check mark
rc.left = rcItem.left+5;
rc.right = rc.left + m_szBitmap.cx + IMGPADDING;
dc.SetBkColor (crBackImg);
HBITMAP hBmp = LoadBitmap (NULL, MAKEINTRESOURCE(OBM_CHECK));
dc.DrawState (CPoint (rc.left,rc.top+3), CSize(rc.Size()), hBmp, DSS_NORMAL, (HBRUSH)NULL);
DeleteObject (hBmp);
}
}
}
Ken
|
|
|
|
|
Hi Ken,
The problem is,I can download the sample project,build and run it successfully.But when I add the MenuXP to my project it doesnt work.I have followed all the steps as mentioned on the web page.
Thanks a lot.
|
|
|
|
|