Reputation: 625
Can someone post the code that would allow me to read the postion and resolution of a specific window by its name, eg
private function findposition(byval windowtitle as string)
cheers Martin
I am using
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As IntPtr
Private Declare Function GetWindowRect Lib "user32" (ByVal _
hwnd As IntPtr, ByVal lpRect As Rectangle) As Integer
Dim lobbywindow As IntPtr = FindWindow("Appclass", "Appname")
Dim lobbyrectangle As New Rectangle
GetWindowRect(lobbywindow, lobbyrectangle)
Please assist in solving this since I get the error
A call to PInvoke function 'App!App.Form1::GetWindowRect' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Upvotes: 2
Views: 3927
Reputation: 2231
I assume it is for any window, even if external? Something like this may help:
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string className, string windowName);
[DllImport("user32.dll")]
private static extern int GetWindowRect(IntPtr hwnd, out Rectangle rect);
private void button2_Click(object sender, EventArgs e)
{
string className = "yourClassName";
string windowName = "yourWindowName";
Rectangle rect;
IntPtr hwnd = FindWindow(className, windowName);
GetWindowRect(hwnd, out rect);
}
Upvotes: 2
Reputation: 53
In this case you need to use the Windows API and a similar problem is being described here: http://www.activevb.de/tipps/vb6tipps/tipp0111.html
You would need to implement
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal _
hwnd As Long, lpRect As RECT) As Long
Upvotes: 2