2008-12-04 43 views

回答

0

不知道这里发生了什么,但你有没有试图运行你的应用程序作为管理员?现在有很多关于非管理应用程序能够在整个系统的其他部分看到的限制。

5

API函数GetForegroundWindow让您获得顶层窗口的句柄,而不是进程ID。 那么你用什么其他函数从你从GetForegroundWindow获得的窗口句柄中获得进程ID?

这将让你在前台窗口的窗口句柄:一个给定的窗口句柄

[DllImport("user32", SetLastError = true)] 
    public static extern int GetForegroundWindow(); 

这将让你的进程ID(PID在taskmgr):

[DllImport("user32", SetLastError = true)] 
    public static extern int GetWindowThreadProcessId(int hwnd, ref int lProcessId); 

    public static int GetProcessThreadFromWindow(int hwnd) { 
     int procid = 0; 
     int threadid = GetWindowThreadProcessId(hwnd, ref procid); 
     return procid; 
    } 

这如果你对你的问题做出回应,那么它就会很好,所以它在这个论坛上有一定的价值。