Guidance
指路人
g.yi.org
software / rapidq / Examples / QObject / Object / QDrawMenu.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'=======================================================
' Type Objet
' Classe QDrawMenu Version 1.3
'=======================================================
     $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 'Menu
     CONST COLOR_MENUTEXT=7 'Window Text
     CONST COLOR_HIGHLIGHT=13 'Selected item background
     CONST COLOR_HIGHLIGHTTEXT=14 'Selected menu item
     CONST COLOR_GRAYTEXT=17 'Grey text, of zero if dithering is used.

     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

  '=======================================
  ' Méthode affiche le texte de menu
  '=======================================
      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

  '=======================================
  ' Méthode affiche le bouton de menu
  '=======================================
      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:

  '========================================
  ' Procedure winproc pour la gestion menu
  '========================================
      SUB MenuProc (hwnd AS LONG,uMsg AS LONG,wParam AS LONG,lParam AS LONG)

       IF uMsg=WM_MEASUREITEM THEN
        Mem.Position = 0
         '-- lParam& is a pointer to the TMeasureItem structure
        Mem.MemCopyFrom(lParam, SIZEOF(MeasureItem))
        Mem.Position = 0
         '-- After we copy it we have to read the structure
        Mem.ReadUDT(MeasureItem)
        IF MeasureItem.CtlType = ODT_MENU THEN
            '-- There are other types, such as listboxes, etc. that we
            '-- want to avoid.
         MeasureItem.itemWidth = QDrawMenu.Text.TextWidth(VARPTR$(MeasureItem.itemData)-"&")+QDrawMenu.image(MeasureItem.itemId).width+9      '-- Should be big enough to fit
         MeasureItem.itemHeight = QDrawMenu.image(MeasureItem.itemId).height+3     '-- your items.
         Mem.Position = 0
         Mem.WriteUDT(MeasureItem)       '-- Write structure back to memory
         Mem.Position = 0
            '-- Copy this structure back to the original address, so
            '-- changes can take effect
         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
            'QDrawMenu.image(DrawItem.itemId).transparentColor=GetSysColor(COLOR_MENU)
         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


  '==============================================
  ' Méthode ajoute un bitmap a l'item menu
  '==============================================
       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

  '==============================================
  ' Méthode supprime un bitmap de l'item menu
  '==============================================
       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
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2023-2-4  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-02-09 18:23:12