VS 2017 の VB.NET で WinForm プロジェクトを作成し、.NET でFreeRDPのインスタンスを開いていますSplitContainer2.Panel1
。これは問題なく機能しますが、最初に FreeRDP ウィンドウに収まるようにフォームをスケーリングしたいと思います。これを行うには、まず FreeRDP インスタンスのサイズを知る必要があります。
残念ながら、私が行ったすべての試みは何も返しません。Windows API から使用しようとしてGetClientRect()
いますが、返されるのは 0 だけです (または何もないと思います)。API呼び出しで遊んだのはこれが初めてなので、何が間違っているのかわかりません。VS で壊れた正しいハンドルがあることを確認しました
(これらのスケーリングが不十分な場合は申し訳ありません。スケーリングされた4kで判断するのは難しいです)
Spy++ との比較
したがって、正しい hWnd ハンドルがあることを確認しましたが、 a を呼び出してGetClientRect()
も何も返されません。
関連するコードは次のとおりです。
Dim rdpWnd As New IntPtr
Dim proc As New Process
Private Declare Auto Function GetClientRect Lib "user32.dll" ( _
ByVal hWnd As IntPtr, ByVal lpRect As RECT) As Boolean
<StructLayout(LayoutKind.Sequential)>
Private Structure RECT
Private Left As Short
Private Top As Short
Private Right As Short
Private Bottom As Short
End Structure
Private Sub Form_Load( _
sender As Object, e As EventArgs) Handles MyBase.Load
Dim startInfo As New ProcessStartInfo With {
.FileName = """" & appPath & "\console\wfreerdp.exe""",
.Arguments = "/parent-window:" & SplitContainer2.Panel1.Handle.ToString() & " /t:" & vmId
}
proc = Process.Start(startInfo)
rdpWnd = getWindowHandle(Me.Text, vmId)
End Sub
Private Function getWindowHandle(caption As String, Guid As String) As IntPtr
Dim hWnd As IntPtr = FindWindow(Nothing, caption)
If hWnd.Equals(IntPtr.Zero) Then
Return Nothing
End If
.......
Dim hWndRdp As IntPtr = FindWindowEx(hWndChild4, IntPtr.Zero, Nothing, Guid)
If hWndRdp.Equals(IntPtr.Zero) Then
Return Nothing
End If
Return hWndRdp
End Function
この時点で、自分のフォームで Hyper-V VM のコンソール ウィンドウを見ていますが、ことわざの Button1 をクリックすると...
Private Sub Button1_MouseClick( _
sender As Object, e As MouseEventArgs) Handles Button1.MouseClick
Dim myRect As New RECT
GetClientRect(rdpWnd, myRect)
Dim rdpWndWidth As Short = myRect.Right - myRect.Left
Dim rdpWndHeight As Short = myRect.Bottom - myRect.Top
MsgBox("Width: " & rdpWndWidth & vbCrLf &
"Height: " & rdpWndHeight)
End Sub
MsgBox()
リターン:
そしてVSの変数:
私は何を間違っていますか?Spy++ ができることを明確に確認できるのに、クライアントのサイズを取得できないのはなぜですか? 私はこれを理解するために何時間も費やしました.このマイルストーンをチェックオフするための支援に感謝します. 何か別のものに移り、すぐに入手できない場合は後で戻ってきます。