home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / msg_spy / spydemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-05-26  |  10.4 KB  |  295 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. '-------------------------------------------------
  210. ' SpyDemo - a Message Spy Custom Control demo
  211. ' Note the possible uses of the following
  212. ' properties within the MsgReceieved event:
  213. '   MessageName - the name of the message
  214. '   IsControl   - whether message is for a control
  215. '   Control     - the actual subclassed control!!!
  216. '   ControlName - the subclassed control's name
  217. '   IsForm      - whether message is for a form
  218. '   Form        - the actual subclassed form!!!
  219. '   FormName    - the subclassed form's name
  220. '   HIWORD      - like HIWORD(LParam) in C/C++
  221. '   LOWORD      - like LOWORD(LParam) in C/C++
  222. ' Copyright (c) 1992-1994 Anton Software Limited.
  223. '-------------------------------------------------
  224. Option Explicit
  225. ' Const WM_SETFOCUS = &H7
  226. ' Const WM_MOUSEMOVE = &H200
  227. ' These constants are not needed, as the message
  228. ' name is provided directly. Nevertheless, for
  229. ' production code, or if performance is a major
  230. ' issue, it would be better to use them instead.
  231. ' e.g.
  232. '   If (Msg = WM_SETFOCUS) Then
  233. '   instead of
  234. '   If (MsgSpy1.MessageName = "WM_SETFOCUS") Then
  235. Sub chkSpyingEnabled_Click ()
  236.     ' Enable/disable the Message Spy control.
  237.     MsgSpy1.Enabled = chkSpyingEnabled.Value
  238. End Sub
  239. Sub Form_Load ()
  240.     ' Handle controls without hWnd properties.
  241.     On Error GoTo Handler
  242.     ' Subclass ALL the other controls on the form.
  243.     Dim i As Integer
  244.     For i = 0 To controls.Count - 1
  245.         MsgSpy1 = controls(i).hWnd
  246.     Next i
  247.     ' Subclass the form itself.
  248.     MsgSpy1 = frmMsgSpyDemo.hWnd
  249.     Exit Sub
  250. Handler:
  251.     ' Labels (etc.) don't have window handles!
  252.     Resume Next
  253. End Sub
  254. Sub MsgSpy1_MsgReceived (hWnd As Integer, Msg As Integer, WParam As Integer, LParam As Long)
  255.     ' The control or form name and tag.
  256.     Dim WindowName As String
  257.     Dim WindowTag  As String
  258.     ' Save the message name.
  259.     Dim MessageName As String
  260.     MessageName = MsgSpy1.MessageName
  261.     ' If the message is for a control...
  262.     If MsgSpy1.IsControl Then
  263.         ' Save the control's name.
  264.         WindowName = MsgSpy1.ControlName
  265.         ' Process the message...
  266.         Select Case MessageName
  267.             Case "WM_SETFOCUS"
  268.                 ' Got focus message.
  269.                 SetLabel lblMessage, WindowName & " got focus"
  270.             Case "WM_MOUSEMOVE"
  271.                 ' Save the control's tag.
  272.                 WindowTag = MsgSpy1.Control.Tag
  273.         End Select
  274.     Else ' MsgSpy1.IsForm = True
  275.         ' Save the form's name and tag.
  276.         WindowName = MsgSpy1.FormName
  277.         WindowTag = MsgSpy1.Form.Tag
  278.     End If
  279.     ' If the mouse is over the control/form...
  280.     If (MessageName = "WM_MOUSEMOVE") Then
  281.         ' Display the control's/form's name and the
  282.         ' mouse coordinates.
  283.         SetLabel lblMessage, "Mouse is over " & WindowName
  284.         SetLabel lblXPos, Str$(MsgSpy1.LOWORD)
  285.         SetLabel lblYPos, Str$(MsgSpy1.HIWORD)
  286.         ' Display the control's/form's tag.
  287.         SetLabel lblControlTag, WindowTag
  288.     End If
  289. End Sub
  290. Sub SetLabel (LabelControl As Label, ByVal LabelCaption As String)
  291.     If (LabelControl.Caption <> LabelCaption) Then
  292.         LabelControl.Caption = LabelCaption
  293.     End If
  294. End Sub
  295.