设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2400|回复: 0
打印 上一主题 下一主题

[API] Office的各个组件的窗体的类名大全

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2015-6-8 09:53:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我们在对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
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-19 17:21 , Processed in 0.090427 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表