home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / clak20 / generapp.frm < prev    next >
Text File  |  1993-12-23  |  13KB  |  393 lines

  1. VERSION 2.00
  2. Begin Form Clacker_Form 
  3.    Caption         =   "Clacker Test"
  4.    ClientHeight    =   4860
  5.    ClientLeft      =   1215
  6.    ClientTop       =   1785
  7.    ClientWidth     =   5055
  8.    Height          =   5550
  9.    Left            =   1155
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4860
  12.    ScaleWidth      =   5055
  13.    Top             =   1155
  14.    Width           =   5175
  15.    Begin Clack Clacker1 
  16.       hwndForm        =   0
  17.       Left            =   360
  18.       SystemMenu      =   -1  'True
  19.       Top             =   240
  20.    End
  21.    Begin CommandButton BTN_Exit 
  22.       Caption         =   "Exit"
  23.       Height          =   375
  24.       Left            =   3720
  25.       TabIndex        =   4
  26.       Top             =   240
  27.       Width           =   1215
  28.    End
  29.    Begin TextBox Text2 
  30.       Height          =   2655
  31.       Left            =   120
  32.       MultiLine       =   -1  'True
  33.       ScrollBars      =   3  'Both
  34.       TabIndex        =   3
  35.       Text            =   "Text2"
  36.       Top             =   840
  37.       Width           =   4815
  38.    End
  39.    Begin CommandButton Btn_UnHook 
  40.       Caption         =   "UnHook"
  41.       Height          =   375
  42.       Left            =   1080
  43.       TabIndex        =   1
  44.       Top             =   240
  45.       Width           =   1215
  46.    End
  47.    Begin CommandButton Btn_Hook 
  48.       Caption         =   "Hook"
  49.       Height          =   375
  50.       Left            =   2400
  51.       TabIndex        =   2
  52.       Top             =   240
  53.       Width           =   1215
  54.    End
  55.    Begin TextBox TXT_MID 
  56.       Height          =   975
  57.       Left            =   120
  58.       MultiLine       =   -1  'True
  59.       TabIndex        =   0
  60.       Text            =   "Menu ID, menu not hooked"
  61.       Top             =   3720
  62.       Width           =   4815
  63.    End
  64.    Begin Menu nmu_File 
  65.       Caption         =   "&File"
  66.       HelpContextID   =   9
  67.       Begin Menu mnu_Exit 
  68.          Caption         =   "&Exit"
  69.          HelpContextID   =   1
  70.       End
  71.    End
  72.    Begin Menu mnu_Edit 
  73.       Caption         =   "&Edit"
  74.       HelpContextID   =   2
  75.       Begin Menu mnu_Cut 
  76.          Caption         =   "Cu&t"
  77.          HelpContextID   =   3
  78.       End
  79.       Begin Menu mnu_Copy 
  80.          Caption         =   "&Copy"
  81.          HelpContextID   =   4
  82.       End
  83.       Begin Menu mnu_Paste 
  84.          Caption         =   "&Paste"
  85.          HelpContextID   =   5
  86.       End
  87.       Begin Menu mnu_submenu 
  88.          Caption         =   "SubMenu"
  89.          HelpContextID   =   6
  90.          Begin Menu mnu_submenu1 
  91.             Caption         =   "SubMenu 1"
  92.             HelpContextID   =   7
  93.          End
  94.          Begin Menu mnu_submenu2 
  95.             Caption         =   "SubMenu 2"
  96.             HelpContextID   =   8
  97.          End
  98.       End
  99.    End
  100. End
  101. Option Explicit
  102.  
  103. Const CLACKER_START = 1
  104. Const CLACKER_STOP = 2
  105.  
  106. Dim CRLF As String
  107.  
  108. Dim MenuStatus(1 To 25) As HelpTextType  '' help string array
  109.  
  110. Dim LocalMenuIDArray() As Long           '' local menu ID array
  111.  
  112. Sub BTN_Exit_Click ()
  113.  
  114.     '' user initiated exit
  115.     mnu_Exit_Click
  116.  
  117. End Sub
  118.  
  119. Sub Btn_Hook_Click ()
  120. '' PURPOSE: Hook up the menu to CLACKER.VBX
  121. '' COMMENTS: Each form with a menu to monitor
  122. ''           should have a similar statement block
  123. '''''''''''''''''''''''''''''''''''''''''''''''''''
  124.  
  125.     '' set the HWND of this form
  126.     Clacker1.hwndForm = Me.hWnd
  127.     
  128.     '' issue the action command
  129.     Clacker1.Action = CLACKER_START   ''1
  130.  
  131.     '' put up some status info
  132.     TXT_MID.Text = "Menu ID, menu hooked"
  133.  
  134. End Sub
  135.  
  136. Sub Btn_UnHook_Click ()
  137.  
  138.     '' user initiated unhook command
  139.     
  140.     '' unhook the menu
  141.     Clacker1.Action = CLACKER_STOP  ''2
  142.  
  143.     '' some status text
  144.     TXT_MID.Text = "Menu Unhooked"
  145.  
  146. End Sub
  147.  
  148. Sub Clacker1_ClackerClick (hMenu As Integer, MenuID As Integer, MenuCaption As String)
  149. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  150. ' PURPOSE: Determine which menu was hit.
  151. ' COMMENTS: Clacker.vbx returns all the values shown from windows.
  152. '           Read the SDK docs, to better understand Window's menu behavior.
  153. '           Parametrs returned are:
  154. '               hMenu the menu handle
  155. '               MenuID the resource ID of the menu ( actually a Unsigned Integer )
  156. '               MenuCaption the menu caption text
  157. ' NOTES:    1. It is not necessary to make use of all of the return params.
  158. '               Using only the MenuID is suffecient to retreive the stored text.
  159. '           2. Clacker does not return a caption for all menu hits. Windows does
  160. '               not provide return captions for typically unused menu items,
  161. '               ie, separators and those menu items which are processed by
  162. '               Window's default menuprocs.
  163. '           3. Separators return MenuID = 0 for all of them.
  164. '           4. Top level menus and submenus return hMenu = MenuID.
  165. '           5. How to get to the status text...
  166. '               Make a text array with the text strings you want to use for each menu item
  167. '               Use the ndex value as a position of the match to fetch the text string.
  168. '           6. Break Points in this Sub suspends execution in a menu call so the VB menus
  169. '               will be disabled until the Sub exits. Use Debug.Print statements instead
  170. '               of break points to debug you code.
  171. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  172. Dim Msg As String
  173. Dim ndex As Integer
  174. Dim lMenuID As Long
  175.  
  176.     '' for diagnostic use to show what is going on
  177.     '' put up data we start with
  178.     Msg = "Returned MenuID = " + Str$(MenuID) + Chr$(13) + Chr$(10)
  179.     Msg = Msg + "Returned hMenu = " + Str$(hMenu) + Chr$(13) + Chr$(10)
  180.     Msg = Msg + "MenuCaption = " + MenuCaption + Chr$(13) + Chr$(10)
  181.     Debug.Print Msg
  182.  
  183.     ''
  184.     ''
  185.     '' VB has no unsigned integer data type so .... this
  186.     '' conversion is necessary before using the MenuID returned
  187.     ''
  188.     '' change the MenuID to a USHORT if required
  189.     '' this is to pick up the system menu items
  190.     If MenuID < -1 Then
  191.         lMenuID = MenuID + 65536
  192.     Else
  193.         lMenuID = MenuID
  194.     End If
  195.     '' end conversion code
  196.  
  197.  
  198.  
  199.     '' find a matching value
  200.     For ndex = 1 To UBound(LocalMenuIDArray)
  201.         If LocalMenuIDArray(ndex) = lMenuID Then
  202.             '' found the matching MenuID that was stored in our local array
  203.  
  204.             ''
  205.             ''
  206.             '' this is to just put up some diagnostic text
  207.             Msg = "MenuID = " + Str$(MenuID) + Chr$(13) + Chr$(10)
  208.             Msg = Msg + "hMenu = " + Str$(hMenu) + Chr$(13) + Chr$(10)
  209.             Msg = Msg + "Help Msg Text = " + MenuStatus(ndex).strHelpMsg + Chr$(13) + Chr$(10)
  210.             If Len(MenuCaption) <> 0 Then
  211.                 Msg = Msg + "Menu Caption = " + MenuCaption + Chr$(13) + Chr$(10)
  212.             Else
  213.                 Msg = Msg + "Menu Caption = [No Caption returned]" + Chr$(13) + Chr$(10)
  214.             End If
  215.             TXT_MID.Text = Msg
  216.             Debug.Print "LocalMenuIDArray(ndex) = "; LocalMenuIDArray(ndex)
  217.  
  218.             
  219.             ''
  220.             '' leave the loop with ndex pointing
  221.             '' to the desired text string position
  222.             Exit For
  223.  
  224.         End If
  225.  
  226.         '' for diagnostic use to show what is going on...
  227.         '' if we fail to find a match we put this up each
  228.         '' time to just do something interesting here
  229.         TXT_MID.Text = "No Match"
  230.  
  231.     Next
  232.  
  233.     
  234.     '' for diagnostic use to show what is going on
  235.     '' put up where we found a match
  236.     Debug.Print "ndex = "; ndex
  237.  
  238.  
  239.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  240.     '' at this point ndex is the position of our desired text string.
  241.     '' use ndex to get to the text and place it in the status box.
  242.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  243. End Sub
  244.  
  245. Sub Clacker1_ClearStatusClick ()
  246. '' PURPOSE: Event returned by CLACKER.VBX
  247. ''COMMENTS: Event is returned when a menu item is
  248. ''          actually selected by the user.
  249. '' USEAGE:  Clear the status line of text if desired
  250. ''''''''''''''''''''''''''''''''''''''''''''''''''''
  251. Dim Msg As String
  252.  
  253.     Msg = "Illustrates the clear function for the staus text." + CRLF
  254.     Msg = Msg + "You would normally just output a blank line" + CRLF
  255.     Msg = Msg + "when a menu command is actually executed."
  256.     TXT_MID.Text = Msg
  257.  
  258. End Sub
  259.  
  260. Sub Clacker1_RefreshHwndClick (MenuItemCount As Integer)
  261. '' PURPOSE: Event returned by CLACKER.VBX
  262. ''COMMENTS: Event is returned in response to the CLACKER.VBX
  263. ''          being issued the command "Clacker1.RefreshHwnd = [HWND]
  264. '' USEAGE:  Load the local array from the CLACKER.VBX control
  265. ''          with the menu IDs of all menu items associated
  266. ''          with the hwnd sent.
  267. ''
  268. ''          This local array is then used for finding the position of the
  269. ''          status text to display.
  270. ''
  271. ''          The MenuID returned in the array is the same as the MenuID parameter
  272. ''          returned in the ClackerClick() event
  273. ''''''''''''''''''''''''''''''''''''''''''''''''''''
  274. Dim ndex As Integer
  275. Dim Msg As String
  276.  
  277.  
  278.     '' A return value of 0 indicates the menu was not found
  279.     '' or the hwnd passed was no good
  280.     If (MenuItemCount = 0) Then
  281.         ' just for debugging, don't use in final apps
  282.         MsgBox "MenuItemCount = 0"
  283.         Exit Sub
  284.     Else
  285.         Debug.Print ""
  286.         Debug.Print "MenuItemCount = "; MenuItemCount
  287.     End If
  288.  
  289.     '' set the array size to MenuItemCount
  290.     ReDim LocalMenuIDArray(1 To MenuItemCount)
  291.  
  292.     '' fill the array
  293.     For ndex = 1 To MenuItemCount
  294.         '' move the data to the loacal array
  295.         LocalMenuIDArray(ndex) = Clacker1.MenuIDArray(ndex)
  296.     
  297.     
  298.         '' for diagnostic use to show what is going on
  299.         '' put up data we stored
  300.         Debug.Print "LocalMenuIDArray(" + Str$(ndex) + ") = "; Str$(Clacker1.MenuIDArray(ndex))
  301.  
  302.     Next ndex
  303.  
  304.  
  305. End Sub
  306.  
  307. Sub Form_Load ()
  308. Dim hSysMenu As Integer
  309. Dim hMainMenu As Integer
  310. Dim Msg As String
  311. Dim ndex As Integer
  312.  
  313.     '' first load the global constant
  314.     CRLF = Chr$(13) + Chr$(10)
  315.     
  316.     If Me.WindowState = 0 Then
  317.         Top = 0
  318.         Left = 0
  319.     End If
  320.     
  321.     '' fill the local array
  322.     Clacker1.RefreshHwnd = Me.hWnd
  323.     
  324.     ''
  325.     '' The array is filled and the event
  326.     '' Clacker1_RefreshHwndClick (MenuItemCount As Integer)
  327.     '' is used to transfer the values into the LocalHwndArray[]
  328.     ''
  329.     ''
  330.  
  331.  
  332. End Sub
  333.  
  334. Sub Form_Resize ()
  335.     If Me.WindowState = 0 Then
  336.         Me.Height = 5550
  337.         Me.Width = 5175
  338.     End If
  339. End Sub
  340.  
  341. Sub Form_Unload (Cancel As Integer)
  342.  
  343.     '' good programming practice to clean up
  344.     '' unhook the menu
  345.     Clacker1.Action = CLACKER_STOP  ''2
  346.  
  347. End Sub
  348.  
  349. Sub MenuHelpText ()
  350. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  351. '  PURPOSE: Load the help text string in the array.
  352. ' COMMENTS: Make sure you provide an entry for each menu in your
  353. '           menu system, even if it won't be used. This helps when
  354. '           laying out the help system and with debugging.
  355. '    NOTES: 1. To conserve stack space in the main module
  356. '               place the text strings and the array in another module
  357. '           2. The MenuStatus array size must be equal to or great than the total
  358. '               number of menu items in the form, or else a bounds error will occur.
  359. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  360.  
  361.     MenuStatus(1).strHelpMsg = "<System Menu>"
  362.     MenuStatus(2).strHelpMsg = "Restore previous window position"
  363.     MenuStatus(3).strHelpMsg = "Move the current window Window"
  364.     MenuStatus(4).strHelpMsg = "Change the size of current Window"
  365.     MenuStatus(5).strHelpMsg = "Minimize current Window"
  366.     MenuStatus(6).strHelpMsg = "Maximize current Window"
  367.     MenuStatus(7).strHelpMsg = "[separator]"        '[separator], no MenuID and no text
  368.     MenuStatus(8).strHelpMsg = "Close current Window"
  369.     MenuStatus(9).strHelpMsg = "[separator]"        '[separator], no MenuID and no text
  370.     MenuStatus(10).strHelpMsg = "Switch to different task"
  371.     MenuStatus(11).strHelpMsg = "<Main Form Menu>"
  372.     MenuStatus(12).strHelpMsg = "<File Menu>"
  373.     MenuStatus(13).strHelpMsg = "Exit the program"
  374.     MenuStatus(14).strHelpMsg = "<Edit Menu>"
  375.     MenuStatus(15).strHelpMsg = "Cut selected text from document"
  376.     MenuStatus(16).strHelpMsg = "Copy selected text to clipboard"
  377.     MenuStatus(17).strHelpMsg = "Paste clipboard text into document"
  378.     MenuStatus(18).strHelpMsg = "Main Submenu text"
  379.     MenuStatus(19).strHelpMsg = "Submenu1 text message"
  380.     MenuStatus(20).strHelpMsg = "Submenu2 text message"
  381.  
  382. End Sub
  383.  
  384. Sub mnu_Exit_Click ()
  385.     '
  386.     ' process should not terminate with menus still hooked in dll
  387.     Clacker1.Action = CLACKER_STOP  ''2
  388.     
  389.     End
  390.  
  391. End Sub
  392.  
  393.