home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / msg_spy / spydemo.frm < prev    next >
Text File  |  1994-05-26  |  11KB  |  340 lines

  1. VERSION 2.00
  2. Begin Form frmMsgSpyDemo 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Message Spy Custom Control Demo"
  6.    ClientHeight    =   4725
  7.    ClientLeft      =   495
  8.    ClientTop       =   1590
  9.    ClientWidth     =   5370
  10.    Height          =   5160
  11.    Icon            =   SPYDEMO.FRX:0000
  12.    Left            =   420
  13.    LinkTopic       =   "Form2"
  14.    ScaleHeight     =   315
  15.    ScaleMode       =   3  'Pixel
  16.    ScaleWidth      =   358
  17.    Tag             =   "This is the main form."
  18.    Top             =   1230
  19.    Width           =   5520
  20.    Begin CommandButton Command1 
  21.       Caption         =   "Command btn"
  22.       Height          =   375
  23.       Left            =   540
  24.       TabIndex        =   1
  25.       Tag             =   "This is a command button."
  26.       Top             =   540
  27.       Width           =   1635
  28.    End
  29.    Begin Frame fraStatusArea 
  30.       BackColor       =   &H00C0C0C0&
  31.       Height          =   1572
  32.       Left            =   120
  33.       TabIndex        =   10
  34.       Tag             =   "This is the status area frame."
  35.       Top             =   3000
  36.       Width           =   5112
  37.       Begin CheckBox chkSpyingEnabled 
  38.          BackColor       =   &H00C0C0C0&
  39.          Caption         =   "&Spying Enabled"
  40.          Height          =   252
  41.          Left            =   240
  42.          TabIndex        =   11
  43.          Tag             =   "Check to enable spying."
  44.          Top             =   240
  45.          Value           =   1  'Checked
  46.          Width           =   1752
  47.       End
  48.       Begin Label lblControlTag 
  49.          Alignment       =   2  'Center
  50.          BackStyle       =   0  'Transparent
  51.          BorderStyle     =   1  'Fixed Single
  52.          FontBold        =   0   'False
  53.          FontItalic      =   0   'False
  54.          FontName        =   "MS Sans Serif"
  55.          FontSize        =   8.25
  56.          FontStrikethru  =   0   'False
  57.          FontUnderline   =   0   'False
  58.          Height          =   252
  59.          Left            =   240
  60.          TabIndex        =   12
  61.          Top             =   660
  62.          Width           =   4572
  63.       End
  64.       Begin Label lblMessage 
  65.          Alignment       =   2  'Center
  66.          BackStyle       =   0  'Transparent
  67.          BorderStyle     =   1  'Fixed Single
  68.          FontBold        =   0   'False
  69.          FontItalic      =   0   'False
  70.          FontName        =   "MS Sans Serif"
  71.          FontSize        =   8.25
  72.          FontStrikethru  =   0   'False
  73.          FontUnderline   =   0   'False
  74.          Height          =   252
  75.          Left            =   240
  76.          TabIndex        =   13
  77.          Top             =   1080
  78.          Width           =   2652
  79.       End
  80.       Begin Label lblXPos 
  81.          Alignment       =   2  'Center
  82.          BackStyle       =   0  'Transparent
  83.          BorderStyle     =   1  'Fixed Single
  84.          FontBold        =   0   'False
  85.          FontItalic      =   0   'False
  86.          FontName        =   "MS Sans Serif"
  87.          FontSize        =   8.25
  88.          FontStrikethru  =   0   'False
  89.          FontUnderline   =   0   'False
  90.          Height          =   252
  91.          Left            =   3120
  92.          TabIndex        =   14
  93.          Top             =   1080
  94.          Width           =   732
  95.       End
  96.       Begin Label lblYPos 
  97.          Alignment       =   2  'Center
  98.          BackStyle       =   0  'Transparent
  99.          BorderStyle     =   1  'Fixed Single
  100.          FontBold        =   0   'False
  101.          FontItalic      =   0   'False
  102.          FontName        =   "MS Sans Serif"
  103.          FontSize        =   8.25
  104.          FontStrikethru  =   0   'False
  105.          FontUnderline   =   0   'False
  106.          Height          =   252
  107.          Left            =   4080
  108.          TabIndex        =   15
  109.          Top             =   1080
  110.          Width           =   732
  111.       End
  112.    End
  113.    Begin Frame Frame1 
  114.       BackColor       =   &H00C0C0C0&
  115.       Caption         =   "Frame"
  116.       Height          =   2772
  117.       Left            =   2700
  118.       TabIndex        =   9
  119.       Tag             =   "This is a frame."
  120.       Top             =   120
  121.       Width           =   2052
  122.       Begin CheckBox Check1 
  123.          BackColor       =   &H00C0C0C0&
  124.          Caption         =   "Check Box"
  125.          Height          =   312
  126.          Left            =   300
  127.          TabIndex        =   5
  128.          Tag             =   "This is the first check box."
  129.          Top             =   360
  130.          Width           =   1572
  131.       End
  132.       Begin CheckBox Check2 
  133.          BackColor       =   &H00C0C0C0&
  134.          Caption         =   "Check Box"
  135.          Height          =   312
  136.          Left            =   300
  137.          TabIndex        =   6
  138.          Tag             =   "This is the second check box."
  139.          Top             =   960
  140.          Width           =   1572
  141.       End
  142.       Begin OptionButton Option4 
  143.          BackColor       =   &H00C0C0C0&
  144.          Caption         =   "Radio button"
  145.          Height          =   375
  146.          Left            =   300
  147.          TabIndex        =   8
  148.          Tag             =   "This is the second radio button in the frame."
  149.          Top             =   2220
  150.          Width           =   1455
  151.       End
  152.       Begin OptionButton Option3 
  153.          BackColor       =   &H00C0C0C0&
  154.          Caption         =   "Radio button"
  155.          Height          =   375
  156.          Left            =   300
  157.          TabIndex        =   7
  158.          Tag             =   "This is the first radio button in the frame."
  159.          Top             =   1560
  160.          Value           =   -1  'True
  161.          Width           =   1455
  162.       End
  163.    End
  164.    Begin MsgSpy MsgSpy1 
  165.       Left            =   2160
  166.       MessageNumber   =   1024
  167.       SpyMode         =   0  'All Messages
  168.       Tag             =   "This is a Message Spy control!"
  169.       Top             =   1440
  170.    End
  171.    Begin OptionButton Option2 
  172.       BackColor       =   &H00C0C0C0&
  173.       Caption         =   "Radio button"
  174.       Height          =   375
  175.       Left            =   540
  176.       TabIndex        =   3
  177.       Tag             =   "This is the second radio button."
  178.       Top             =   1620
  179.       Width           =   1455
  180.    End
  181.    Begin TextBox Text1 
  182.       Height          =   285
  183.       Left            =   540
  184.       TabIndex        =   0
  185.       Tag             =   "This is a text box."
  186.       Text            =   "Text box"
  187.       Top             =   120
  188.       Width           =   1635
  189.    End
  190.    Begin ListBox List1 
  191.       Height          =   810
  192.       Left            =   540
  193.       TabIndex        =   4
  194.       Tag             =   "This is a list box."
  195.       Top             =   2160
  196.       Width           =   1635
  197.    End
  198.    Begin OptionButton Option1 
  199.       BackColor       =   &H00C0C0C0&
  200.       Caption         =   "Radio button"
  201.       Height          =   375
  202.       Left            =   540
  203.       TabIndex        =   2
  204.       Tag             =   "This is the first radio button."
  205.       Top             =   1080
  206.       Value           =   -1  'True
  207.       Width           =   1455
  208.    End
  209. End
  210. '-------------------------------------------------
  211. '
  212. ' SpyDemo - a Message Spy Custom Control demo
  213. '
  214. ' Note the possible uses of the following
  215. ' properties within the MsgReceieved event:
  216. '
  217. '   MessageName - the name of the message
  218. '   IsControl   - whether message is for a control
  219. '   Control     - the actual subclassed control!!!
  220. '   ControlName - the subclassed control's name
  221. '   IsForm      - whether message is for a form
  222. '   Form        - the actual subclassed form!!!
  223. '   FormName    - the subclassed form's name
  224. '   HIWORD      - like HIWORD(LParam) in C/C++
  225. '   LOWORD      - like LOWORD(LParam) in C/C++
  226. '
  227. ' Copyright (c) 1992-1994 Anton Software Limited.
  228. '
  229. '-------------------------------------------------
  230.  
  231. Option Explicit
  232.  
  233. ' Const WM_SETFOCUS = &H7
  234. ' Const WM_MOUSEMOVE = &H200
  235. '
  236. ' These constants are not needed, as the message
  237. ' name is provided directly. Nevertheless, for
  238. ' production code, or if performance is a major
  239. ' issue, it would be better to use them instead.
  240. '
  241. ' e.g.
  242. '
  243. '   If (Msg = WM_SETFOCUS) Then
  244. '
  245. '   instead of
  246. '
  247. '   If (MsgSpy1.MessageName = "WM_SETFOCUS") Then
  248.  
  249. Sub chkSpyingEnabled_Click ()
  250.  
  251.     ' Enable/disable the Message Spy control.
  252.     MsgSpy1.Enabled = chkSpyingEnabled.Value
  253.  
  254. End Sub
  255.  
  256. Sub Form_Load ()
  257.  
  258.     ' Handle controls without hWnd properties.
  259.     On Error GoTo Handler
  260.  
  261.     ' Subclass ALL the other controls on the form.
  262.     Dim i As Integer
  263.     For i = 0 To controls.Count - 1
  264.         MsgSpy1 = controls(i).hWnd
  265.     Next i
  266.  
  267.     ' Subclass the form itself.
  268.     MsgSpy1 = frmMsgSpyDemo.hWnd
  269.  
  270.     Exit Sub
  271.  
  272. Handler:
  273.  
  274.     ' Labels (etc.) don't have window handles!
  275.     Resume Next
  276.  
  277. End Sub
  278.  
  279. Sub MsgSpy1_MsgReceived (hWnd As Integer, Msg As Integer, WParam As Integer, LParam As Long)
  280.  
  281.     ' The control or form name and tag.
  282.     Dim WindowName As String
  283.     Dim WindowTag  As String
  284.  
  285.     ' Save the message name.
  286.     Dim MessageName As String
  287.     MessageName = MsgSpy1.MessageName
  288.  
  289.     ' If the message is for a control...
  290.     If MsgSpy1.IsControl Then
  291.  
  292.         ' Save the control's name.
  293.         WindowName = MsgSpy1.ControlName
  294.  
  295.         ' Process the message...
  296.         Select Case MessageName
  297.  
  298.             Case "WM_SETFOCUS"
  299.                 ' Got focus message.
  300.                 SetLabel lblMessage, WindowName & " got focus"
  301.  
  302.             Case "WM_MOUSEMOVE"
  303.                 ' Save the control's tag.
  304.                 WindowTag = MsgSpy1.Control.Tag
  305.  
  306.         End Select
  307.  
  308.     Else ' MsgSpy1.IsForm = True
  309.  
  310.         ' Save the form's name and tag.
  311.         WindowName = MsgSpy1.FormName
  312.         WindowTag = MsgSpy1.Form.Tag
  313.  
  314.     End If
  315.     
  316.     ' If the mouse is over the control/form...
  317.     If (MessageName = "WM_MOUSEMOVE") Then
  318.  
  319.         ' Display the control's/form's name and the
  320.         ' mouse coordinates.
  321.         SetLabel lblMessage, "Mouse is over " & WindowName
  322.         SetLabel lblXPos, Str$(MsgSpy1.LOWORD)
  323.         SetLabel lblYPos, Str$(MsgSpy1.HIWORD)
  324.  
  325.         ' Display the control's/form's tag.
  326.         SetLabel lblControlTag, WindowTag
  327.  
  328.     End If
  329.  
  330. End Sub
  331.  
  332. Sub SetLabel (LabelControl As Label, ByVal LabelCaption As String)
  333.  
  334.     If (LabelControl.Caption <> LabelCaption) Then
  335.         LabelControl.Caption = LabelCaption
  336.     End If
  337.  
  338. End Sub
  339.  
  340.