Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Const SW_SHOWNORMAL = 1 Const WM_CLOSE = &H10 Const gcClassnameMSWord = "OpusApp" Const gcClassnameMSExcel = "XLMAIN" Const gcClassnameMSIExplorer = "IEFrame" Const gcClassnameMSVBasic = "wndclass_desked_gsk" Const gcClassnameNotePad = "Notepad" Const gcClassnameMyVBApp = "ThunderForm" Private Sub Form_Load() 'KPD-Team 1998 'URL: http://www.allapi.net/ 'E-Mail: [email protected] Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String 'Ask for a Window title Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match") 'Search the window WinWnd = FindWindow(vbNullString, Ret) If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub 'Show the window ShowWindow WinWnd, SW_SHOWNORMAL 'Create a buffer lpClassName = Space(256) 'retrieve the class name RetVal = GetClassName(WinWnd, lpClassName, 256) 'Show the classname MsgBox "Classname: " + Left$(lpClassName, RetVal) 'Post a message to the window to close itself PostMessage WinWnd, WM_CLOSE, 0&, 0& End Sub
【VB声明】 Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long【说明】 控制窗口的可见性(在vb里使用:针对vb窗体及控件,请使用对应的vb属性) 【返回值】 Long,如窗口之前是可见的,则返回TRUE(非零),否则返回FALSE(零) 【参数表】 hwnd ----------- Long,窗口句柄,要向这个窗口应用由nCmdShow指定的命令 nCmdShow ------- Long,为窗口指定可视性方面的一个命令。请用下述任何一个常数 SW_HIDE 隐藏窗口,活动状态给令一个窗口 SW_MINIMIZE 最小化窗口,活动状态给令一个窗口 SW_RESTORE 用原来的大小和位置显示一个窗口,同时令其进入活动状态 SW_SHOW 用当前的大小和位置显示一个窗口,同时令其进入活动状态 SW_SHOWMAXIMIZED 最大化窗口,并将其激活 SW_SHOWMINIMIZED 最小化窗口,并将其激活 SW_SHOWMINNOACTIVE 最小化一个窗口,同时不改变活动窗口 SW_SHOWNA 用当前的大小和位置显示一个窗口,不改变活动窗口 SW_SHOWNOACTIVATE 用最近的大小和位置显示一个窗口,同时不改变活动窗口 SW_SHOWNORMAL 与SW_RESTORE相同
Private Const SW_SHOWMAXIMIZED = 3 Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Sub Command1_Click() Shell "Sol.exe", 1 End Sub Private Sub Command2_Click() Dim lpClassName As String, lpCaption As String Dim Handle As Long Dim RetVal As LonglpClassName = "Solitaire" lpCaption = "纸牌"Handle = FindWindow(vbNullString, lpCaption)ShowWindow Handle, SW_SHOWMAXIMIZEDEnd Sub
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
'Show the window
ShowWindow WinWnd, SW_SHOWNORMAL
'Create a buffer
lpClassName = Space(256)
'retrieve the class name
RetVal = GetClassName(WinWnd, lpClassName, 256)
'Show the classname
MsgBox "Classname: " + Left$(lpClassName, RetVal)
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub
Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long【说明】
控制窗口的可见性(在vb里使用:针对vb窗体及控件,请使用对应的vb属性) 【返回值】
Long,如窗口之前是可见的,则返回TRUE(非零),否则返回FALSE(零) 【参数表】
hwnd ----------- Long,窗口句柄,要向这个窗口应用由nCmdShow指定的命令 nCmdShow ------- Long,为窗口指定可视性方面的一个命令。请用下述任何一个常数
SW_HIDE
隐藏窗口,活动状态给令一个窗口
SW_MINIMIZE
最小化窗口,活动状态给令一个窗口
SW_RESTORE
用原来的大小和位置显示一个窗口,同时令其进入活动状态
SW_SHOW
用当前的大小和位置显示一个窗口,同时令其进入活动状态
SW_SHOWMAXIMIZED
最大化窗口,并将其激活
SW_SHOWMINIMIZED
最小化窗口,并将其激活
SW_SHOWMINNOACTIVE
最小化一个窗口,同时不改变活动窗口
SW_SHOWNA
用当前的大小和位置显示一个窗口,不改变活动窗口
SW_SHOWNOACTIVATE
用最近的大小和位置显示一个窗口,同时不改变活动窗口
SW_SHOWNORMAL
与SW_RESTORE相同
ShowWindow (hwnd,SW_SHOWMAXIMIZED)
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Shell "Sol.exe", 1
End Sub
Private Sub Command2_Click()
Dim lpClassName As String, lpCaption As String
Dim Handle As Long
Dim RetVal As LonglpClassName = "Solitaire"
lpCaption = "纸牌"Handle = FindWindow(vbNullString, lpCaption)ShowWindow Handle, SW_SHOWMAXIMIZEDEnd Sub