none
Not receive WM_MEASUREITEM message RRS feed

  • 问题

  • Hi, there,

    I know there are many questions whose names are quite similar to mine, but their answers don't meet my demand. My problem is:

    Now, I have created a notify icon in notification area, implemented the handler of WM_CONTEXTMENU message, so when I right click the notify icon, a context menu will popup. Then I want the first menu item of the context menu to be a owner-drawn one. I have already changed the flag of the first menu item with following code

    ModifyMenu(hmenu, menuItemId, MF_BYCOMMAND | MF_OWNERDRAW, menuItemId, (LPTSTR) this)

    And this function return correctly. 

    But in my windows main procedure, the WM_MEASUREITEM message is never received. 

    Is there any other configuration I miss? Or the owner of the context menu is not my main windows?

    Thanks in advance for any help.

    Cheers,

    Hu Jingfei


    潜心研究医学图像

    2012年2月28日 3:50

答案

  • Add Window call back function like this:

    case WM_CONTEXTMENU:
    		{
    			POINT pt = {LOWORD(lParam), HIWORD(lParam)};
    			HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1));
    			if(NULL == hMenu)
    			{
    				return 0;
    			}
    			HMENU hSubMenu = GetSubMenu(hMenu, 0);
    			
    			int nCount = GetMenuItemCount(hSubMenu);
    			UINT nID = 0;
    			const UINT MAX_COUNT = 64;
    			TCHAR szText[MAX_COUNT] = {0};
    			for(int i=0; i<nCount; i++)
    			{
    				nID = GetMenuItemID(hSubMenu, i);
    				if((-1 != nID) && (0 != nID))
    				{
    					GetMenuString(hSubMenu, nID, szText, MAX_COUNT, MF_BYCOMMAND);
    					ModifyMenu(hSubMenu, nID, MF_BYCOMMAND | MF_OWNERDRAW, nID, szText);
    				}
    			}
    			TrackPopupMenu(hSubMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, NULL, hWnd, NULL);
    			DestroyMenu(hMenu);
    		}
    		break;
    	case WM_MEASUREITEM:
    		{
    			static int i = 0;
    			TCHAR buf[32] = {0};
    			_stprintf(buf, _T("MenuItem: %d"), ++i);
    			MessageBox(hWnd, buf, _T("Message"), 0);
    		}
    		break;


    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    • 已建议为答案 Helen Zhao 2012年2月29日 6:09
    • 已标记为答案 Hu Jingfei 2012年2月29日 11:49
    2012年2月28日 5:13
    版主