如何使用Windows SDK重绘菜单(弹出菜单的框架边缘)? [英] How to Use Windows SDK redrawing the Menu (The Frame edge of the popupmenu)?
问题描述
大家好,
我正在尝试重新绘制菜单(具有POPUP样式的菜单,右键菜单为右键菜单),我已经重新编码了以下三则消息:WM_MESUREITEM
,WM_INITPOPUP
和WM_DRAWITEM
,但是最终结果并不令我满意.
上面的三则消息仅涉及菜单项,整个菜单框架看起来非常丑陋,菜单框架尚未重绘,我仍然不知道如何.
在这里,我列出了这三个消息的代码:
大小写 WM_DRAWITEM:
{
UINT ctlID =(UINT)wParam;
LPDRAWITEMSTRUCT lpDraw =(LPDRAWITEMSTRUCT)lParam;
// if(ctlID == 0){
HDC hDC = lpDraw-> hDC;
SetBkMode(hDC,TRANSPARENT);
字符 mStr [ 255 ] = { 0 };
HMENU hMenu =(HMENU)lpDraw-> hwndItem;
int len = GetMenuString(hMenu,lpDraw-> itemID,mStr, 255 ,MF_BYCOMMAND);
// HRGN菜单Rgn = 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 ));
如果(lpDraw-> itemID!= 0 ){
如果(lpDraw-> itemAction& ODA_SELECT)
{
FillRect(hDC,&(lpDraw-> rcItem),hBrushSel);
如果(lpDraw-> itemState& ODS_GRAYED)
SetTextColor(hDC,RGB( 70 , 70 , 70 ));
else SetTextColor(hDC,RGB( 206 , 206 , 206 ));
}
如果(!(((lpDraw-> itemAction& ODA_SELECT)&&(lpDraw-> itemState& ODS_SELECTED))
{
FillRect(hDC,&(lpDraw-> rcItem),hBrushUnSel);
如果(lpDraw-> itemState& ODS_GRAYED)
SetTextColor(hDC,RGB( 70 , 70 , 70 ));
else SetTextColor(hDC,RGB( 206 , 206 , 206 ));
}
}
其他 {
HDC hDCMEM = CreateCompatibleDC(hDC);
HBITMAP hBMP = LoadBitmap(G_hInstance," );
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);
返回 0 ;
// FrameRect(hDC,&(lpDraw-&rc; rcItem),hBrush);
// }
}
break ;
案例 WM_MEASUREITEM:
{
UINT ctlID =(UINT)wParam; // 控件标识符
LPMEASUREITEMSTRUCT lpItemStruct =(LPMEASUREITEMSTRUCT)lParam;
如果(lpItemStruct-> CtlType == ODT_MENU){
如果( 0 == lpItemStruct-> itemID){
lpItemStruct-> itemWidth = 150 ;
lpItemStruct-> itemHeight = 2 ;
}
其他 {
lpItemStruct-> itemWidth = 150 ;
lpItemStruct-> itemHeight = 20 ;
}
返回 0 ;
}
}
break ;
案例 WM_INITMENUPOPUP:
{
HMENU hMenu =(HMENU)wParam;
int uPos =(UINT)LOWORD(lParam);
BOOL fSystemMenu =(BOOL)HIWORD(lParam);
int itemCount = GetMenuItemCount(hMenu);
for ( int i = 0 ;我< itemCount; i ++){
HMENU mItem = GetSubMenu(hMenu,i);
UINT mItemID = GetMenuItemID(hMenu,i);
字符 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);
}
返回 0 ;
}
中断;
这篇关于如何使用Windows SDK重绘菜单(弹出菜单的框架边缘)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
希望任何人给我一个建议,谢谢! google.com/search?q=owner+draw+menu&aq=f&oq=owner+draw+menu&aqs=chrome.0.57j0l3j62l2.7555&sugexp=chrome,mod=1&sourceid=chrome&ie=UTF -8>这些链接 [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 !You have not really explained what your problem is, but some of these links[^] may help you.