Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello Everyone,
 
I'm trying to redraw the menu (a menu with POPUP style ,right keydown menu), I already recoded three messages: WM_MESUREITEM, WM_INITPOPUP and WM_DRAWITEM, but the finally result doesn't make me satisfied.
The three messages above only deal with menu items, the whole menu frame looks so ugly, the frame of the menu has not been redrawn and I still do not know how.
 
Here I list the code of the three messages:
case WM_DRAWITEM:
{
	UINT ctlID = (UINT) wParam;  
	LPDRAWITEMSTRUCT lpDraw = (LPDRAWITEMSTRUCT)lParam; 
	//if (ctlID == 0)	{
		HDC hDC = lpDraw->hDC;
 
		SetBkMode(hDC , TRANSPARENT);
		char mStr[255] = {0};
		HMENU hMenu = (HMENU)lpDraw->hwndItem;
		int len = GetMenuString(hMenu ,lpDraw->itemID , mStr , 255 , MF_BYCOMMAND);
		//HRGN menuRgn = lpDraw->rcItem;
		HBRUSH hBrush = CreateSolidBrush(RGB(33, 82 ,153));
		HBRUSH hBrushSel = CreateSolidBrush(RGB(37,125,194));
		HBRUSH hBrushFont = CreateSolidBrush(RGB(206,206,206));
		HBRUSH hBrushUnSel = CreateSolidBrush(RGB(27,30,32));
		HBRUSH hBrushSep   = CreateSolidBrush(RGB(0,0,0));
		
		if (lpDraw->itemID != 0) {
			if (lpDraw->itemAction & ODA_SELECT)  
			{
				FillRect(hDC ,&(lpDraw->rcItem) , hBrushSel);
				if (lpDraw->itemState & ODS_GRAYED)
					SetTextColor(hDC , RGB(70,70,70));
				else SetTextColor(hDC , RGB(206,206,206));
			}
			if (!((lpDraw->itemAction & ODA_SELECT) &&(lpDraw->itemState & ODS_SELECTED))) 
			{
				FillRect(hDC ,&(lpDraw->rcItem) , hBrushUnSel);
				if (lpDraw->itemState & ODS_GRAYED)
					SetTextColor(hDC , RGB(70,70,70));
				else SetTextColor(hDC ,RGB(206,206,206));
			}		
		}
		else {
			HDC hDCMEM = CreateCompatibleDC(hDC);
			HBITMAP hBMP = LoadBitmap(G_hInstance , "SEPARATOR");
			SelectObject(hDCMEM , hBMP );
			StretchBlt(hDC , (lpDraw->rcItem).left ,(lpDraw->rcItem).top, RWIDTH(lpDraw->rcItem) ,RHEIGHT(lpDraw->rcItem),
				 hDCMem ,		1 , 0 , 1, 4 ,SRCCOPY);
			//FillRect(hDC ,&(lpDraw->rcItem) , hBrushSep);
			DeleteObject(hBMP);
			DeleteDC(hDCMEM);
			
		}
		TextOut(hDC ,(lpDraw->rcItem).left + 20 ,(lpDraw->rcItem).top + 4 , mStr , len  );
		DeleteObject(hBrush);
		DeleteObject(hBrushSel);
		DeleteObject(hBrushFont);
		DeleteObject(hBrushUnSel);
		DeleteObject(hBrushSep);
		return 0;
		//FrameRect(hDC , &(lpDraw->rcItem) , hBrush);
	//}
}
break;
case WM_MEASUREITEM: 
{
	UINT ctlID = (UINT) wParam; //控件标识符
	LPMEASUREITEMSTRUCT lpItemStruct = (LPMEASUREITEMSTRUCT)lParam; 
	if (lpItemStruct->CtlType == ODT_MENU ) {	 
		if (0 == lpItemStruct->itemID)	{
			lpItemStruct->itemWidth = 150;
			lpItemStruct->itemHeight = 2;
		}
		else {
			lpItemStruct->itemWidth = 150;
			lpItemStruct->itemHeight = 20;	
		}
		return 0;
	}			
	
}
break;
case WM_INITMENUPOPUP:
{
	HMENU hMenu = (HMENU)wParam;
	int		uPos = (UINT) LOWORD(lParam); 
	BOOL	fSystemMenu = (BOOL) HIWORD(lParam); 
	
	int itemCount = GetMenuItemCount(hMenu);
	for (int i = 0 ; i < itemCount ; i++)	{
		HMENU mItem = GetSubMenu(hMenu , i);
		UINT mItemID = GetMenuItemID(hMenu , i);
		char mStr[255] = {0};
		GetMenuString(hMenu , i , mStr , 255 , MF_BYPOSITION);
		ModifyMenu(hMenu,i,MF_BYPOSITION|MF_OWNERDRAW,mItemID,(LPCTSTR)mStr);
		//MessageBox(hWnd , mStr , "MENU" , MB_OK);
	}
	return 0;
}
break;
 
Hope anyone give me a suggestion , thanks !
Posted 24-Nov-12 8:29am
Younth483
Edited 24-Nov-12 8:53am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You have not really explained what your problem is, but some of these links[^] may help you.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 25 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100