首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

关于SetParent的应用,该怎么处理

2012-03-04 
关于SetParent的应用PublicFunctiongetExcelHwnd(AppExcelAsExcel.Application)AsLongDimVarPid,VarHwndAs

关于SetParent的应用
Public   Function   getExcelHwnd(AppExcel   As   Excel.Application)   As   Long
        Dim   VarPid,   VarHwnd   As   Long
        Dim   VarTid   As   Long
        Dim   Str1   As   String
        VarHwnd   =   FindWindow(vbNullString,   vbNullString)
        'VarTid   =   GetWindowThreadProcessId(VarHwnd,   VarPid)
        Do   While   VarHwnd   <>   0
                'GetWindowThreadProcessId   VarHwnd,   VarPid
                Str1   =   Space(100)
                GetWindowText   VarHwnd,   Str1,   80
                If   InStr(1,   Str1,   AppExcel.Caption)   >   0   Then
                        Debug.Print   CStr(VarPid)   &   "   --   "   &   CStr(VarHwnd)   &   "   --   "   &   Trim(Str1)
                        getExcelHwnd   =   VarHwnd
                        Exit   Do
                End   If
                VarHwnd   =   GetWindow(VarHwnd,   GW_HWNDNEXT)
        Loop
End   Function
可以找到正确的Hwnd,但是用SetParent后,有时得到的不是整个Excel界面,而且不能编辑,不知该如何处理

[解决办法]
回复人:VBAdvisor(Sunlight) ( 四级(中级)) 信誉:100 2007-06-14 12:48:22 得分:0

FindWindow
是FindWindowA的别名(Alias)
The FindWindow function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows.

FindWindowEx
是FindWindowExA的别名(Alias)
The FindWindowEx function retrieves the handle to a window whose class name and window name match the specified strings. The function searches child windows, beginning with the one following the given child window.

Excel Class is "XLMAIN "
Word Class is "OpusApp "
Powerpoint Class is "PP11FrameClass "
Access Class is "OMain "
Outlook Class is "rctrl_renwnd32 "

of123() ( 四星(高级)) 信誉:125 2007-6-13 19:26:05 得分:0

Public Declare Function FindWindow Lib "user32 " Alias "FindWindowA " (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function FindWindowEx Lib "user32 " Alias "FindWindowExA " (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Dim hW As Long

hW = FindWindow( "OpusApp ", vbNullString)
If hW Then MsgBox "WinWord.exe is running "

hW = FindWindow( "PP11FrameClass ", vbNullString)
If hW Then MsgBox "POWERPNT.exe is running "
[解决办法]
你是要GetWindow,还是GetWindowText 还是SetParent???
[解决办法]
俺 要分

热点排行