$IFNDEF TRUE
$DEFINE True 1
$ENDIF
$IFNDEF FALSE
$DEFINE False 0
$ENDIF
$IFNDEF boolean
$DEFINE boolean INTEGER
$ENDIF
CONST ODT_MENU=1
CONST ODS_SELECTED=1
CONST ODS_GRAYED=2
CONST ODS_DISABLED=4
CONST ODS_CHECKED=8
CONST WM_DRAWITEM=&H2B
CONST WM_MEASUREITEM=&H2C
CONST MF_BYCOMMAND=0
CONST MF_BYPOSITION=&H400
CONST MF_OWNERDRAW=&H100
CONST MF_GRAYED=&H1
CONST MF_DISABLED=&H2
CONST MF_STRING=0
CONST MF_BITMAP=4
CONST COLOR_MENU=4
CONST COLOR_MENUTEXT=7
CONST COLOR_HIGHLIGHT=13
CONST COLOR_HIGHLIGHTTEXT=14
CONST COLOR_GRAYTEXT=17
TYPE TMEASUREITEMSTRUCT
CtlType AS LONG
CtlID AS LONG
itemID AS LONG
itemWidth AS LONG
itemHeight AS LONG
itemData AS DWORD
END TYPE
TYPE TDRAWITEMSTRUCT
CtlType AS LONG
CtlID AS LONG
itemID AS LONG
itemAction AS LONG
itemState AS LONG
hwndItem AS LONG
hDC AS LONG
left AS LONG
top AS LONG
right AS LONG
bottom AS LONG
itemData AS DWORD
END TYPE
DIM MeasureItem AS TMEASUREITEMSTRUCT
DIM DrawItem AS TDRAWITEMSTRUCT
DIM Mem AS QMEMORYSTREAM
DECLARE FUNCTION GetSysColor LIB "user32" ALIAS "GetSysColor" (nIndex AS LONG) AS LONG
DECLARE FUNCTION ModifyMenu LIB "USER32" ALIAS "ModifyMenuA" (hMenu AS LONG,uPosition AS LONG,uFlags AS LONG,uIDNewItem AS LONG,lpNewItem AS LONG) AS LONG
TYPE QdrawMenu EXTENDS QOBJECT
PRIVATE:
Text AS QBITMAP
Bitmap AS QBITMAP
Font AS QFONT
image(10000) AS QBITMAP
button(10000) AS boolean
SUB DrawText(cl AS INTEGER)
DIM S AS STRING
DIM I AS INTEGER
DIM X AS INTEGER
DIM Y AS INTEGER
S=VARPTR$(DrawItem.itemData)
X=QDrawMenu.image(DrawItem.itemId).width+9
IF INSTR(S,"&")>0 THEN
QDrawMenu.Font.AddStyles(2)
QDrawMenu.Bitmap.Font=QDrawMenu.Font
Y=((DrawItem.bottom-DrawItem.top)-QDrawMenu.Bitmap.TextHeight(S))\2
QDrawMenu.Font.DelStyles(2)
QDrawMenu.Bitmap.Font=QDrawMenu.Font
ELSE
Y=((DrawItem.bottom-DrawItem.top)-QDrawMenu.Bitmap.TextHeight(S))\2
END IF
I=INSTR(S, "&")
IF I THEN
QDrawMenu.Bitmap.TextOut(DrawItem.left+X,DrawItem.top+Y,LEFT$(S, I-1),cl,-1)
QDrawMenu.Font.AddStyles(2)
QDrawMenu.Bitmap.Font=QDrawMenu.Font
QDrawMenu.Bitmap.TextOut(DrawItem.left+X+QDrawMenu.Bitmap.TextWidth(LEFT$(S, I-1)),DrawItem.top+Y,MID$(S, I+1, 1),cl,-1)
QDrawMenu.Font.DelStyles(2)
QDrawMenu.Bitmap.Font=QDrawMenu.Font
S=S - "&"
QDrawMenu.Bitmap.TextOut(DrawItem.left+X+QDrawMenu.Bitmap.TextWidth(LEFT$(S, I)),DrawItem.top+Y,MID$(S, I+1, LEN(S)),cl,-1)
ELSE
QDrawMenu.Bitmap.TextOut(DrawItem.left+X,DrawItem.top+Y,S,cl,-1)
END IF
END SUB
SUB DrawButton()
DIM width AS INTEGER
DIM height AS INTEGER
width=QDrawMenu.image(DrawItem.itemId).width+2
height=QDrawMenu.image(DrawItem.itemId).height+2
QDrawMenu.Bitmap.Line(DrawItem.left,DrawItem.top,DrawItem.left+width,DrawItem.top,&HFFFFFF)
QDrawMenu.Bitmap.Line (DrawItem.left,DrawItem.top,DrawItem.left,DrawItem.top+height,&HFFFFFF)
QDrawMenu.Bitmap.Line (DrawItem.left,DrawItem.top+height,DrawItem.left+width,DrawItem.top+height,&H808080)
QDrawMenu.Bitmap.Line (DrawItem.left+width,DrawItem.top+height,DrawItem.left+width,DrawItem.top,&H808080)
END SUB
PUBLIC:
SUB MenuProc (hwnd AS LONG,uMsg AS LONG,wParam AS LONG,lParam AS LONG)
IF uMsg=WM_MEASUREITEM THEN
Mem.Position = 0
Mem.MemCopyFrom(lParam, SIZEOF(MeasureItem))
Mem.Position = 0
Mem.ReadUDT(MeasureItem)
IF MeasureItem.CtlType = ODT_MENU THEN
MeasureItem.itemWidth = QDrawMenu.Text.TextWidth(VARPTR$(MeasureItem.itemData)-"&")+QDrawMenu.image(MeasureItem.itemId).width+9
MeasureItem.itemHeight = QDrawMenu.image(MeasureItem.itemId).height+3
Mem.Position = 0
Mem.WriteUDT(MeasureItem)
Mem.Position = 0
Mem.MemCopyTo(lParam, SIZEOF(MeasureItem))
END IF
ELSEIF uMsg=WM_DRAWITEM THEN
Mem.Position = 0
Mem.MemCopyFrom(lParam, SIZEOF(DrawItem))
Mem.Position = 0
Mem.ReadUDT(DrawItem)
IF DrawItem.CtlType = ODT_MENU THEN
QDrawMenu.Bitmap.Handle = DrawItem.hDC
QDrawMenu.image(DrawItem.itemId).transparent=true
IF (ODS_SELECTED AND DrawItem.itemState) <> 0 THEN
IF QDrawMenu.button(DrawItem.itemId) THEN
QDrawMenu.Bitmap.FillRect(DrawItem.left+QDrawMenu.image(DrawItem.itemId).width+4,DrawItem.top,DrawItem.right,DrawItem.bottom,GetSysColor(COLOR_HIGHLIGHT))
ELSE
QDrawMenu.Bitmap.FillRect(DrawItem.left,DrawItem.top,DrawItem.right,DrawItem.bottom,GetSysColor(COLOR_HIGHLIGHT))
END IF
QDrawMenu.Bitmap.Draw (DrawItem.left+1,DrawItem.top+1,QDrawMenu.image(DrawItem.itemId).bmp)
IF (ODS_DISABLED AND DrawItem.itemState)<>0 THEN
QDrawMenu.DrawText(GetSysColor(COLOR_GRAYTEXT))
ELSE
IF QDrawMenu.button(DrawItem.itemId) THEN QDrawMenu.DrawButton
QDrawMenu.DrawText(GetSysColor(COLOR_HIGHLIGHTTEXT))
END IF
ELSEIF(ODS_DISABLED AND DrawItem.itemState)<>0 THEN
QDrawMenu.Bitmap.FillRect(DrawItem.left,DrawItem.top,DrawItem.right,DrawItem.bottom,GetSysColor(COLOR_MENU))
QDrawMenu.Bitmap.Draw (DrawItem.left+1,DrawItem.top+1,QDrawMenu.image(DrawItem.itemId).bmp)
QDrawMenu.DrawText(GetSysColor(COLOR_GRAYTEXT))
ELSE
QDrawMenu.Bitmap.FillRect(DrawItem.left,DrawItem.top,DrawItem.right,DrawItem.bottom,GetSysColor(COLOR_MENU))
QDrawMenu.Bitmap.Draw (DrawItem.left+1,DrawItem.top+1,QDrawMenu.image(DrawItem.itemId).bmp)
QDrawMenu.DrawText(GetSysColor(COLOR_MENUTEXT))
END IF
END IF
END IF
END SUB
SUB AddBitmap(SubMenu AS QMENUITEM,item AS QMENUITEM,picture AS QBITMAP,button AS boolean,backcolor AS LONG)
DIM s AS STRING
DIM flag AS INTEGER
s=item.CAPTION
flag=mf_ByPosition+mf_OwnerDraw
IF item.Enabled=false THEN flag=flag+mf_disabled
ModifyMenu(SubMenu.Handle,item.MenuIndex,flag,Item.Command,VARPTR(s))
QDrawMenu.image(Item.Command).bmp=picture.bmp
QDrawMenu.image(Item.Command).transparentColor=backcolor
IF button THEN QDrawMenu.button(Item.Command)=true
END SUB
SUB DelBitmap(SubMenu AS QMENUITEM,item AS QMENUITEM)
DIM s AS STRING
DIM flag AS INTEGER
s=item.CAPTION
flag=mf_ByPosition+mf_string
IF item.Enabled=false THEN flag=flag+mf_disabled
ModifyMenu(SubMenu.Handle,item.MenuIndex,flag,Item.Command,VARPTR(s))
QDrawMenu.image(Item.Command).transparent=false
END SUB
END TYPE
|
|