Office中国论坛/Access中国论坛

标题: Office的各个组件的窗体的类名大全 [打印本页]

作者: tmtony    时间: 2015-6-8 09:53
标题: Office的各个组件的窗体的类名大全
我们在对Access深入编程时,有时需要使用API FindWindow来搜索系统相关的窗体,如Access Excel Outlook等自身的窗体,而FindWindow是通过窗体类名来搜索的,所以我们必须先预先知道Office各组件的窗体的类名,以下是常见的Office组件的的类名,更高的Office版本也差不多

应用程序类名-Class Name
Access 97OMain
Access 2000OMain
Access XPOMain
Excel 97XLMAIN
Excel 2000XLMAIN
Excel XPXLMAIN
FrontPage 2000FrontPageExplorerWindow40
FrontPage XPFrontPageExplorerWindow40
Outlook 97rctrl_renwnd32
Outlook 98rctrl_renwnd32
Outlook 2000rctrl_renwnd32
Outlook XPrctrl_renwnd32
PowerPoint 95PP7FrameClass
PowerPoint 97PP97FrameClass
PowerPoint 2000PP9FrameClass
PowerPoint XPPP10FrameClass
Project 98JWinproj-WhimperMainClass
Project 2000JWinproj-WhimperMainClass
Visual Basic Editorwndclass_desked_gsk
Word 97OpusApp
Word 2000OpusApp
Word XPOpusApp


获取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





欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3