javaw.exeプロセスに添付された特定のウィンドウのサイズと位置を取得しようとしています。GetWindowRectはNullReferenceExceptionを返します
悲しいことに、GetWindowRectは「NullReferenceException」というエラーをスローします。チェックしたところ、引数はどれも== nullではありません。
NB.Attach(Process.GetProcessesByName("javaw")[0]);
使用サンプル:
public static void Attach(Process process)
{
FocusProcess = process;
FocusWindow = FindWindow(null, process.MainWindowTitle);
}
public static int[] GetWindowPosition()
{
WindowRect rect = new WindowRect();
Console.WriteLine(FocusProcess == null);
Console.WriteLine(FocusProcess.MainWindowHandle == null);
Console.WriteLine(rect==null);
GetWindowRect(FocusProcess.MainWindowHandle, out rect);
if (rect.Top != 0)
{
return new int[] { rect.Left, rect.Top };
}
return new int[] { 0, 0 };
}
プロセスを添付する静的関数を実行
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr handle, out WindowRect rect);
[StructLayout(LayoutKind.Sequential)]
private class WindowRect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
:ここ
はコード呼び出すサンプルの一部です
事前に感謝します。ネイティブ関数の使用については、私は全く経験がありません。
これは完全なコードですか? 'NullReferenceException'が.Net例外であり、' GetWindowRect'がそれを投げないので、確かにここに欠けているものがあります。 – DavidG
GetWindowRect()を使用しようとすると、完全なコードとエラーが発生します。 – Netheous
'FocusProcess'はここでは定義されていないので、それはできません。あなたは例外の完全なスタックトレースを投稿できますか? – DavidG