我想用api关闭excel的一个子窗口,我的思路是这样的,先用FindWindow查到Excel的句柄,然后用查到的句柄,用api FindWindowEx查找子窗口句柄,然后发消息        SendMessage handle, WM_DESTROY, &O0, &O0
        SendMessage handle, WM_NCDESTROY, &O0, &O0关闭子窗口
代码如下:
'        'find childwindow named "filename"
'    handle = 0
'    phandle = FindWindow(vbNullString, "Microsoft Excel")
'    MsgBox winclass & "," & phandle
'    If phandle <> 0 Then
'        'find child window
'       ' handle = FindWindowEx(handle, 0, vbNullString, filename)
'       ' If handle <> 0 Then
'        'confirm
'            MsgBox LoadResString(GID_ERR_MSG_FILECLOSECONFIRM) & "(" & filenameorg & ")1", vbCritical, LoadResString(GID_STRMNUQVIC_WIRE)
'            'close window
'            SendMessage phandle, WM_DESTROY, &O0, &O0
'            SendMessage phandle, WM_NCDESTROY, &O0, &O0
'       ' End If
'    End If子窗口是关闭了,但是用spy++还是能找到子窗口,而且在vb中保存这个文件的时候还是提示这个文件已经被打开!不知道为什么,请教高手了!

解决方案 »

  1.   

    代码不对,应该是这个:
            'find childwindow named "filename"
        handle = 0
        phandle = FindWindow(vbNullString, "Microsoft Excel")
        MsgBox winclass & "," & phandle
        If phandle <> 0 Then
            'find child window
            handle = FindWindowEx(handle, 0, vbNullString, filename)
            If handle <> 0 Then
            'confirm
                MsgBox LoadResString(GID_ERR_MSG_FILECLOSECONFIRM) & "(" & filenameorg & ")1", vbCritical, LoadResString(GID_STRMNUQVIC_WIRE)
                'close window
                SendMessage handle, WM_DESTROY, &O0, &O0
                SendMessage handle, WM_NCDESTROY, &O0, &O0
            End If
        End If