home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_1 / CLAK20 / GENERAPP.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-12-23  |  12.8 KB  |  327 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. Option Explicit
  101. Const CLACKER_START = 1
  102. Const CLACKER_STOP = 2
  103. Dim CRLF As String
  104. Dim MenuStatus(1 To 25) As HelpTextType  '' help string array
  105. Dim LocalMenuIDArray() As Long           '' local menu ID array
  106. Sub BTN_Exit_Click ()
  107.     '' user initiated exit
  108.     mnu_Exit_Click
  109. End Sub
  110. Sub Btn_Hook_Click ()
  111. '' PURPOSE: Hook up the menu to CLACKER.VBX
  112. '' COMMENTS: Each form with a menu to monitor
  113. ''           should have a similar statement block
  114. '''''''''''''''''''''''''''''''''''''''''''''''''''
  115.     '' set the HWND of this form
  116.     Clacker1.hwndForm = Me.hWnd
  117.     '' issue the action command
  118.     Clacker1.Action = CLACKER_START   ''1
  119.     '' put up some status info
  120.     TXT_MID.Text = "Menu ID, menu hooked"
  121. End Sub
  122. Sub Btn_UnHook_Click ()
  123.     '' user initiated unhook command
  124.     '' unhook the menu
  125.     Clacker1.Action = CLACKER_STOP  ''2
  126.     '' some status text
  127.     TXT_MID.Text = "Menu Unhooked"
  128. End Sub
  129. Sub Clacker1_ClackerClick (hMenu As Integer, MenuID As Integer, MenuCaption As String)
  130. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  131. ' PURPOSE: Determine which menu was hit.
  132. ' COMMENTS: Clacker.vbx returns all the values shown from windows.
  133. '           Read the SDK docs, to better understand Window's menu behavior.
  134. '           Parametrs returned are:
  135. '               hMenu the menu handle
  136. '               MenuID the resource ID of the menu ( actually a Unsigned Integer )
  137. '               MenuCaption the menu caption text
  138. ' NOTES:    1. It is not necessary to make use of all of the return params.
  139. '               Using only the MenuID is suffecient to retreive the stored text.
  140. '           2. Clacker does not return a caption for all menu hits. Windows does
  141. '               not provide return captions for typically unused menu items,
  142. '               ie, separators and those menu items which are processed by
  143. '               Window's default menuprocs.
  144. '           3. Separators return MenuID = 0 for all of them.
  145. '           4. Top level menus and submenus return hMenu = MenuID.
  146. '           5. How to get to the status text...
  147. '               Make a text array with the text strings you want to use for each menu item
  148. '               Use the ndex value as a position of the match to fetch the text string.
  149. '           6. Break Points in this Sub suspends execution in a menu call so the VB menus
  150. '               will be disabled until the Sub exits. Use Debug.Print statements instead
  151. '               of break points to debug you code.
  152. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  153. Dim Msg As String
  154. Dim ndex As Integer
  155. Dim lMenuID As Long
  156.     '' for diagnostic use to show what is going on
  157.     '' put up data we start with
  158.     Msg = "Returned MenuID = " + Str$(MenuID) + Chr$(13) + Chr$(10)
  159.     Msg = Msg + "Returned hMenu = " + Str$(hMenu) + Chr$(13) + Chr$(10)
  160.     Msg = Msg + "MenuCaption = " + MenuCaption + Chr$(13) + Chr$(10)
  161.     Debug.Print Msg
  162.     ''
  163.     ''
  164.     '' VB has no unsigned integer data type so .... this
  165.     '' conversion is necessary before using the MenuID returned
  166.     ''
  167.     '' change the MenuID to a USHORT if required
  168.     '' this is to pick up the system menu items
  169.     If MenuID < -1 Then
  170.         lMenuID = MenuID + 65536
  171.     Else
  172.         lMenuID = MenuID
  173.     End If
  174.     '' end conversion code
  175.     '' find a matching value
  176.     For ndex = 1 To UBound(LocalMenuIDArray)
  177.         If LocalMenuIDArray(ndex) = lMenuID Then
  178.             '' found the matching MenuID that was stored in our local array
  179.             ''
  180.             ''
  181.             '' this is to just put up some diagnostic text
  182.             Msg = "MenuID = " + Str$(MenuID) + Chr$(13) + Chr$(10)
  183.             Msg = Msg + "hMenu = " + Str$(hMenu) + Chr$(13) + Chr$(10)
  184.             Msg = Msg + "Help Msg Text = " + MenuStatus(ndex).strHelpMsg + Chr$(13) + Chr$(10)
  185.             If Len(MenuCaption) <> 0 Then
  186.                 Msg = Msg + "Menu Caption = " + MenuCaption + Chr$(13) + Chr$(10)
  187.             Else
  188.                 Msg = Msg + "Menu Caption = [No Caption returned]" + Chr$(13) + Chr$(10)
  189.             End If
  190.             TXT_MID.Text = Msg
  191.             Debug.Print "LocalMenuIDArray(ndex) = "; LocalMenuIDArray(ndex)
  192.             
  193.             ''
  194.             '' leave the loop with ndex pointing
  195.             '' to the desired text string position
  196.             Exit For
  197.         End If
  198.         '' for diagnostic use to show what is going on...
  199.         '' if we fail to find a match we put this up each
  200.         '' time to just do something interesting here
  201.         TXT_MID.Text = "No Match"
  202.     Next
  203.     '' for diagnostic use to show what is going on
  204.     '' put up where we found a match
  205.     Debug.Print "ndex = "; ndex
  206.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  207.     '' at this point ndex is the position of our desired text string.
  208.     '' use ndex to get to the text and place it in the status box.
  209.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  210. End Sub
  211. Sub Clacker1_ClearStatusClick ()
  212. '' PURPOSE: Event returned by CLACKER.VBX
  213. ''COMMENTS: Event is returned when a menu item is
  214. ''          actually selected by the user.
  215. '' USEAGE:  Clear the status line of text if desired
  216. ''''''''''''''''''''''''''''''''''''''''''''''''''''
  217. Dim Msg As String
  218.     Msg = "Illustrates the clear function for the staus text." + CRLF
  219.     Msg = Msg + "You would normally just output a blank line" + CRLF
  220.     Msg = Msg + "when a menu command is actually executed."
  221.     TXT_MID.Text = Msg
  222. End Sub
  223. Sub Clacker1_RefreshHwndClick (MenuItemCount As Integer)
  224. '' PURPOSE: Event returned by CLACKER.VBX
  225. ''COMMENTS: Event is returned in response to the CLACKER.VBX
  226. ''          being issued the command "Clacker1.RefreshHwnd = [HWND]
  227. '' USEAGE:  Load the local array from the CLACKER.VBX control
  228. ''          with the menu IDs of all menu items associated
  229. ''          with the hwnd sent.
  230. ''          This local array is then used for finding the position of the
  231. ''          status text to display.
  232. ''          The MenuID returned in the array is the same as the MenuID parameter
  233. ''          returned in the ClackerClick() event
  234. ''''''''''''''''''''''''''''''''''''''''''''''''''''
  235. Dim ndex As Integer
  236. Dim Msg As String
  237.     '' A return value of 0 indicates the menu was not found
  238.     '' or the hwnd passed was no good
  239.     If (MenuItemCount = 0) Then
  240.         ' just for debugging, don't use in final apps
  241.         MsgBox "MenuItemCount = 0"
  242.         Exit Sub
  243.     Else
  244.         Debug.Print ""
  245.         Debug.Print "MenuItemCount = "; MenuItemCount
  246.     End If
  247.     '' set the array size to MenuItemCount
  248.     ReDim LocalMenuIDArray(1 To MenuItemCount)
  249.     '' fill the array
  250.     For ndex = 1 To MenuItemCount
  251.         '' move the data to the loacal array
  252.         LocalMenuIDArray(ndex) = Clacker1.MenuIDArray(ndex)
  253.         '' for diagnostic use to show what is going on
  254.         '' put up data we stored
  255.         Debug.Print "LocalMenuIDArray(" + Str$(ndex) + ") = "; Str$(Clacker1.MenuIDArray(ndex))
  256.     Next ndex
  257. End Sub
  258. Sub Form_Load ()
  259. Dim hSysMenu As Integer
  260. Dim hMainMenu As Integer
  261. Dim Msg As String
  262. Dim ndex As Integer
  263.     '' first load the global constant
  264.     CRLF = Chr$(13) + Chr$(10)
  265.     If Me.WindowState = 0 Then
  266.         Top = 0
  267.         Left = 0
  268.     End If
  269.     '' fill the local array
  270.     Clacker1.RefreshHwnd = Me.hWnd
  271.     ''
  272.     '' The array is filled and the event
  273.     '' Clacker1_RefreshHwndClick (MenuItemCount As Integer)
  274.     '' is used to transfer the values into the LocalHwndArray[]
  275.     ''
  276.     ''
  277. End Sub
  278. Sub Form_Resize ()
  279.     If Me.WindowState = 0 Then
  280.         Me.Height = 5550
  281.         Me.Width = 5175
  282.     End If
  283. End Sub
  284. Sub Form_Unload (Cancel As Integer)
  285.     '' good programming practice to clean up
  286.     '' unhook the menu
  287.     Clacker1.Action = CLACKER_STOP  ''2
  288. End Sub
  289. Sub MenuHelpText ()
  290. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  291. '  PURPOSE: Load the help text string in the array.
  292. ' COMMENTS: Make sure you provide an entry for each menu in your
  293. '           menu system, even if it won't be used. This helps when
  294. '           laying out the help system and with debugging.
  295. '    NOTES: 1. To conserve stack space in the main module
  296. '               place the text strings and the array in another module
  297. '           2. The MenuStatus array size must be equal to or great than the total
  298. '               number of menu items in the form, or else a bounds error will occur.
  299. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  300.     MenuStatus(1).strHelpMsg = "<System Menu>"
  301.     MenuStatus(2).strHelpMsg = "Restore previous window position"
  302.     MenuStatus(3).strHelpMsg = "Move the current window Window"
  303.     MenuStatus(4).strHelpMsg = "Change the size of current Window"
  304.     MenuStatus(5).strHelpMsg = "Minimize current Window"
  305.     MenuStatus(6).strHelpMsg = "Maximize current Window"
  306.     MenuStatus(7).strHelpMsg = "[separator]"        '[separator], no MenuID and no text
  307.     MenuStatus(8).strHelpMsg = "Close current Window"
  308.     MenuStatus(9).strHelpMsg = "[separator]"        '[separator], no MenuID and no text
  309.     MenuStatus(10).strHelpMsg = "Switch to different task"
  310.     MenuStatus(11).strHelpMsg = "<Main Form Menu>"
  311.     MenuStatus(12).strHelpMsg = "<File Menu>"
  312.     MenuStatus(13).strHelpMsg = "Exit the program"
  313.     MenuStatus(14).strHelpMsg = "<Edit Menu>"
  314.     MenuStatus(15).strHelpMsg = "Cut selected text from document"
  315.     MenuStatus(16).strHelpMsg = "Copy selected text to clipboard"
  316.     MenuStatus(17).strHelpMsg = "Paste clipboard text into document"
  317.     MenuStatus(18).strHelpMsg = "Main Submenu text"
  318.     MenuStatus(19).strHelpMsg = "Submenu1 text message"
  319.     MenuStatus(20).strHelpMsg = "Submenu2 text message"
  320. End Sub
  321. Sub mnu_Exit_Click ()
  322.     '
  323.     ' process should not terminate with menus still hooked in dll
  324.     Clacker1.Action = CLACKER_STOP  ''2
  325.     End
  326. End Sub
  327.