Weird popup menu display on XP
-
would like to have your point of view about a really weird behaviour with my popup menu on XP (Desktop properties => Menu Fade effect). I only use CMenu to create the popup menu. I coded a very simple MFC program to display a popup memu when the left mouse button is pressed. So I back and forth between my App (Left button) and the desktop (right button)and after a while the menu doesn't display fine. (http://home.comcast.net/~llaissus/MFCMenu.jpg) (http://home.comcast.net/~llaissus/MFCMenu2.jpg). I just get the shading for the whole menu sytem on XP. I have to click again in my app to get a good display. If I didn't do that I have to reboot my PC to fix that. (It seems like when you put break point in WM_DRAWITEM). Note It works fine with Menu Scroll effect or no menu effect. I think it's a problem of timing but I don't know why I did that and it works better
LRESULT CALLBACK NewMenuHook(int code, WPARAM wParam, LPARAM lParam) { return CallNextHookEx(HookOldMenuCbtFilter, code,wParam, lParam); } BOOL CMFCMenuApp::InitInstance() { // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. HookOldMenuCbtFilter = ::SetWindowsHookEx(WH_CALLWNDPROC, NewMenuHook, NULL, ::GetCurrentThreadId()); .../... }
Code .NET: http://home.comcast.net/~llaissus/MFCMenu.zip Has anyone any idea ? Is it a XP bug ? Regards -
would like to have your point of view about a really weird behaviour with my popup menu on XP (Desktop properties => Menu Fade effect). I only use CMenu to create the popup menu. I coded a very simple MFC program to display a popup memu when the left mouse button is pressed. So I back and forth between my App (Left button) and the desktop (right button)and after a while the menu doesn't display fine. (http://home.comcast.net/~llaissus/MFCMenu.jpg) (http://home.comcast.net/~llaissus/MFCMenu2.jpg). I just get the shading for the whole menu sytem on XP. I have to click again in my app to get a good display. If I didn't do that I have to reboot my PC to fix that. (It seems like when you put break point in WM_DRAWITEM). Note It works fine with Menu Scroll effect or no menu effect. I think it's a problem of timing but I don't know why I did that and it works better
LRESULT CALLBACK NewMenuHook(int code, WPARAM wParam, LPARAM lParam) { return CallNextHookEx(HookOldMenuCbtFilter, code,wParam, lParam); } BOOL CMFCMenuApp::InitInstance() { // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. HookOldMenuCbtFilter = ::SetWindowsHookEx(WH_CALLWNDPROC, NewMenuHook, NULL, ::GetCurrentThreadId()); .../... }
Code .NET: http://home.comcast.net/~llaissus/MFCMenu.zip Has anyone any idea ? Is it a XP bug ? RegardsAm replying according to the snapshots you sent, cuz I encountered such weird effect before and it mya be the same problem. I have encountered this problem when I was making an owner draw menu, which I guess you are making one as well. According to the MSDN you shall save the DC state that is passed to you in the DRAWITEMSTRUCT struct and restore it back. I found that this is simply calling SaveDC and RestoreDC. Follwing is the code i used:
void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your message handler code here and/or call default if(nIDCtl == 0) //check if menu { CDC dc; dc.Attach(lpDrawItemStruct->hDC); //wrap the HDC into a CDC dc.SaveDC(); //draw the menu item . . . dc.RestoreDC(-1); //restore the dc to the previous state dc.Detach(); //detach the HDC from the CDC to prevent its destruction } }
When added this lines it did solve the problem and menus didnt show this effect anymore, so I hope this solves your problem.