如何使用函数SetMenuItemBitmaps()自画菜单的图标?(100分)

  • 主题发起人 主题发起人 zouming
  • 开始时间 开始时间
Z

zouming

Unregistered / Unconfirmed
GUEST, unregistred user!
如何使用函数SetMenuItemBitmaps()自画菜单的图标?<br>SetMenuItemBitmaps(Menu,indexMenu,MF_BYPOSITION,LoadBitmap(HInstance,PChar('myBitmap')),0);
 
菜单的自画。<br>function DrawBmpMenu(itemMenu : DRAWITEMSTRUCT):BOOL;<br>var<br>&nbsp; orgrect, rG, rect: TRect;<br>&nbsp; p : TPoint;<br>&nbsp; DC : HDC;<br>&nbsp; bmpDC : HDC;<br>&nbsp; lb : LOGBRUSH;<br>&nbsp; oldBrush,Brush : HBRUSH;<br>&nbsp; oldbmp,bmp,bufBmp : HBITMAP;<br>&nbsp; BKcolor,txtColor : DWORD;<br>&nbsp; oldRight : integer;<br>&nbsp; i : integer;<br>begin<br>&nbsp; rect := itemMenu.rcItem;<br>&nbsp; //DC := CreateCompatibleDC(itemMenu.hDC);<br>&nbsp; DC := itemMenu.hDC;<br>&nbsp; {<br>&nbsp; bufBmp := CreateCompatibleBitmap(DC,<br>&nbsp; &nbsp; &nbsp; rect.right - rect.left,rect.bottom-rect.top);<br>&nbsp; SelectObject(DC,bufBmp);<br>&nbsp; }<br>&nbsp; //Brush := CreateSolidBrush(GetSysColor(COLOR_MENU));<br>&nbsp; //SelectObject(DC,brush);<br>&nbsp; //DeleteObject(brush);<br>&nbsp; //DC := itemMenu.hDC;<br>&nbsp; orgrect := rect;<br>&nbsp; {<br>&nbsp; rect.Bottom := rect.Bottom -rect.Top;<br>&nbsp; rect.Right := rect.Right - rect.left;<br>&nbsp; rect.top := 0;<br>&nbsp; rect.left := 0;<br>&nbsp; }<br>&nbsp; bmpDC := CreateCompatibleDC(DC);<br>&nbsp; if &nbsp;(itemMenu.itemAction = ODA_DRAWENTIRE) then &nbsp;begin<br>&nbsp; &nbsp; BKcolor := GetSysColor(COLOR_MENU);<br>&nbsp; &nbsp; txtColor := GetSysColor(COLOR_MENUTEXT);<br>&nbsp; end<br>&nbsp; else if itemMenu.itemAction = ODA_SELECT then begin<br>&nbsp; &nbsp; if not BOOL(itemMenu.itemState and ODS_SELECTED) then begin<br>&nbsp; &nbsp; &nbsp; BKcolor := GetSysColor(COLOR_MENU);<br>&nbsp; &nbsp; &nbsp; txtColor := GetSysColor(COLOR_MENUTEXT);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else begin<br>&nbsp; &nbsp; &nbsp; BKcolor := GetSysColor(COLOR_HIGHLIGHT);<br>&nbsp; &nbsp; &nbsp; txtColor := GetSysColor(COLOR_HIGHLIGHTTEXT);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br><br>&nbsp; {<br>&nbsp; rG := rect;<br>&nbsp; Inc(rG.Left, 20);<br>&nbsp; if BKColor = GetSysColor(COLOR_HIGHLIGHT) then begin<br>&nbsp; &nbsp; for i:= 1 to 120 do begin<br>&nbsp; &nbsp; &nbsp; Brush := CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT) +<br>&nbsp; &nbsp; &nbsp; &nbsp; i*(Abs(GetSysColor(COLOR_HIGHLIGHT)-GetSysColor(COLOR_MENU)) div 120));<br>&nbsp; &nbsp; &nbsp; rG.Left := rg.Left +(rect.right-rect.left-20) div 120;<br>&nbsp; &nbsp; &nbsp; rG.right := rG.Left + (rect.right - rect.left - 20) div 120;<br>&nbsp; &nbsp; &nbsp; FillRect(DC,rG,Brush);<br>&nbsp; &nbsp; &nbsp; DeleteObject(Brush);<br>&nbsp; &nbsp; end;<br>&nbsp; end else begin }<br>&nbsp; &nbsp; Brush := CreateSolidBrush(DWORD(BKcolor));<br>&nbsp; &nbsp; FillRect(DC,rect,Brush);<br>&nbsp; &nbsp; DeleteObject(Brush);<br>&nbsp;{ end; }<br>&nbsp; rG := rect;<br>&nbsp; rG.Right := rect.Left +19;<br>&nbsp; Brush := CreateSolidBrush(GetSysColor(COLOR_MENU));<br>&nbsp; FillRect(DC,rG,Brush);<br>&nbsp; DeleteObject(Brush);<br>&nbsp; bmp := LoadBitmap(hInstance,'BITMAP_MENUCLKSET');<br>&nbsp; oldbmp := SelectObject(bmpDC,bmp);<br>&nbsp; Bitblt(DC,rect.left+3,rect.top+4,12,12,bmpDC,0,0,SRCCOPY);<br>&nbsp; SetBkColor(DC,BKcolor);<br>&nbsp; SetTextColor(DC,txtColor);<br>&nbsp; TextOut(DC,rect.left + 22,rect.top+2,'Clock setting',13);<br>&nbsp; if BKColor = GetSysColor(COLOR_HIGHLIGHT) then<br>&nbsp; begin<br>&nbsp; &nbsp; Brush := CreateSolidBrush(RGB(255,0,0));<br>&nbsp; &nbsp; Inc(rect.Left,18);<br>&nbsp; &nbsp; FrameRect(DC,rect,Brush);<br>&nbsp; &nbsp; DeleteObject(Brush);<br>&nbsp; &nbsp; Dec(rect.Left,18);<br>&nbsp; &nbsp; OldRight := rect.Right;<br>&nbsp; &nbsp; rect.Right := rect.Left + 17;<br>&nbsp; &nbsp; DrawEdge(DC,rect,EDGE_RAISED,BF_RECT);<br>&nbsp; &nbsp; rect.Right := OldRight;<br>&nbsp; end;<br>&nbsp; {<br>&nbsp; BitBlt(itemMenu.hDC,orgrect.Left,orgrect.Top,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; orgrect.Right - orgrect.Left,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; orgrect.Bottom - orgrect.top,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DC,rect.Left,rect.top,SRCCOPY);<br>&nbsp; }<br>&nbsp; SelectObject(bmpDC,oldbmp);<br>&nbsp; DeleteDC(bmpDC);<br>&nbsp; {DeleteDC(DC);}<br>&nbsp; {DeleteObject(bufBmp);}<br>&nbsp; DeleteObject(bmp);<br><br>end;<br>
 
当移到word的菜单条时,菜单条前的图标会象speedbutton一样浮起,在delphi3中如何编程实现?
 
用如下代码,画出的菜单变得暗色,为什么?<br>&nbsp; BM:= TBitMap.Create;<br>&nbsp; BM.Width:=16;<br>&nbsp; BM.Height:=16;<br>&nbsp; BM.LoadFromFile(maindir+'/icon/open.bmp');<br>&nbsp; try<br>&nbsp; &nbsp; SetMenuItemBitmaps(MI_File.Handle,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1,<br> MF_BYPOSITION,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BM.BitMap.Handle,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BM.BitMap.Handle);<br><br>&nbsp; finally<br>&nbsp; &nbsp; BM.free;<br>&nbsp; end;}<br>
 
=&gt;huiyugan<br>如何加入包含文件?<br>uses ???
 
accept answer
 
后退
顶部