home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PROG / CLAK20.ZIP / SAMPLE.ZIP / GENERAPP.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1993-07-10  |  14.3 KB  |  373 lines

  1. VERSION 2.00
  2. Begin Form Clacker_Form 
  3.    Caption         =   "Clacker Test"
  4.    ClientHeight    =   4860
  5.    ClientLeft      =   1215
  6.    ClientTop       =   1830
  7.    ClientWidth     =   5055
  8.    Height          =   5550
  9.    Left            =   1155
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4860
  12.    ScaleWidth      =   5055
  13.    Top             =   1200
  14.    Width           =   5175
  15.    Begin Clack Clacker1 
  16.       hwndForm        =   0
  17.       Left            =   840
  18.       Top             =   1200
  19.    End
  20.    Begin CommandButton BTN_Exit 
  21.       Caption         =   "Exit"
  22.       Height          =   375
  23.       Left            =   3720
  24.       TabIndex        =   4
  25.       Top             =   240
  26.       Width           =   1215
  27.    End
  28.    Begin TextBox Text2 
  29.       Height          =   2655
  30.       Left            =   120
  31.       MultiLine       =   -1  'True
  32.       ScrollBars      =   3  'Both
  33.       TabIndex        =   3
  34.       Text            =   "Text2"
  35.       Top             =   840
  36.       Width           =   4815
  37.    End
  38.    Begin CommandButton Btn_UnHook 
  39.       Caption         =   "UnHook"
  40.       Height          =   375
  41.       Left            =   1080
  42.       TabIndex        =   1
  43.       Top             =   240
  44.       Width           =   1215
  45.    End
  46.    Begin CommandButton Btn_Hook 
  47.       Caption         =   "Hook"
  48.       Height          =   375
  49.       Left            =   2400
  50.       TabIndex        =   2
  51.       Top             =   240
  52.       Width           =   1215
  53.    End
  54.    Begin TextBox TXT_MID 
  55.       Height          =   975
  56.       Left            =   120
  57.       MultiLine       =   -1  'True
  58.       TabIndex        =   0
  59.       Text            =   "Menu ID, menu not hooked"
  60.       Top             =   3720
  61.       Width           =   4815
  62.    End
  63.    Begin Menu nmu_File 
  64.       Caption         =   "&File"
  65.       Begin Menu mnu_Exit 
  66.          Caption         =   "&Exit"
  67.       End
  68.    End
  69.    Begin Menu mnu_Edit 
  70.       Caption         =   "&Edit"
  71.       Begin Menu mnu_Cut 
  72.          Caption         =   "Cu&t"
  73.       End
  74.       Begin Menu mnu_Copy 
  75.          Caption         =   "&Copy"
  76.       End
  77.       Begin Menu mnu_Paste 
  78.          Caption         =   "&Paste"
  79.       End
  80.       Begin Menu mnu_submenu 
  81.          Caption         =   "SubMenu"
  82.          Begin Menu mnu_submenu1 
  83.             Caption         =   "SubMenu 1"
  84.          End
  85.          Begin Menu mnu_submenu2 
  86.             Caption         =   "SubMenu 2"
  87.          End
  88.       End
  89.    End
  90. Option Explicit
  91. Const CLACKER_START = 1
  92. Const CLACKER_STOP = 2
  93. Declare Function GetParent Lib "User" (ByVal hWnd As Integer) As Integer
  94. Dim MenuStatus() As HelpTextType
  95. Dim taContextHelp(1 To 25) As HelpTextType
  96. Sub BTN_Exit_Click ()
  97.     mnu_Exit_Click
  98. End Sub
  99. Sub Btn_Hook_Click ()
  100. Dim Msg As String
  101. Dim hWndParent As Integer
  102.     'Msg = "hWnd HEX = " + Hex$(hWnd) + "    DECIMAL = " + Str$(hWnd) + Chr$(10) + Chr(13)
  103.     'hWndParent = GetParent(hWnd)
  104.     'Msg = Msg + "Parent of Me.hWnd HEX = " + Hex$(hWndParent) + "    DECIMAL = " + Str$(hWndParent)
  105.     'MsgBox Msg
  106.     Clacker1.hwndForm = Me.hWnd
  107.     Clacker1.Action = CLACKER_START
  108.     TXT_MID.Text = "Menu ID, menu hooked"
  109. End Sub
  110. Sub Btn_UnHook_Click ()
  111.     Clacker1.hwndForm = Me.hWnd
  112.     Clacker1.Action = CLACKER_STOP
  113.     TXT_MID.Text = "Menu ID, menu not hooked"
  114. End Sub
  115. Sub Clacker1_ClackerClick (hMenu As Integer, MenuID As Integer, MenuCaption As String)
  116. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  117. ' PURPOSE: Determine which menu was hit.
  118. ' COMMENTS: Clacker.vbx returns all the values shown from windows.
  119. '           Read the SDK docs, to better understand Window's menu behavior.
  120. ' NOTES:    1. It is not necessary to make use of all of the return params.
  121. '               Using only the MenuID is suffecient to retreive the stored text.
  122. '           2. Clacker does not return a caption for all menu hits. Windows does
  123. '               not provide return captions for typically unused menu items,
  124. '               ie, those which are processed by Window's default menuprocs.
  125. '           3. Separators return MenuID = 0 for all of them.
  126. '           4. Top level menus and submenus return hMenu = MenuID.
  127. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  128. Dim Msg As String
  129. Dim ndex As Integer
  130. Dim lMenuID As Long, lhMenu As Long
  131. If MenuID = -1 Then Stop
  132. If hMenu = -1 Then Stop
  133.     If MenuID < -1 Then
  134.         'change Menu ID to faked USHORT
  135.         lMenuID = MenuID + 65536
  136.     Else
  137.         lMenuID = MenuID
  138.     End If
  139.     If hMenu < -1 Then
  140.         'change Menu ID to faked USHORT
  141.         lhMenu = hMenu + 65536
  142.     Else
  143.         lhMenu = hMenu
  144.     End If
  145.     '
  146.     ' debugging output
  147.     Msg = ""
  148.     Msg = Msg + "hMenu  hex = " + Hex$(lhMenu) + Chr$(13) + Chr$(10)
  149.     Msg = Msg + "MenuID hex = " + Hex$(lMenuID) + Chr$(13) + Chr$(10)
  150.     If Len(MenuCaption) <> 0 Then
  151.         Msg = Msg + "MenuCaption  " + MenuCaption + Chr$(13) + Chr$(10)
  152.     Else
  153.         Msg = Msg + "MenuCaption  [none returned]" + Chr$(13) + Chr$(10)
  154.     End If
  155.     Debug.Print Msg
  156.     '
  157.     ' user output
  158.     ' search for the MenuID, get the assigned help text and display it.
  159.     For ndex = 1 To 20
  160.         If MenuStatus(ndex).lMenuID = lMenuID Then
  161.             ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  162.             ' IMPORTANT NOTE:
  163.             ' A BOGUS MenuID was initially stored in the top menu spot
  164.             ' The real hMenu of a top level menu shows up here
  165.             ' You can sub the bogus for the real one if desired.
  166.             ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  167.             If MenuStatus(ndex).lhMenu <> lhMenu Then
  168.               '
  169.               ' see if it is the BOGUS MenuID
  170.               '
  171.               If MenuStatus(ndex).lhMenu <> lMenuID Then
  172.                 Msg = "Bad stored hMenu" + Chr$(13) + Chr$(10)
  173.                 Msg = Msg + "Stored hMenu = " + Hex$(MenuStatus(ndex).lhMenu) + Chr$(13) + Chr$(10)
  174.                 Msg = Msg + "Return hMenu = " + Hex$(lhMenu) + Chr$(13) + Chr$(10)
  175.                 Msg = Msg + "return MenuID= " + Hex$(lMenuID) + Chr$(13) + Chr$(10)
  176.                 Debug.Print Msg
  177.               Else
  178.                 Debug.Print "Bogus top level menu was stored here"
  179.               End If
  180.             End If
  181.             Msg = "MenuID = " + Hex$(lMenuID) + Chr$(13) + Chr$(10)
  182.             Msg = Msg + "hMenu = " + Hex$(hMenu) + Chr$(13) + Chr$(10)
  183.             Msg = Msg + "Help Msg Text = " + MenuStatus(ndex).strHelpMsg + Chr$(13) + Chr$(10)
  184.             If Len(MenuCaption) <> 0 Then
  185.                 Msg = Msg + "Menu Caption = " + MenuCaption + Chr$(13) + Chr$(10)
  186.             Else
  187.                 Msg = Msg + "Menu Caption = [No Caption returned]" + Chr$(13) + Chr$(10)
  188.             End If
  189.             TXT_MID.Text = Msg
  190.             Msg = "Found It " + Msg
  191.             Debug.Print Msg
  192.             Exit Sub
  193.         End If
  194.     Next
  195. End Sub
  196. Sub Form_Load ()
  197. Dim hSysMenu As Integer
  198. Dim hMainMenu As Integer
  199. Dim Msg As String
  200. Dim ndex As Integer
  201.     Top = 0
  202.     Left = 0
  203.     '' how many menu items
  204.     ' system
  205.     hSysMenu = GetSystemMenu(Me.hWnd, False)
  206.     ' main menu
  207.     hMainMenu = GetMenu(Me.hWnd)
  208.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  209.     ' IMPORTANT NOTE:
  210.     '   The MenuStatus array size must be equal to or great than the total
  211.     '   number of menu items in the form, or else a bounds error will occur.
  212.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  213.     ReDim MenuStatus(1 To 25) As HelpTextType
  214.     '' fill the array with their ids
  215.     ' first the system menu
  216.     Debug.Print "Setup hSysMenu"
  217.     MenuSetup hSysMenu
  218.     ' now the main menu
  219.     ' start where the sysmenu ends
  220.     Debug.Print "Setup hMainMenu"
  221.     MenuSetup hMainMenu
  222.     '
  223.     '
  224.     ' set up help text
  225.     MenuHelpText
  226.     ' Print all menu IDs to a dialog
  227.     Msg = ""
  228.     Msg = Msg + "Me.hWnd HEX = " + Hex$(hWnd) + "    DECIMAL = " + Str$(hWnd) + Chr$(13) + Chr$(10)
  229.     Msg = Msg + "hSysMenu  =" + Hex$(hSysMenu) + Chr$(13) + Chr$(10)
  230.     Msg = Msg + "hMainMenu =" + Hex$(hMainMenu) + Chr$(13) + Chr$(10) + Chr$(13) + Chr$(10)
  231.     For ndex = 1 To 20
  232.         Msg = Msg + "Index = " + Str$(ndex) + Chr$(13) + Chr$(10)
  233.         Msg = Msg + "hMenu = " + Hex$(MenuStatus(ndex).lhMenu) + Chr$(13) + Chr$(10)
  234.         Msg = Msg + "MID = " + Hex$(MenuStatus(ndex).lMenuID) + Chr$(13) + Chr$(10)
  235.         Msg = Msg + "Help Text    = " + MenuStatus(ndex).strHelpMsg + Chr$(13) + Chr$(10) + Chr$(13) + Chr$(10)
  236.     Next
  237.     Text2.Text = Msg
  238. End Sub
  239. Sub Form_Resize ()
  240.     If Me.WindowState = 0 Then
  241.         Me.Height = 5550
  242.         Me.Width = 5175
  243.     End If
  244. End Sub
  245. Sub Form_Unload (Cancel As Integer)
  246.     Clacker1.hwndForm = Me.hWnd
  247.     Clacker1.Action = CLACKER_STOP
  248. End Sub
  249. Sub MenuHelpText ()
  250. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  251. '  PURPOSE: Load the help text string in the array.
  252. ' COMMENTS: Make sure you provide an entry for each menu in your
  253. '           menu system, even if it won't be used. This helps when
  254. '           laying out the help system and with debugging.
  255. '    NOTES: 1. To conserve stack space in the main module
  256. '               place the text strings and the array in another module
  257. '           2. The MenuStatus array size must be equal to or great than the total
  258. '               number of menu items in the form, or else a bounds error will occur.
  259. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  260.     MenuStatus(1).strHelpMsg = "<System Menu>"
  261.     MenuStatus(2).strHelpMsg = "Restore previous window position"
  262.     MenuStatus(3).strHelpMsg = "Move the current window Window"
  263.     MenuStatus(4).strHelpMsg = "Change the size of current Window"
  264.     MenuStatus(5).strHelpMsg = "Minimize current Window"
  265.     MenuStatus(6).strHelpMsg = "Maximize current Window"
  266.     MenuStatus(7).strHelpMsg = "[separator]"        '[separator], no MenuID and no text
  267.     MenuStatus(8).strHelpMsg = "Close current Window"
  268.     MenuStatus(9).strHelpMsg = "[separator]"        '[separator], no MenuID and no text
  269.     MenuStatus(10).strHelpMsg = "Switch to different task"
  270.     MenuStatus(11).strHelpMsg = "<Main Form Menu>"
  271.     MenuStatus(12).strHelpMsg = "<File Menu>"
  272.     MenuStatus(13).strHelpMsg = "Exit the program"
  273.     MenuStatus(14).strHelpMsg = "<Edit Menu>"
  274.     MenuStatus(15).strHelpMsg = "Cut selected text from document"
  275.     MenuStatus(16).strHelpMsg = "Copy selected text to clipboard"
  276.     MenuStatus(17).strHelpMsg = "Paste clipboard text into document"
  277.     MenuStatus(18).strHelpMsg = "Main Submenu text"
  278.     MenuStatus(19).strHelpMsg = "Submenu1 text message"
  279.     MenuStatus(20).strHelpMsg = "Submenu2 text message"
  280. End Sub
  281. Sub MenuSetup (hMenu As Integer)
  282. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  283. '  PURPOSE: Save the menu item ID information into the passed array
  284. ' COMMENTS: MenuSetup() is called recursively to load sub-menus
  285. '    NOTES: 1. The MenuStatus array size must be equal to or great than the total
  286. '              number of menu items in the form, or else a bounds error will occur.
  287. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  288. Dim nItemCount As Integer
  289. Dim lMenuID, lMenu As Long
  290. Dim nItemPos As Integer
  291. Dim nResult As Integer
  292. Dim nMenuID As Integer
  293. Static nElement As Integer  ' Static for pointer locating the last element inserted
  294. Debug.Print "New hMenu = "; Hex$(hMenu)
  295. Debug.Print
  296.     nItemPos = 0
  297.     nElement = nElement + 1
  298.     '
  299.     '
  300.     ' store the top most menu
  301.     If hMenu < -1 Then
  302.         'change Menu ID to a faked USHORT
  303.         lMenu = hMenu + 65536
  304.     Else
  305.         lMenu = hMenu
  306.     End If
  307.     MenuStatus(nElement).lhMenu = lMenu
  308.     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  309.     ' IMPORTANT NOTE:
  310.     ' Store the hMenu in the menuID spot as a FLAG
  311.     ' The MenuID returned from Clacker WILL NOT MATCH THIS
  312.     ' Clacker will return the real top level hMenu from windows.
  313.     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  314.     lMenuID = hMenu
  315.     MenuStatus(nElement).lMenuID = lMenuID
  316.     Debug.Print "nItemPos = "; nItemPos
  317.     Debug.Print "nElement = "; nElement
  318.     Debug.Print "MenuStatus(nElement).nMenuID = "; Hex$(MenuStatus(nElement).lMenuID)
  319.     Debug.Print "MenuStatus(nElement).lhMenu   = "; Hex$(MenuStatus(nElement).lhMenu)
  320.     Debug.Print
  321.     nItemCount = GetMenuItemCount(hMenu)
  322.     For nItemPos = 0 To nItemCount - 1
  323.         ' Enumerate all sub-menus
  324.         ' each sub menu starts at zero
  325.         ' the menu id for this position
  326.         nMenuID = GetMenuItemID(hMenu, nItemPos)
  327.         If nMenuID = -1 Then
  328.             '
  329.             ' if the first item is -1
  330.             '   it's a submenu ( cascade menu )
  331.             nMenuID = GetSubMenu(hMenu, nItemPos)
  332.             '
  333.             ' since it is a submenu need to
  334.             ' call this function recursively
  335.             Debug.Print "Recurse"
  336.             MenuSetup nMenuID
  337.         Else
  338.             '
  339.             'normal menu item, save the menu item ID
  340.             '
  341.             ' bump the position so we start at 2,
  342.             '   after the first hMenu is added
  343.             nElement = nElement + 1
  344.             ' Menu ID is a USHORT type, but VB has none so,
  345.             ' change Menu ID to unsigned short as required for saving
  346.             ' and later matching the return value from Clacker
  347.             If nMenuID < -1 Then
  348.                 'change Menu ID to a faked USHORT
  349.                 lMenuID = nMenuID + 65536
  350.             Else
  351.                 lMenuID = nMenuID
  352.             End If
  353.             '
  354.             ' Put a menu item in the array
  355.             MenuStatus(nElement).lMenuID = lMenuID
  356.             MenuStatus(nElement).lhMenu = hMenu
  357.             
  358.             Debug.Print "nItemPos = "; nItemPos
  359.             Debug.Print "nElement = "; nElement
  360.             Debug.Print "MenuStatus(nElement).nMenuID = "; Hex$(MenuStatus(nElement).lMenuID)
  361.             Debug.Print "MenuStatus(nElement).lhMenu   = "; Hex$(MenuStatus(nElement).lhMenu)
  362.             Debug.Print
  363.         End If
  364.     Next
  365. End Sub
  366. Sub mnu_Exit_Click ()
  367.     '
  368.     ' process cannot terminate with menus still hooked to dll
  369.     Clacker1.hwndForm = Me.hWnd
  370.     Clacker1.Action = CLACKER_STOP
  371.     End
  372. End Sub
  373.