2010-10-07 30 views
0

我非常努力地找到一種方法來提出另一個程序窗口。如何將不屬於該程序的另一個窗口向前推進

例如,我使用FindWindow來查找記事本的句柄。然後我嘗試使用SetWindowPos(hWnd,0,0,0,0,0,SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE)使窗口前進;

但它只是不工作! ShowWindow也沒有!

你可以請幫忙,也許讓我看一段代碼?

感謝

回答

-2

說不上來,如果這是同樣的事情或沒有,但在開發Windows某些時候微軟增加了一些太聰明,通過半「反彈出」代碼,將阻止一個程序,不重點是從最小化它的窗口...而是,窗口在程序欄中的入口只會閃爍。也許有類似的邏輯阻止非前景節目向前發展?

在任何情況下,這裏是一些代碼來試試,可能會或可能不會幫助:

// Check to see if we are the foreground thread 
DWORD foregroundThreadID = GetWindowThreadProcessId(GetForegroundWindow(), NULL); 
DWORD ourThreadID = GetCurrentThreadId(); 

// If not, attach our thread's 'input' to the foreground thread's 
if (foregroundThreadID != ourThreadID) AttachThreadInput(foregroundThreadID, ourThreadID, TRUE); 

// Bring our window to the foreground 
SetForegroundWindow(hWnd); 

// If we attached our thread, detach it now 
if (foregroundThreadID != ourThreadID) AttachThreadInput(foregroundThreadID, ourThreadID, FALSE); 

// Force our window to redraw 
InvalidateRect(hWnd, NULL, TRUE); 
+1

嗯,你不必爲MSFT的制止了「推窗力度不夠升值在用戶的臉上「的態度。真丟臉。 – 2010-10-07 23:51:23

+0

我對此有很多讚賞。我只是覺得他們應該將SetForegroundWindow()函數重命名爲SetForegroundWindowButNotUnlessIAddSomeExtraMumboJumboToShowThatIReallyMeanIt(),這樣它的名字才能準確地反映它的行爲。 – 2010-10-08 01:55:06

相關問題