窗口置顶

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 


原文地址:https://www.cnblogs.com/ziwuge/archive/2012/01/06/2315342.html



猜你喜欢

转载自blog.csdn.net/huanongying131/article/details/78885875
今日推荐