如何讓程式A的視窗跟隨程式B,與程式B在同一桌面Z序或高1級,即QQ或旺旺的自動回復客服軟體那種效果?
不要下面圖1的效果,要圖2.
圖1:

圖2:

因為客服程式A要占用程式B的部分界面以節約空間,所以不想讓其它軟體視窗會意外地插到兩者之間顯示,會顯得難得業余。用置頂的方法一直沒成功。請指教
示例代碼如下,運行后不知道子視窗跑哪去了
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32 " (ByVal hWnd As Long, lpRect As RECT) As Long
Dim OriPHwnd
'//讓程式表單剛好占滿記事本的客戶區
Private Sub Cmd打開記事本_Click()
Shell "notepad.exe", vbNormalFocus '打開記事本
End Sub
Private Sub Cmd覆寫_Click()
'//父視窗變數
Dim pHwnd As Long
Dim pRect As RECT
Dim pHeight As Long
Dim pWidth As Long
Me.Cls
pHwnd = FindWindow(vbNullString, Text1.Text)
If pHwnd = 0 Then
MsgBox "表單不存在 "
Else
GetWindowRect pHwnd, pRect
pHeight = pRect.Bottom - pRect.Top
pWidth = pRect.Right - pRect.Left
Me.Print "父視窗寬高:"
Me.Print "width = " & pWidth
Me.Print "height = " & pHeight
Me.Print "父視窗坐標:"
Me.Print "left,top = ( " & pRect.Left & ", " & pRect.Top & ") "
Me.Print "right,top = ( " & pRect.Right & ", " & pRect.Top & ") "
Me.Print "right,bottom = ( " & pRect.Right & ", " & pRect.Bottom & ") "
Me.Print "left,bottom = ( " & pRect.Left & ", " & pRect.Bottom & ") "
OriPHwnd = SetParent(Me.hWnd, pHwnd) '設定目標視窗為父視窗
Me.Top = pRect.Top
Me.Left = pRect.Left
Me.Width = pWidth
Me.Height = pHeight
End If
End Sub
Private Sub Cmd恢復_Click()
SetParent npad, oParent '恢復原有父子視窗關系
End Sub
界面如下
uj5u.com熱心網友回復:
頂下看看~~轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/106554.html
標籤:VB基礎類
上一篇:有人做過中行8583報文嗎
下一篇:求能控制視頻播放速度的軟體演算法
