Windowsフォームアプリケーションを作成しました。そのアプリケーションの処理フォーム(現在のフォーム)を別のアプリケーションから取得したい。(最初の)アプリケーションは複数のフォームで構成されているため、どのフォームが処理中/アクティブであるかを知りたいです。
4199 次
2 に答える
0
別のアプリケーションを使用していますか?
では、アプリBはアプリAの処理フォームにアクセスする必要がありますか?そして、実行時には、AとBは別個のプロセスですよね?したがって、アプリAは、アプリBからアクセス可能な一種のリスニングソケットと、などのメソッドを使用したAPIを公開する必要がありますGetCurrentForm()
。そのため、アプリBはソケットにリクエストを送信し、レスポンスを取得できます。私はこのようなものを理解します。
参照:
于 2012-10-11T08:53:25.700 に答える
0
フォアグラウンドウィンドウ(ユーザーが現在作業しているウィンドウ)へのハンドルを取得します。
C#署名:
/// <summary>The GetForegroundWindow function returns a handle to the foreground window.</summary>
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
およびspinvokeのサンプルコード:
public ApplicationState AppState
{
get
{
Process[] processCollection = Process.GetProcessesByName(ProcessName);
if(processCollection != null && processCollection.Length >= 1 &&
processCollection[0] != null)
{
IntPtr activeWindowHandle = Win32.GetForegroundWindow();
//Optional int ProcessID;
//Optional Win32.GetWindowThreadProcessId(GetForegroundWindow(),out ProcessID)
foreach(Process wordProcess in processCollection)
{
//Optional if( ProcessID == wordProcess.Id ) return ApplicationState.Focused;
if(wordProcess.MainWindowHandle == activeWindowHandle)
{
return ApplicationState.Focused;
}
}
return ApplicationState.Running;
}
return ApplicationState.NotRunning;
}
}
于 2012-10-11T09:37:18.983 に答える