|
我们在对Access深入编程时,有时需要使用API FindWindow来搜索系统相关的窗体,如Access Excel Outlook等自身的窗体,而FindWindow是通过窗体类名来搜索的,所以我们必须先预先知道Office各组件的窗体的类名,以下是常见的Office组件的的类名,更高的Office版本也差不多
应用程序 | 类名-Class Name | Access 97 | OMain | Access 2000 | OMain | Access XP | OMain | Excel 97 | XLMAIN | Excel 2000 | XLMAIN | Excel XP | XLMAIN | FrontPage 2000 | FrontPageExplorerWindow40 | FrontPage XP | FrontPageExplorerWindow40 | Outlook 97 | rctrl_renwnd32 | Outlook 98 | rctrl_renwnd32 | Outlook 2000 | rctrl_renwnd32 | Outlook XP | rctrl_renwnd32 | PowerPoint 95 | PP7FrameClass | PowerPoint 97 | PP97FrameClass | PowerPoint 2000 | PP9FrameClass | PowerPoint XP | PP10FrameClass | Project 98 | JWinproj-WhimperMainClass | Project 2000 | JWinproj-WhimperMainClass | Visual Basic Editor | wndclass_desked_gsk | Word 97 | OpusApp | Word 2000 | OpusApp | Word XP | OpusApp |
获取Access的 类名是 OMain
获取Excel的,类名是XLMAIN
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Caption = "New Caption Supplied by Program"
Dim hWndXl As Long
hWndXl = FindWindow("XLMAIN", xlApp.Caption)
xlApp.Caption = Empty 'Set the original caption back
xlApp.Visible = True
MsgBox "hWndXl ( " & Hex(hWndXl) & " ) contains the Window Handle " & _
"of the Excel application created by this program." & vbCr & _
"You can use this Window Handle in various Win 32 APIs, " & _
"such as SetForeGroundWindow," & vbCr & _
"which require a Window Handle parameter to be supplied." & vbCr _
& vbCr & "All Done. Click OK to close Excel.", vbMsgBoxSetForeground
xlApp.Quit
Set xlApp = Nothing
End Sub
而PPT则比较特殊,不同版本有所不同
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim PptApp As Object
Set PptApp = CreateObject("PowerPoint.Application")
PptApp.Visible = True
Dim hWndPpt As Long
' Replace the frame_class place holder with one of the following:
' PP12FrameClass for PowerPoint 2007
' PP11FrameClass for PowerPoint 2003
' PP10FrameClass for PowerPoint 2002
' PP9FrameClass for PowerPoint 2000
' PP97FrameClass for PowerPoint 97
hWndPpt = FindWindow("frame_class", 0)
MsgBox "hWndPpt ( " & Hex(hWndPpt) & " ) contains the Window Handle " & _
"of the PowerPoint application created by this program." & vbCr & _
"You can use this Window Handle in various Win 32 APIs, such " & _
"as SetForeGroundWindow," & vbCr & _
"which require a Window Handle parameter to be supplied." & vbCr & _
vbCr & "All Done. Click OK to close PowerPoint.", vbMsgBoxSetForeground
PptApp.Quit
Set PptApp = Nothing
End Sub
写完才发现,以前也写过一篇有关Office窗口类名的文章
可参考这里: http://www.office-cn.net/thread-66562-1-1.html
|
|