Documentation by John Kelly  QMENUex

QMenuEx Component

INCLUDED IN RAPIDQ2.INC
QMenuEx adds bitmaps, descriptions, and fonts to an QMENUITEM. It is not a stand-alone component and must be declared after you define your QMainMenu and QMenuItems. You can add bitmaps or Icons with $RESOURCE handles or by filename. You must be sure to follow the programming example below. Code is based on the QMenu and QDrawMenu by D. Glodt and Jordi Ramos.
 See limitations.

QMenuEx Properties
FieldTypeR/WDefault




BackColorLONGRWclMenu
Set the color of the Menu item background
CountINTEGERR
Count returns the number of images used
DisabledColorLONGRWsystem default
Color of a disabled Menu Item
ForeColorINTEGERRsystem default
Set the color of the Menu item text
HighLightColorLONGRsystem default
Color when the mouse highlights Menu Item
HighLightTextColorLONGRTrue
FontQFONTR/W
Use the SetFontSize Method for size
FontSizeINTEGERRW
You will need to set ownerDraw properties to all QMenuItems in order to work consistently
HeightINTEGERR/WautoW
OutlineINTEGERRWFalse
specifies an outline drawn around the Menu image
TransparentINTEGERRWTrue
Specifies whether the image on the menu contains transparent or non-transparent images.
TransparentColorINTEGERRW 0
The color in the image that will be transparent
WidthINTEGERRW


QMenuEx Methods
MethodTypeParams



AddBMPFile  SUB (MenuItem AS QMENUITEM, FileName$)1
Add BMP file  to the menu item 
AddICOFile   SUB (MenuItem AS QMENUITEM, FileName$)1
Add icon  resource handle, must be followed by an AddDescription command
AddDescription SUB (MenuItem AS QMENUITEM,  descript AS STRING)1
Give a sub-caption to each QMenuItem, ie, update this string in a status bar in a OnMouseHover event
No bitmap will be assigned.
DelBitmap SUB (Menuitem as Qmenuitem)1
delete an image from the sub-menuitem of the Parent menu 
MenuModifySUB (MenuItem AS QMENUITEM,   Image AS QBITMAP,  description AS STRING)4
Add Subitems to MenuItem
Parent SUB (TheMenuParent AS QMENUITEM)1
Images can only be assigned to sub-menuitems. Use this to specify the Parent menu
InitSUB  (Form AS QFORM)1
The parent form. with the menus. You MUST specify the QFORM
CloseVOID         stop drawing bitmaps and free up memory0

QMenuEx Events
EventTypeOccurs when...ParamsSupport





OnMouseHoverSUB (Xpos&, Ypos&, Descript AS STRING)Mouse over MenuItem  when High lighted. String is the Menu Item Description3W
REMARKS
there are 2 global structures with this component:
gRQ2_MeasureItem   AS TMEASUREITEMSTRUCT
gRQ2_DrawItem        AS TDRAWITEMSTRUCT


QMenuEx Example
$INCLUDE "RapidQ2.inc"

$RESOURCE New_bmp as "\rapidQ\icon\New.bmp"
$RESOURCE Open_bmp as "\rapidQ\icon\Open.bmp"
$RESOURCE Save_bmp as "\rapidQ\icon\Save.bmp"
$RESOURCE Exit_bmp as "\rapidQ\icon\Exit.bmp"
$RESOURCE Cut_bmp as "\rapidQ\icon\Cut.bmp"
$RESOURCE Copy_bmp as "\rapidQ\icon\Copy.bmp"
$RESOURCE Paste_bmp as "\rapidQ\icon\Paste.bmp"
$RESOURCE Empty_bmp as "\rapidQ\icon\Empty.bmp"

Declare Sub FormClose (Action As integer)
Declare Sub NewItemClick (Sender As QMENUITEM)
Declare Sub ExitItemClick (Sender As QMENUITEM)
Declare SUB MnuShowDescription(Xpos AS LONG, Ypos AS LONG, Descript AS STRING)
CREATE Form2 As QFORM
    Caption = "New Form"
    Width = 200
    Height = 100
    Center
END CREATE


CREATE Form As QForm
   Width = 400
   Center
   Caption = "Ownerdraw Menus"
   onClose = FormClose
   
   CREATE MainMenu As QMainMenu
      CREATE FileMenu As QMenuItem
         Caption = "&File"
         CREATE NewItem As QMenuItem
            Caption = "&New"
            Hint = "New"
            onclick = NewItemClick
         END CREATE
         CREATE OpenItem As QMenuItem
            Caption = "&Open..."
            Hint = "Open"
            ShortCut = "Ctrl+O"
         END CREATE
         CREATE SaveItem As QMenuItem
            Caption = "&Save"
            Hint = "Save"
         END CREATE
         CREATE SaveASItem As QMenuItem
            Caption = "Sa&ve as..."
            Hint = "Save as"
         END CREATE
         CREATE BreakItem As QMenuItem
            Caption = "-"
         END CREATE
         CREATE ExitItem As QMenuItem
            Caption = "E&xit"
            onclick = ExitItemClick
         END CREATE
      END CREATE
      CREATE EditMenu As QMenuItem
         Caption = "&Edit"
         CREATE CutItem As QMenuItem
             Caption = "&Cut           Ctrl+X"
             ShortCut = "Ctrl+X"
         END CREATE
         CREATE CopyItem As QMenuItem
             Caption = "&Copy        Ctrl+C"
         END CREATE
         CREATE PasteItem As QMenuItem
             Caption = "&Paste       Ctrl+V"
             Checked = true   'no effect with bmp
         END CREATE
      END CREATE
      CREATE SearchMenu As QMenuItem
         Caption = "&Search"
         CREATE FindItem As QMenuItem
             Caption = "&Find"
         END CREATE
         CREATE ReplaceItem As QMenuItem
             Caption = "&Replace"
         END CREATE
       END CREATE
    END CREATE
    
    CREATE StatusBar As QStatusBar
       AddPanels "QMenuEx Demo",""
       panel(0).Width = 170
    END CREATE

END CREATE

DIM pic AS QIMAGE
DIM MenuX as QMenuEx
WITH MenuX
.Transparent = False            'default is True
.Parent(FileMenu)
      pic.bmphandle= New_bmp
      .MenuModify NewItem, pic, "Creates a new document"
      pic.BMPhandle= Open_bmp
      .MenuModify OpenItem, pic, "Opens a Document"
      pic.BMPhandle= Save_bmp
      .MenuModify SaveItem, pic, "Save Document"
      .MenuModify SaveAsItem, pic, "Save Document as"
      pic.BMPhandle= Exit_bmp
      .MenuModify  ExitItem, pic, "Exits Program"
.Parent(EditMenu)
      pic.BMPhandle= Cut_bmp
      .MenuModify CutItem, pic, "Cuts Selection to Clipboard"
      pic.BMPhandle= Copy_bmp
      .MenuModify CopyItem, pic, "Copies Selection to Clipboard"
      pic.BMPhandle= Paste_bmp
      .MenuModify PasteItem, pic, "Pastes Contents of Clipboard"
.Parent (SearchMenu)
      .AddDescription FindItem, "Search for a text string"
      .AddDescription ReplaceItem, "Replace a character string by another"
      .OnMouseHover = MnuShowDescription
    ' ** Add effects, best if all items have a bmp assigned
'     .FontSize = 12 
'     .BackColor = RGB(32, 32, 255)
'     .ForeColor = RGB(255, 255, 32)
         'default is to draw transparently, use this for no transparency
     .Init Form                  'must do this to work
END WITH
Form.ShowModal


SUB MnuShowDescription(Xpos AS LONG, Ypos AS LONG, Descript AS STRING)
   StatusBar.Panel(1).Caption = Descript
END SUB


SUB NewItemClick (Sender AS QMENUITEM)
   Form2.ShowModal
end Sub 

SUB ExitItemClick (Sender AS QMENUITEM)
   Form.close
end Sub 

sub FormClose (Action as integer)
   MenuX.Close
end Sub

Prev Component Contents Next Component