home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / numwin20 / generapp.frm next >
Text File  |  1993-12-23  |  6KB  |  197 lines

  1. VERSION 2.00
  2. Begin Form NumWin_Form 
  3.    Caption         =   "NumWin  Test"
  4.    ClientHeight    =   5145
  5.    ClientLeft      =   1215
  6.    ClientTop       =   1860
  7.    ClientWidth     =   5010
  8.    Height          =   5835
  9.    Left            =   1155
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5145
  12.    ScaleWidth      =   5010
  13.    Top             =   1230
  14.    Width           =   5130
  15.    Begin Numwin NumWin1 
  16.       Left            =   720
  17.       Top             =   120
  18.    End
  19.    Begin CommandButton BTN_Exit 
  20.       Caption         =   "Exit"
  21.       Height          =   375
  22.       Left            =   3720
  23.       TabIndex        =   2
  24.       Top             =   240
  25.       Width           =   1215
  26.    End
  27.    Begin TextBox Text2 
  28.       Height          =   4215
  29.       Left            =   120
  30.       MultiLine       =   -1  'True
  31.       ScrollBars      =   3  'Both
  32.       TabIndex        =   1
  33.       Top             =   840
  34.       Width           =   4815
  35.    End
  36.    Begin CommandButton Btn_Refresh 
  37.       Caption         =   "Refresh"
  38.       Height          =   375
  39.       Left            =   2400
  40.       TabIndex        =   0
  41.       Top             =   240
  42.       Width           =   1215
  43.    End
  44.    Begin Menu nmu_File 
  45.       Caption         =   "&File"
  46.       Begin Menu mnu_Exit 
  47.          Caption         =   "&Exit"
  48.       End
  49.    End
  50.    Begin Menu mnu_Edit 
  51.       Caption         =   "&Edit"
  52.       Begin Menu mnu_Cut 
  53.          Caption         =   "Cu&t"
  54.       End
  55.       Begin Menu mnu_Copy 
  56.          Caption         =   "&Copy"
  57.       End
  58.       Begin Menu mnu_Paste 
  59.          Caption         =   "&Paste"
  60.       End
  61.       Begin Menu mnu_submenu 
  62.          Caption         =   "SubMenu"
  63.          Begin Menu mnu_submenu1 
  64.             Caption         =   "SubMenu 1"
  65.          End
  66.          Begin Menu mnu_submenu2 
  67.             Caption         =   "SubMenu 2"
  68.          End
  69.       End
  70.    End
  71. End
  72. Option Explicit
  73.  
  74. ' The Action parameter
  75. Const NUMWIN_REFRESH = 10
  76.  
  77. ''
  78. '' some of the APIs which might be useful
  79. Declare Function GetClassName Lib "User" (ByVal hWnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
  80.  
  81. '' a constant for use with GetWindowWord and GetModuleFileName
  82. Const GWW_HINSTANCE = (-6)
  83. Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
  84. Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String, ByVal nSize As Integer) As Integer
  85.  
  86. Sub BTN_Exit_Click ()
  87.     mnu_Exit_Click
  88. End Sub
  89.  
  90. Sub Btn_Refresh_Click ()
  91. ' PURPOSE: Fill the array with current values
  92. '''''''''''''''''''''''''''''''''''''''''''''''''
  93.     
  94.     Text2.Text = ""
  95.     NumWin1.Action = NUMWIN_REFRESH '10
  96.  
  97. End Sub
  98.  
  99. Sub Form_Load ()
  100. ' PURPOSE: Just load
  101. ''''''''''''''''''''''''''''''''''
  102.     If Me.windowstate = 0 Then
  103.         top = 0
  104.         Left = 0
  105.     End If
  106.  
  107. End Sub
  108.  
  109. Sub Form_Resize ()
  110.     If Me.windowstate = 0 Then
  111.         Me.Height = 5815
  112.         Me.Width = 5175
  113.     End If
  114. End Sub
  115.  
  116. Sub mnu_Exit_Click ()
  117.     End
  118. End Sub
  119.  
  120. Sub NumWin1_NumWinClick (Count As Integer)
  121. ' PURPOSE: Put all the window handles and window text in the text box
  122. ' COMMENTS: Three arrays are passed back from NUMWIN.VBX
  123. '           They are;
  124. '           1. HwndArray the hwnds of all windows.
  125. '           2. HwndParArray the parent hwnds.
  126. '               if zero then hwnd is a top level window.
  127. '           3. WinTextArray the window text appearing in
  128. '               the window bar or control caption.
  129. '           The variable Count returned is the total window count
  130. '
  131. '           Shows some of the things that can be done with APIs.
  132. '           Declares are in this module.
  133. '
  134. '           This test print out is somewhat long and in much more detail
  135. '           than is normally needed. Choose the data appropiate for your
  136. '           program.
  137. '
  138. ' IMPORTANT ... IMPORTANT ... IMPORTANT
  139. '
  140. '   DATA IN THE ARRAYS IS ONLY VALID IN THIS SUB ROUTINE.
  141. '
  142. '   ALWAYS USE THE NUMWINx.REFRESH COMMAND IMMEDIATELY BEFORE ACCESSING DATA.
  143. '   WINDOWS CAN UPDATE THE SCREEN AT ANY TIME AND DESTROY OR CREATE NEW WINDOWS.
  144. '   CAUTION IS ADVISED WHEN USING THIS DATA. IT IS PRUDENT PROGRAMMING PRACTICE TO
  145. '   ALWAYS TEST FOR VALIDITY BEFORE USE TO PREVENT PROBLEMS FROM OCCURRING.
  146. '   THE WINDOWS API IsWindow() CAN PERFORM A HWND VALIDITY TEST.
  147. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  148. Dim Msg As String
  149. Dim CRLF As String
  150. Dim ndex As Integer
  151. Dim cbBuf As String * 64
  152. Dim cbCount As Integer
  153. Dim hInstance As Integer
  154.  
  155.     '' inits
  156.     CRLF = Chr$(13) + Chr$(10)
  157.     Msg = ""
  158.     '' go through all the hWnds
  159.     For ndex = 1 To Count
  160.         ''
  161.         '' the hWnd
  162.         Msg = Msg + "hWnd = " + Str$(NumWin1.HwndArray(ndex)) + CRLF
  163.         ''
  164.         '' parent of window
  165.         '' if hwnd parent = 0 then it is a top level window
  166.         '' use this technique to find all top level windows
  167.         If NumWin1.HwndParArray(ndex) = 0 Then
  168.             Msg = Msg + "Parent = " + "[TOPLEVEL WINDOW]" + CRLF
  169.             ''
  170.             '' this is for top level windows only
  171.             hInstance = GetWindowWord(NumWin1.HwndArray(ndex), GWW_HINSTANCE)
  172.             cbCount = GetModuleFileName(hInstance, cbBuf, 64)
  173.             cbBuf = Left$(cbBuf, cbCount)
  174.             Msg = Msg + "ModuleName = " + cbBuf + CRLF
  175.         Else
  176.             Msg = Msg + "Parent = " + Str$(NumWin1.HwndParArray(ndex)) + CRLF
  177.         End If
  178.         ''
  179.         '' the class name contains additional information about the window
  180.         '' use the API call to get the ClassName
  181.         cbCount = GetClassName(NumWin1.HwndArray(ndex), cbBuf, 64)
  182.         cbBuf = Left$(cbBuf, cbCount)
  183.         Msg = Msg + "Class Name = " + cbBuf + CRLF
  184.         ''
  185.         '' window text
  186.         If Len(NumWin1.WinTextArray(ndex)) <> "0" Then
  187.             Msg = Msg + "Text = " + NumWin1.WinTextArray(ndex) + CRLF + CRLF
  188.         Else
  189.             Msg = Msg + "Text = <NONE>" + CRLF + CRLF
  190.         End If
  191.     Next ndex
  192.  
  193.     Text2.Text = "Number of Windows = " + Str$(Count) + CRLF + CRLF + Msg
  194.  
  195. End Sub
  196.  
  197.