home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch10 / menulook.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  22.5 KB  |  637 lines

  1. VERSION 4.00
  2. Begin VB.Form Menulook 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000005&
  5.    Caption         =   "Menulook demo program"
  6.    ClientHeight    =   4020
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1770
  9.    ClientWidth     =   7365
  10.    BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   8.25
  13.       Charset         =   0
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   4710
  21.    Left            =   1035
  22.    LinkMode        =   1  'Source
  23.    LinkTopic       =   "Form1"
  24.    ScaleHeight     =   4020
  25.    ScaleWidth      =   7365
  26.    Top             =   1140
  27.    Width           =   7485
  28.    Begin VB.ListBox List1 
  29.       Appearance      =   0  'Flat
  30.       Height          =   1785
  31.       Left            =   240
  32.       TabIndex        =   0
  33.       Top             =   2160
  34.       Width           =   6855
  35.    End
  36.    Begin VB.PictureBox Picture2 
  37.       Appearance      =   0  'Flat
  38.       AutoRedraw      =   -1  'True
  39.       BackColor       =   &H80000005&
  40.       ForeColor       =   &H80000008&
  41.       Height          =   375
  42.       Left            =   4440
  43.       ScaleHeight     =   345
  44.       ScaleWidth      =   1305
  45.       TabIndex        =   6
  46.       Top             =   1680
  47.       Width           =   1335
  48.    End
  49.    Begin VB.PictureBox Picture1 
  50.       Appearance      =   0  'Flat
  51.       BackColor       =   &H80000005&
  52.       ForeColor       =   &H80000008&
  53.       Height          =   495
  54.       Left            =   3720
  55.       Picture         =   "MENULOOK.frx":0000
  56.       ScaleHeight     =   465
  57.       ScaleWidth      =   465
  58.       TabIndex        =   5
  59.       Top             =   1560
  60.       Width           =   495
  61.    End
  62.    Begin VB.CommandButton CmdAnalyze 
  63.       Appearance      =   0  'Flat
  64.       BackColor       =   &H80000005&
  65.       Caption         =   "Analyze"
  66.       Height          =   495
  67.       Left            =   6000
  68.       TabIndex        =   1
  69.       Top             =   1140
  70.       Width           =   1215
  71.    End
  72.    Begin VB.CommandButton CmdTrack 
  73.       Appearance      =   0  'Flat
  74.       BackColor       =   &H80000005&
  75.       Caption         =   "TrackPopup"
  76.       Height          =   495
  77.       Left            =   6000
  78.       TabIndex        =   2
  79.       Top             =   600
  80.       Width           =   1215
  81.    End
  82.    Begin VB.CommandButton CmdEntry2Chk 
  83.       Appearance      =   0  'Flat
  84.       BackColor       =   &H80000005&
  85.       Caption         =   "Entry2-Check"
  86.       Height          =   495
  87.       Left            =   4560
  88.       TabIndex        =   8
  89.       Top             =   600
  90.       Width           =   1335
  91.    End
  92.    Begin VB.CommandButton CmdAddBitmap 
  93.       Appearance      =   0  'Flat
  94.       BackColor       =   &H80000005&
  95.       Caption         =   "Add Bitmap"
  96.       Height          =   495
  97.       Left            =   6000
  98.       TabIndex        =   4
  99.       Top             =   60
  100.       Width           =   1215
  101.    End
  102.    Begin VB.CommandButton CmdAddRandom 
  103.       Appearance      =   0  'Flat
  104.       BackColor       =   &H80000005&
  105.       Caption         =   "AddRandom"
  106.       Height          =   495
  107.       Left            =   4560
  108.       TabIndex        =   7
  109.       Top             =   60
  110.       Width           =   1335
  111.    End
  112.    Begin VB.Label Label1 
  113.       Appearance      =   0  'Flat
  114.       BackColor       =   &H80000005&
  115.       BorderStyle     =   1  'Fixed Single
  116.       ForeColor       =   &H80000008&
  117.       Height          =   255
  118.       Left            =   240
  119.       TabIndex        =   3
  120.       Top             =   1680
  121.       Width           =   3255
  122.    End
  123.    Begin VB.Menu MenuTop 
  124.       Caption         =   "Menu1"
  125.       HelpContextID   =   500
  126.       Begin VB.Menu MenuEntry1 
  127.          Caption         =   "Entry1"
  128.       End
  129.       Begin VB.Menu MenuEntry2 
  130.          Caption         =   "Entry2"
  131.       End
  132.       Begin VB.Menu MenuEntry3 
  133.          Caption         =   "-"
  134.       End
  135.       Begin VB.Menu MenuArray1 
  136.          Caption         =   "Array1"
  137.          Index           =   0
  138.       End
  139.       Begin VB.Menu MenuArray1 
  140.          Caption         =   "Array1B"
  141.          Index           =   1
  142.       End
  143.       Begin VB.Menu MenuSubMenu1 
  144.          Caption         =   "SubMenu1"
  145.          Begin VB.Menu MenuSub1Entry1 
  146.             Caption         =   "Sub1Entry1"
  147.          End
  148.          Begin VB.Menu MenuSub1Entry2 
  149.             Caption         =   "Sub1Entry2"
  150.          End
  151.       End
  152.    End
  153.    Begin VB.Menu MenuFloat 
  154.       Caption         =   "Floating"
  155.       Begin VB.Menu MenuFloat1 
  156.          Caption         =   "Float1"
  157.          Index           =   0
  158.       End
  159.       Begin VB.Menu MenuFloat1 
  160.          Caption         =   "Float2"
  161.          Index           =   1
  162.       End
  163.    End
  164.    Begin VB.Menu MenuRandomTop 
  165.       Caption         =   "Random"
  166.       Begin VB.Menu MenuArt 
  167.          Caption         =   "Art1"
  168.          Index           =   0
  169.       End
  170.    End
  171. Attribute VB_Name = "Menulook"
  172. Attribute VB_Creatable = False
  173. Attribute VB_Exposed = False
  174. Option Explicit
  175. ' Copyright 
  176.  1997 by Desaware Inc. All Rights Reserved.
  177. Dim IsWindows95 As Boolean
  178. ' This command adds the bitmap that is in the Picture1
  179. ' control to the Floating menu.
  180. Private Sub CmdAddBitmap_Click()
  181. #If Win32 Then
  182.     Dim topmenuhnd&
  183.     Dim floatmenu&
  184.     Dim menuid&
  185. #Else
  186.     Dim topmenuhnd%
  187.     Dim floatmenu%
  188.     Dim menuid%
  189. #End If
  190.     Dim di&
  191.     ' Get a handle to the top level menu
  192.     topmenuhnd = GetMenu(Menulook.hwnd)
  193.     ' And get a handle to the Floating popup menu.
  194.     floatmenu = GetSubMenu(topmenuhnd, 1)
  195.     ' If 3rd (bitmap) entry is already loaded, exit now
  196.     ' (we only load the bitmap once)
  197.     If GetMenuItemCount(floatmenu) >= 3 Then Exit Sub
  198.     ' First, add a menu entry under VB - this provides us
  199.     ' with a menu entry that can be replaced with a bitmap,
  200.     ' but whose menu ID will be the same (so it will work
  201.     ' properly
  202.     Load MenuFloat1(2)
  203.     ' Now get the ID of that entry
  204.     menuid = GetMenuItemID(floatmenu, 2)
  205.     If FloatBitmap = 0 Then FloatBitmap = CopyPictureImage(picture1)
  206.     ' And replace it with a bitmap.
  207.     di = ModifyMenuBynum(floatmenu, 2, MF_BITMAP Or MF_BYPOSITION, menuid, FloatBitmap)
  208. End Sub
  209. ' This command creates a random bitmap and loads it into
  210. ' the Random popup menu.
  211. Private Sub CmdAddRandom_Click()
  212. #If Win32 Then
  213.     Dim topmenuhnd&
  214.     Dim floatmenu&
  215.     Dim menuid&
  216.     Dim newmenupos&
  217.     Dim newbm&
  218. #Else
  219.     Dim topmenuhnd%
  220.     Dim floatmenu%
  221.     Dim menuid%
  222.     Dim newmenupos%
  223.     Dim newbm%
  224. #End If
  225.     Dim pw!, ph!
  226.     Dim x%, di&
  227.     ' First get the width and height of the picture2 control
  228.     pw! = Picture2.ScaleWidth
  229.     ph! = Picture2.ScaleHeight
  230.     ' Get a handle to the Random popup menu
  231.     topmenuhnd = GetMenu(Menulook.hwnd)
  232.     floatmenu = GetSubMenu(topmenuhnd, 2)
  233.     ' Find out how many menu items are already in the popup
  234.     newmenupos = GetMenuItemCount(floatmenu)
  235.     ' Load a VB menu entry at that position
  236.     Load MenuArt(newmenupos)
  237.     ' And get the MenuID for that entry
  238.     menuid = GetMenuItemID(floatmenu, newmenupos)
  239.     ' Draw some stuff on picture2
  240.     Picture2.Cls
  241.     For x% = 0 To 5 ' Random rectangles
  242.         Picture2.Line (Rnd * pw!, Rnd * ph!)-(Rnd * pw!, Rnd * ph!), QBColor(CInt(Rnd * 15)), B
  243.     Next x%
  244.     ' Get a bitmap that is a copy of the picture2 control
  245.     newbm = CopyPictureImage(Picture2)
  246.     For x% = 0 To 32
  247.         If BMHandles(x%) = 0 Then Exit For
  248.     Next x%
  249.     If x% = 32 Then ' No room to store the bitmap handle
  250.         di = DeleteObject(newbm)
  251.         Exit Sub
  252.     End If
  253.     BMHandles(x%) = newbm
  254.     ' And place that bitmap in the menu
  255.     di = ModifyMenuBynum(floatmenu, newmenupos, MF_BITMAP Or MF_BYPOSITION, menuid, newbm)
  256. End Sub
  257. '   Get the form's menu and analyze it.
  258. Private Sub CmdAnalyze_Click()
  259. #If Win32 Then
  260.     Dim menuhnd&
  261. #Else
  262.     Dim menuhnd%
  263. #End If
  264.     ' Clear the listbox
  265.     'dl& = SendMessage(List1.hwnd, LB_RESETCONTENT, 0, 0&)
  266.     List1.Clear
  267.     ' Get a handle to the top level menu for this window
  268.     menuhnd = GetMenu(Menulook.hwnd)
  269.     ' And analyze it
  270.     ViewMenu menuhnd
  271. End Sub
  272. ' Create a box checkmark bitmap for the Entry2 menu
  273. Private Sub CmdEntry2Chk_Click()
  274. #If Win32 Then
  275.     Dim topmenuhnd&
  276.     Dim floatmenu&
  277.     Dim NewCheck&
  278. #Else
  279.     Dim NewCheck%
  280.     Dim topmenuhnd%
  281.     Dim floatmenu%
  282. #End If
  283.     Dim oldbkcolor&
  284.     Dim di&
  285.     ' Get the new checkmark bitmap
  286.     NewCheck = GetNewCheck()
  287.     ' Get a handle to the top level menu
  288.     topmenuhnd = GetMenu(Menulook.hwnd)
  289.     ' Get a handle to the first popup
  290.     floatmenu = GetSubMenu(topmenuhnd, 0)
  291.     ' And set the new check bitmap for the first (entry1) menu item
  292.     di = SetMenuItemBitmaps(floatmenu, 1, MF_BYPOSITION, 0, NewCheck)
  293.     ' Check the entry
  294.     MenuEntry2.Checked = -1
  295.     ' Remind the user to look at it.
  296.     MsgBox "Look at the Menu1 - Entry2 menu"
  297. End Sub
  298. '   Hides the Floating menu entry in the caption,
  299. '   and turns it into a tracked popup menu
  300. Private Sub CmdTrack_Click()
  301. #If Win32 Then  ' Port to correct handle type
  302.     Dim topmenuhnd&
  303.     Dim floatmenu&
  304. #Else
  305.     Dim topmenuhnd%
  306.     Dim floatmenu%
  307. #End If
  308.     Dim oldcap$, di&
  309.     Dim pt As POINTAPI
  310.     ' Get a handle to the popup menu
  311.     topmenuhnd = GetMenu(Menulook.hwnd)
  312.     floatmenu = GetSubMenu(topmenuhnd, 1)
  313.     ' Hide the menu entry by clearing the string
  314.     ' temporarily. Note, don't make it invisible or the
  315.     ' menu will go away!
  316.     oldcap$ = MenuFloat.Caption
  317.     MenuFloat.Caption = ""
  318.     ' Find where the mouse cursor is and place the
  319.     ' popup at that point
  320.     GetCursorPos pt
  321.     di = TrackPopupMenuBynum(floatmenu, TPM_CENTERALIGN, pt.x, pt.y, 0, Menulook.hwnd, 0&)
  322.     ' Restore the original popup name
  323.     MenuFloat.Caption = oldcap$
  324. End Sub
  325. '   This function makes a copy of the Image property bitmap
  326. '   and returns a handle to that bitmap
  327. Private Function CopyPictureImage(SourceImage As PictureBox) As Long
  328.     Dim bm As BITMAP
  329.     #If Win32 Then
  330.     Dim newbm&
  331.     Dim tdc&, oldbm&
  332.     #Else
  333.     Dim newbm%
  334.     Dim tdc%, oldbm%
  335.     #End If
  336.     Dim di&
  337.     ' First get the information about the image bitmap
  338.     di = GetObjectAPI(SourceImage.Image, Len(bm), bm)
  339.     bm.bmBits = 0
  340.     ' Create a new bitmap with the same structure and size
  341.     ' of the image bitmap
  342.     newbm = CreateBitmapIndirect(bm)
  343.     ' Create a temporary memory device context to use
  344.     tdc = CreateCompatibleDC(SourceImage.hdc)
  345.     ' Select in the newly created bitmap
  346.     oldbm = SelectObject(tdc, newbm)
  347.     ' Now copy the bitmap from the persistant bitmap in
  348.     ' picture 2 (note that picture2 has AutoRedraw set TRUE
  349.     di = BitBlt(tdc, 0, 0, bm.bmWidth, bm.bmHeight, SourceImage.hdc, 0, 0, SRCCOPY)
  350.     ' Select out the bitmap and delete the memory DC
  351.     oldbm = SelectObject(tdc, oldbm)
  352.     di = DeleteDC(tdc)
  353.     ' And return the new bitmap
  354.     CopyPictureImage = newbm
  355. End Function
  356. ' Clicking anywhere on the form triggers the CmdTrack command
  357. ' button.
  358. Private Sub Form_Load()
  359. #If Win32 Then
  360.     Dim os As OSVERSIONINFO
  361.     Dim di&
  362.     Print "Click anywhere on the form to"
  363.     Print "bring up a tracked popup menu"
  364.     Randomize
  365.     os.dwOSVersionInfoSize = Len(os)
  366.     di = GetVersionEx(os)
  367.     If os.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then IsWindows95 = True
  368. #End If
  369.     ' We never let IsWindows95 get set to True in 16 bits, because
  370.     ' it is only used for Win32 specific APIs
  371. End Sub
  372. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  373.     ' Clicking anywhere on the form triggers the CmdTrack button
  374.     CmdTrack.value = -1
  375. End Sub
  376. Private Sub Form_Unload(Cancel As Integer)
  377.     Dim x%, di&
  378.     ' If a new check bitmap was set, we need to destroy it
  379.     ' otherwise the resources used by the bitmap will not
  380.     ' be freed.
  381.     If NewCheck <> 0 Then
  382.         di = DeleteObject(NewCheck)
  383.     End If
  384.     ' The same applies to the random menu bitmaps
  385.     For x% = 0 To 32
  386.         If BMHandles(x%) <> 0 Then
  387.             di = DeleteObject(BMHandles(x%))
  388.         End If
  389.     Next x%
  390.     If FloatBitmap <> 0 Then
  391.         Call DeleteObject(FloatBitmap)
  392.     End If
  393. End Sub
  394. '   Gets a string containing a description of the flags
  395. '   set for this menu item.
  396. Private Function GetFlagString$(menuflags%)
  397.     Dim f$
  398.     If (menuflags% And MF_CHECKED) <> 0 Then
  399.         f$ = f$ + "Checked "
  400.     Else
  401.         f$ = f$ + "Unchecked "
  402.     End If
  403.     If (menuflags% And MF_DISABLED) <> 0 Then
  404.         f$ = f$ + "Disabled "
  405.     Else
  406.         f$ = f$ + "Enabled "
  407.     End If
  408.     If (menuflags% And MF_GRAYED) <> 0 Then f$ = f$ + "Grayed "
  409.     If (menuflags% And MF_BITMAP) <> 0 Then f$ = f$ + "Bitmap "
  410.     If (menuflags% And MF_MENUBARBREAK) <> 0 Then f$ = f$ + "Bar-break "
  411.     If (menuflags% And MF_MENUBREAK) <> 0 Then f$ = f$ + "Break "
  412.     If (menuflags% And MF_SEPARATOR) <> 0 Then f$ = f$ + "Seperator "
  413.     GetFlagString$ = f$
  414. End Function
  415. ' Create a custom bitmap checkmark and return a
  416. ' handle to that bitmap.
  417. Private Function GetNewCheck&()
  418.     Dim bm As BITMAP
  419.     Dim pt As POINTS
  420.     #If Win32 Then
  421.     Dim newbm&
  422.     Dim tdc&, oldbm&
  423.     Dim br&, oldbrush&
  424.     #Else
  425.     Dim newbm%
  426.     Dim tdc%, oldbm%
  427.     Dim br%, oldbrush%
  428.     #End If
  429.     Dim markdims&
  430.     Dim di&
  431.     ' Find out how big the checkmark should be.
  432.     markdims& = GetMenuCheckMarkDimensions()
  433.     agDWORDto2Integers markdims&, pt.x, pt.y
  434.     ' And create a magenta brush (the check mark will be
  435.     ' a magenta filled rectangle
  436.     br = CreateSolidBrush(QBColor(5))
  437.     Picture2.Cls
  438.     oldbrush = SelectObject(Picture2.hdc, br)
  439.     ' Draw the rectangle.
  440.     di = Rectangle(Picture2.hdc, 2, 2, pt.x - 2, pt.y - 2)
  441.     di = SelectObject(Picture2.hdc, oldbrush)
  442.     di = DeleteObject(br) ' Dump the brush.
  443.     ' Create a compatible bitmap of the right size
  444.     ' was: di% = GetObjectAPI(Picture2.Image, 14, agGetAddressForObject&(bm))
  445.     di = GetObjectAPI(Picture2.Image, Len(bm), bm)
  446.     bm.bmBits = 0
  447.     bm.bmWidth = pt.x
  448.     bm.bmHeight = pt.y
  449.     newbm = CreateBitmapIndirect(bm)
  450.     ' And create a memory device context to use
  451.     tdc = CreateCompatibleDC(Picture2.hdc)
  452.     oldbm = SelectObject(tdc, newbm)
  453.     ' Copy in the new check mark
  454.     di = BitBlt(tdc, 0, 0, pt.x, pt.y, Picture2.hdc, 0, 0, SRCCOPY)
  455.     oldbm = SelectObject(tdc, oldbm)
  456.     di = DeleteDC(tdc)
  457.     GetNewCheck = newbm
  458. End Function
  459. ' Let the system know this menu has been clicked
  460. Private Sub MenuArray1_Click(Index As Integer)
  461.     Label1.Caption = "Array1(" + Str$(Index) + ") selected."
  462. End Sub
  463. ' Let the system know this menu has been clicked'
  464. Private Sub MenuArt_Click(Index As Integer)
  465.     Label1.Caption = "Menu Random Art (" + Str$(Index) + ") selected."
  466. End Sub
  467. ' Let the system know this menu has been clicked'
  468. Private Sub MenuEntry1_Click()
  469.     ' Check or uncheck the menu each time it is clicked
  470.     Label1.Caption = "Entry1 selected."
  471.     MenuEntry1.Checked = Not MenuEntry1.Checked
  472. End Sub
  473. ' Let the system know this menu has been clicked'
  474. Private Sub MenuEntry2_Click()
  475.     ' Check or uncheck the menu each time it is clicked
  476.     If MenuEntry2.Checked Then MenuEntry2.Checked = 0 Else MenuEntry2.Checked = -1
  477.     Label1.Caption = "Entry2 selected."
  478. End Sub
  479. ' Let the system know this menu has been clicked'
  480. Private Sub MenuFloat_Click()
  481.     Label1.Caption = "Floating selected."
  482. End Sub
  483. ' Let the system know this menu has been clicked'
  484. Private Sub MenuFloat1_Click(Index As Integer)
  485.     Label1.Caption = "Float1(" + Str$(Index) + ") selected."
  486. End Sub
  487. ' Let the system know this menu has been clicked'
  488. Private Sub MenuRandomTop_Click()
  489.     Label1.Caption = "Menu Random selected."
  490. End Sub
  491. ' Let the system know this menu has been clicked'
  492. Private Sub MenuSub1Entry1_Click()
  493.     Label1.Caption = "Sub1Entry1 selected."
  494. End Sub
  495. ' Let the system know this menu has been clicked'
  496. Private Sub MenuSub1Entry2_Click()
  497.     Label1.Caption = "Sub1Entry2 selected."
  498. End Sub
  499. ' Let the system know this menu has been clicked'
  500. Private Sub MenuSubMenu1_Click()
  501.     Label1.Caption = "SubMenu1 selected."
  502. End Sub
  503. ' Let the system know this menu has been clicked'
  504. Private Sub MenuTop_Click()
  505.     Label1.Caption = "MenuTop selected."
  506. End Sub
  507. '   This function loads into list1 an analysis of the
  508. '   specified menu
  509. Private Sub ViewMenu(ByVal menuhnd&)
  510.     Dim menulen&
  511.     Dim di&
  512. #If Win32 Then
  513.     Dim thismenu&
  514.     Dim menuid&
  515.     Dim currentpopup&
  516.     Dim menuinfo As MENUITEMINFO
  517. #Else
  518.     Dim thismenu%
  519.     Dim menuid%
  520.     Dim currentpopup%
  521. #End If
  522.     Dim db%
  523.     Dim menuflags%
  524.     Dim flagstring$
  525.     Dim menustring(128) As Byte
  526.     Dim menustring2 As String * 128
  527.     Dim context&
  528.     ' This routine can analyze up to 32 popup sub-menus
  529.     ' for each menu. We keep track of them here so that
  530.     ' we can recursively analyze the popups after we
  531.     ' analyze the main menu.
  532.     Dim trackpopups&(32)
  533.     currentpopup = 0
  534.     List1.AddItem "Analysis of Menu handle# " & Hex$(menuhnd)
  535.     ' Find out how many entries are in the menu.
  536.     menulen = GetMenuItemCount(menuhnd)
  537.     List1.AddItem "# of entries = " & Str$(menulen)
  538.     #If Win32 Then
  539.     context& = GetMenuContextHelpId(menuhnd)
  540.     If context& > 0 Then List1.AddItem "Help Context ID = " & Str$(context&)
  541.     #End If
  542.     If IsWindows95 Then
  543.         #If Win32 Then
  544.             menuinfo.cbSize = Len(menuinfo)
  545.             
  546.             For thismenu = 0 To menulen - 1
  547.                 ' cch field is reset each time
  548.                 menuinfo.cch = 127
  549.                 menuinfo.dwTypeData = agGetAddressForObject(menustring(0))
  550.                 menuinfo.fMask = MIIM_DATA Or MIIM_ID Or MIIM_STATE Or MIIM_SUBMENU Or MIIM_TYPE Or MIIM_CHECKMARKS
  551.                 
  552.                 ' Get the ID for this menu
  553.                 ' It's a command ID, -1 for a popup, 0 for a seperator
  554.                 di = GetMenuItemInfo(menuhnd, thismenu, True, menuinfo)
  555.                 If di = 0 Then
  556.                     List1.AddItem "Entry #" + Str$(thismenu) + " is unaccessable via GetMenuItemInfo"
  557.                 Else
  558.                     With menuinfo
  559.                         ' Obtain all information about a menu
  560.                         If .hSubMenu <> 0 Then
  561.                             ' Save it in the list of popups
  562.                             trackpopups&(currentpopup) = thismenu
  563.                             currentpopup = currentpopup + 1
  564.                             ' Why do we use left$?
  565.                             List1.AddItem "Entry #" + Str$(thismenu) + " is a submenu. Handle = " + Hex$(.hSubMenu) + " is " + Left$(StrConv(menustring, vbUnicode), .cch)
  566.                             List1.AddItem "Flags: " + GetFlagStringNew$(.fType, .fState)
  567.                         Else
  568.                             If .fType = MFT_STRING Then
  569.                                 List1.AddItem "Entry #" + Str$(thismenu) + " is a string = " + Left$(StrConv(menustring, vbUnicode), .cch)
  570.                                 List1.AddItem "Flags: " + GetFlagStringNew$(.fType, .fState)
  571.                             Else
  572.                                 ' Menu type is a bitmap, or otherwise not supported by this application
  573.                                 List1.AddItem "Entry #" & Str$(thismenu) & " has flags: " + GetFlagStringNew$(.fType, .fState)
  574.                             End If
  575.                             
  576.                         End If
  577.                         
  578.                     End With
  579.                 End If
  580.             Next thismenu
  581.         #End If
  582.     Else
  583.         For thismenu = 0 To menulen - 1
  584.             ' Get the ID for this menu
  585.             ' It's a command ID, -1 for a popup, 0 for a seperator
  586.             menuid = GetMenuItemID(menuhnd, thismenu)
  587.             Select Case menuid
  588.                 Case 0  ' It's a seperator
  589.                     List1.AddItem "Entry #" + Str$(thismenu) + "is a seperator"
  590.                 Case -1 ' It's a popup menu
  591.                     ' Save it in the list of popups
  592.                     trackpopups&(currentpopup) = thismenu
  593.                     currentpopup = currentpopup + 1
  594.                     ' And report that it's here
  595.                     db = GetMenuString(menuhnd, thismenu, menustring2, 127, MF_BYPOSITION)
  596.                     menuflags = GetMenuState(menuhnd, thismenu, MF_BYPOSITION)
  597.                     List1.AddItem "Entry #" + Str$(thismenu) + " is a submenu. Handle = " + Hex$(GetSubMenu(menuhnd, thismenu)) + " is " + Left$(menustring2, db)
  598.                     List1.AddItem "Flags: " + GetFlagString$(menuflags)
  599.                     
  600.                 Case Else ' A regular entry
  601.                     db = GetMenuString(menuhnd, menuid, menustring2, 127, MF_BYCOMMAND)
  602.                     List1.AddItem "Entry #" + Str$(thismenu) + " cmd = " + Str$(menuid) + " is " + Left$(menustring2, db)
  603.                     menuflags = GetMenuState(menuhnd, menuid, MF_BYCOMMAND)
  604.                     List1.AddItem "Flags: " + GetFlagString$(menuflags)
  605.             End Select
  606.         Next thismenu
  607.     End If
  608.     If currentpopup > 0 Then ' At least one popup was found
  609.         List1.AddItem "Sub menus:"
  610.         For thismenu = 0 To currentpopup - 1
  611.             menuid = trackpopups&(thismenu)
  612.             ' Recursively analyze the popup menu.
  613.             ViewMenu GetSubMenu(menuhnd, menuid)
  614.         Next thismenu
  615.     End If
  616. End Sub
  617. Public Function GetFlagStringNew$(ByVal fType&, ByVal fState&)
  618.     Dim f$
  619.     If (fState And MFS_CHECKED) <> 0 Then
  620.         f$ = f$ + "Checked "
  621.     Else
  622.         f$ = f$ + "Unchecked "
  623.     End If
  624.     If (fState And MFS_DISABLED) <> 0 Then
  625.         f$ = f$ + "Disabled "
  626.     Else
  627.         f$ = f$ + "Enabled "
  628.     End If
  629.     If (fState And MFS_GRAYED) <> 0 Then f$ = f$ + "Grayed "
  630.     If (fType And MFT_BITMAP) <> 0 Then f$ = f$ + "Bitmap "
  631.     If (fType And MFT_MENUBARBREAK) <> 0 Then f$ = f$ + "Bar-break "
  632.     If (fType And MFT_RADIOCHECK) <> 0 Then f$ = f$ + "Radio "
  633.     If (fType And MFT_MENUBREAK) <> 0 Then f$ = f$ + "Break "
  634.     If (fType And MFT_SEPARATOR) <> 0 Then f$ = f$ + "Seperator "
  635.     GetFlagStringNew$ = f$
  636. End Function
  637.