HWND hForeWnd = NULL;
HWND hWnd= FindWindow(NULL, "" );
DWORD dwForeID;
DWORD dwCurID;

hForeWnd =  GetForegroundWindow();
dwCurID =  GetCurrentThreadId();
dwForeID =  GetWindowThreadProcessId( hForeWnd, NULL );
AttachThreadInput( dwCurID, dwForeID, TRUE);
ShowWindow( hWnd, SW_SHOWNORMAL );
SetWindowPos( hWnd, HWND_TOPMOST, 0 , 0 , 0 , 0 , SWP_NOSIZE|SWP_NOMOVE );
SetWindowPos( hWnd, HWND_NOTOPMOST, 0 , 0 , 0 , 0 , SWP_NOSIZE|SWP_NOMOVE );
SetForegroundWindow( hWnd );
AttachThreadInput( dwCurID, dwForeID, FALSE);



设置当前某窗口为当前窗口,有几个步骤要做:
1.得到窗口句柄FindWindow
2.切换键盘输入焦点AttachThreadInput
3.显示窗口ShowWindow(有些窗口被最小化/隐藏了)
4.更改窗口的Zorder,SetWindowPos使之最上,为了不影响后续窗口的Zorder,改完之后,再还原
5.最后SetForegroundWindow


原文地址: