⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 Visual.Basic.NET实用编程百例-47.6M.zip
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "枚举系统正在运行的程序"
   ClientHeight    =   3885
   ClientLeft      =   4470
   ClientTop       =   2715
   ClientWidth     =   5910
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3885
   ScaleWidth      =   5910
   Begin VB.CommandButton cmdActivate 
      Caption         =   "活动窗口"
      Height          =   300
      Left            =   4560
      TabIndex        =   8
      Top             =   645
      Width           =   1185
   End
   Begin VB.Timer tmrWinClass 
      Interval        =   100
      Left            =   4380
      Top             =   3360
   End
   Begin VB.CommandButton cmdRefresh 
      Caption         =   "刷新"
      Height          =   300
      Left            =   4560
      TabIndex        =   3
      Top             =   240
      Width           =   1200
   End
   Begin VB.ListBox lstOpenWindows 
      Height          =   1425
      Left            =   105
      Sorted          =   -1  'True
      TabIndex        =   2
      Top             =   660
      Width           =   4260
   End
   Begin VB.TextBox txtTitle 
      Height          =   285
      Left            =   105
      TabIndex        =   0
      Text            =   "窗口的标题:"
      Top             =   240
      Width           =   4260
   End
   Begin VB.Label lblCount 
      BackColor       =   &H80000004&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   240
      Left            =   120
      TabIndex        =   9
      Top             =   2520
      Width           =   5625
      WordWrap        =   -1  'True
   End
   Begin VB.Label lblClass 
      Caption         =   "Current Window Class:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   240
      Left            =   2040
      TabIndex        =   7
      Top             =   3240
      Width           =   3735
      WordWrap        =   -1  'True
   End
   Begin VB.Label Label3 
      Caption         =   "目前活动窗口的类别:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   480
      Left            =   120
      TabIndex        =   6
      Top             =   3240
      Width           =   1980
      WordWrap        =   -1  'True
   End
   Begin VB.Label Label2 
      Caption         =   "目前活动窗口的标题:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   225
      Left            =   120
      TabIndex        =   5
      Top             =   2760
      Width           =   1860
      WordWrap        =   -1  'True
   End
   Begin VB.Label lblCurrent 
      Caption         =   "Current Window:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   360
      Left            =   2055
      TabIndex        =   4
      Top             =   2760
      Width           =   3735
      WordWrap        =   -1  'True
   End
   Begin VB.Label lblClassName 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   375
      Left            =   120
      TabIndex        =   1
      Top             =   2100
      Width           =   5625
      WordWrap        =   -1  'True
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'  获得运行的程序
Private Sub cmdGetClass()
    Dim lngHand As Long
    Dim strName As String * 255
    Dim wndClass As wndClass
    Dim lngProcID As Long
    Dim rctTemp As RECT
    
    '  定位选中的窗口并获得其句柄
    lngHand = FindWindow(vbNullString, txtTitle.Text)
    
    '  获得窗口的信息
    GetClassName lngHand, strName, Len(strName)
    '  获得进程ID与窗口尺寸信息
    If Left$(strName, 1) = vbNullChar Then
         lblClassName.Caption = "Window Not Found!!!"
    Else
         lblClassName.Caption = "Class Name: " & strName
         GetWindowThreadProcessId lngHand, lngProcID
         GetWindowRect lngHand, rctTemp
    End If
    
End Sub

'  刷新信息
Private Sub cmdRefresh_Click()
    lstOpenWindows.Clear
    cmdGetClass
    lblCount.Caption = GetOpenWindowNames & " open Windows."
End Sub

'  激活选中的窗口
Private Sub cmdActivate_Click()
    Dim lngHand As Long

    '  找寻窗口
    If Trim$(lblClassName.Caption) = "" Then
         lngHand = FindWindow(vbNullChar, Trim$(txtTitle.Text))
    Else
         lngHand = FindWindow(Right$(lblClassName.Caption, (Len(lblClassName) - 12)), lstOpenWindows.Text)
    End If
    BringWindowToTop lngHand
End Sub

'  初始化
Private Sub Form_Load()
    SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    txtTitle.SelLength = Len(txtTitle.Text)
    lblCount.Caption = GetOpenWindowNames & " open Windows."
End Sub

Private Sub lstOpenWindows_Click()
    txtTitle.Text = lstOpenWindows.Text
    cmdGetClass
End Sub

'  定时属性标签中的信息
Private Sub tmrWinClass_Timer()
    Dim lngHand As Long
    Dim strName As String * 255
    
    lngHand = GetForegroundWindow
    GetWindowText lngHand, strName, Len(strName)
    lblCurrent.Caption = strName
    GetClassName lngHand, strName, Len(strName)
    lblClass.Caption = strName
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -