我有一個Windows CE嵌入式6.0應用程序,在後臺打開另一個應用程序,我想把另一個應用程序放在前面。我第一次嘗試使用第三方應用程序的MainWindowHandle SetParent,它沒有工作。然後,我再次在同一個MainWindowHandle上嘗試了SetActiveWindow,它沒有工作。這讓我相信MainWindowHandle已經搞亂了,當我在控制檯上打印它時,它始終爲0.這讓我想起了第一個問題:應用程序的開發人員忘記提及MainWindow是什麼可能嗎?或者它是在.NET中自動分配的?其次,現在這種方法失敗了,我嘗試使用EnumWindows,然後爲每個窗口獲取ID並將其與我所知道的我需要的程序的ID進行匹配。這給了我一個異常0x80131515說不支持「EnumWindows」。我已經從CoreDll導入EnumWindows就好了。第二個問題:可能是這個錯誤的原因是什麼?我究竟做錯了什麼?窗口前景無窗口把手
對不起!下面是一些代碼(假設VCProcess已經開始):
[DllImport("coredll.dll")]
static extern int EnumWindows(CallbackDef callback, int lParam);
[DllImport("coredll.dll")]
static extern int GetWindowThreadProcessId(IntPtr hWnd, int pid);
static void Main()
{
callBackPtr = new CallBackPtr(Report);
EnumWindows(callBackPtr, 0);
}
public static bool Report(int hwnd, int lParam)
{
int pid = 0;
GetWindowThreadProcessId(hWnd, pid);
if (pid == VCProcessId)
{
SetForegroundWindow(hWnd);
}
MessageBox.show("Window handle is "+hwnd);
return true;
}
問題是缺少重要的東西:代碼。 – user7116 2011-04-18 21:25:50