列出所有窗口的標題

Option   Explicit  
   
  Public   Declare   Function   GetWindowText   Lib   "user32"   Alias   "GetWindowTextA"   (ByVal   hwnd   As   Long,   ByVal   lpString   As   String,   ByVal   cch   As   Long)   As   Long  
  Public   Declare   Function   EnumWindows   Lib   "user32"   (ByVal   lpEnumFunc   As   Long,   ByVal   lParam   As   Long)   As   Long  
  Public   Declare   Function   ShowWindow   Lib   "user32"   (ByVal   hwnd   As   Long,   ByVal   nCmdShow   As   Long)   As   Long  
  Public   Declare   Function   FindWindow   Lib   "user32"   Alias   "FindWindowA"   (ByVal   lpClassName   As   String,   ByVal   lpWindowName   As   String)   As   Long  
   
  Public   Const   SW_HIDE   =   0  
   
  Function   EnumWindowsProc(ByVal   hwnd   As   Long,   ByVal   lParam   As   Long)   As   Boolean  
   
          Dim   S   As   String               '   讀取   hWnd   的視窗標題  
          S   =   String(80,   0)  
          Call   GetWindowText(hwnd,   S,   80)  
          S   =   Left(S,   InStr(S,   Chr(0))   -   1)  
                  '   若視窗標題不爲空字串,則顯示在   ListBox   之中  
          If   Len(S)   >   0   Then   Form1.List1.AddItem   S  
          EnumWindowsProc   =   True   '   表示繼續列舉   hWnd  
  End   Function  
   
   
  窗體中:  
  Option   Explicit  
   
  Private Sub Command1_Click()
  Dim i     As Integer
          Dim hw     As Long
           
          List1.Clear
          EnumWindows AddressOf EnumWindowsProc, 0&         '測偵巳在執行的程序
          For i = 0 To List1.ListCount - 1
                  If List1.List(i) Like "CID*" Then'指定標題不列出
                        hw = FindWindow(vbNullString, List1.List(i))
                        Call ShowWindow(ByVal hw, ByVal SW_HIDE)
                  End If
          Next i
  End Sub
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章