2008-09-22 55 views

回答

8

這將是PInvoke的城市......

你需要的PInvoke以下API在User32.dll中

的Win32 :: GetForegroundWindow ()in返回當前活動窗口的HWND。

/// <summary> 
/// The GetForegroundWindow function returns a handle to the foreground window. 
/// </summary> 
[DllImport("user32.dll")] 
static extern IntPtr GetForegroundWindow(); 

的Win32 :: GetWindowThreadProcessId(HWND,LPDWORD)返回給定的HWND

[DllImport("user32.dll", SetLastError=true)] 
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); 

的PID在C#

Process.GetProcessByID()採用PID來創建C#過程對象

processInstance.MainModule返回一個附有FileVersionInfo的ProcessModule。

+0

你能舉一個如何使用的例子嗎? – Danpe 2011-10-11 20:40:04

0

你能澄清你的問題?你的意思是你想要一個運行的程序,它會告訴你有關活動窗口中的程序的數據?或者你希望你的程序報告自己的版本?

你要找的信息是System.Reflection.Assembly。 (請參閱鏈接中的代碼示例。)

如何從外部程序獲取程序集?這一個我不知道......

相關問題