VB 程序 :如何让已经打开的Word文件前端显示?
我做了一个程序,运行VB时会打开一个指定的word文档;如果在运行VB时,这个word文档已经打开,但没有前端显示;如何在运行vb时,使该word文档前端显示?...
我做了一个程序,运行VB时 会打开一个指定的 word文档;如果在运行VB时,这个word文档已经打开,但没有前端显示;如何在运行vb时,使该word文档 前端显示?
展开
1个回答
展开全部
通过在打开之前进行窗口查找,如果查找成功,则调用SetWindowPos 置顶窗体,否则打开
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_SHOWWINDOW = &H40
Private Sub Form_Load()
Dim n As Long, m As Long
Dim sName As String
sName = "1.doc" & " - Microsoft Word" '这里的1.doc 改成你的文件名
n = FindWindow(vbNullString, sName)
If n <> 0 Then
m = SetWindowPos(n, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
Else
'打开Word代码
End If
End Sub
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_SHOWWINDOW = &H40
Private Sub Form_Load()
Dim n As Long, m As Long
Dim sName As String
sName = "1.doc" & " - Microsoft Word" '这里的1.doc 改成你的文件名
n = FindWindow(vbNullString, sName)
If n <> 0 Then
m = SetWindowPos(n, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
Else
'打开Word代码
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |