菜鸟求教,如何让窗口弹到最前面?

bleem2014 2014-11-21 04:47:33
在键盘钩子里按F10隐藏窗口F9弹出
但是窗口有时候会弹不出来,只能在任务栏上闪烁,非得鼠标点一下
请教高手


if (p->vkCode == 120) {
ShowWindow(main_hwnd, SW_SHOW);
SetForegroundWindow(main_hwnd);
//SetWindowPos(main_hwnd,HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE | SWP_NOSIZE| SWP_SHOWWINDOW );
//BringWindowToTop(main_hwnd);
if(1){
typedef void (WINAPI *PSWITCHTOTHISWINDOW) (HWND,BOOL);
PSWITCHTOTHISWINDOW SwitchToThisWindow;
HMODULE hUser32=GetModuleHandle("user32");
SwitchToThisWindow=(PSWITCHTOTHISWINDOW)GetProcAddress(hUser32,"SwitchToThisWindow");
//现在就可以使用此函数了
SwitchToThisWindow(main_hwnd,0);
}
//SetFocus(main_hwnd);
}
if (p->vkCode == 121) {
ShowWindow(main_hwnd, SW_HIDE);
}
...全文
475 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bleem2014 2014-11-24
  • 打赏
  • 举报
回复
HWND_TOPMOST确实可以让窗口弹出 但窗口是灰的 还是需要鼠标点一下
赵4老师 2014-11-24
  • 打赏
  • 举报
回复
SetActiveWindow The SetActiveWindow function activates a window. The window must be associated with the calling thread's message queue. HWND SetActiveWindow( HWND hWnd // handle to window to activate ); Parameters hWnd Handle to the top-level window to be activated. Return Values If the function succeeds, the return value is the handle to the window that was previously active. If the function fails, the return value is NULL. To get extended error information, callGetLastError. Remarks The SetActiveWindow function activates a window, but not if the application is in the background. The window will be brought into the foreground (top of Z order) if the application is in the foreground when it sets the activation. If the window identified by the hWnd parameter was created by the calling thread, the active window status of the calling thread is set to hWnd. Otherwise, the active window status of the calling thread is set to NULL. The SetForegroundWindow window function, on the other hand, activates a window and forces it into the foreground. An application should only call SetForegroundWindow if it needs to display critical errors or information that needs the user's immediate attention . By using theAttachThreadInput function, a thread can attach its input processing to another thread. This allows a thread to call SetActiveWindow to activate a window associated with another thread's message queue. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winuser.h. Import Library: Use user32.lib. See Also Keyboard Input Overview, Keyboard Input Functions, GetActiveWindow, SetForegroundWindow, WM_ACTIVATE SetForegroundWindow The SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user. The system assigns a slightly higher priority to the thread that created the foreground window than it does to other threads. BOOL SetForegroundWindow( HWND hWnd // handle to window to bring to foreground ); Parameters hWnd Handle to the window that should be activated and brought to the foreground. Return Values If the window was brought to the foreground, the return value is nonzero. If the window was not brought to the foreground, the return value is zero. Remarks The foreground window is the window at the top of the Z order. It is the window that the user is working with. In a preemptive multitasking environment, you should generally let the user control which window is the foreground window. Windows NT 5.0 and later: An application cannot force a window to the foreground while the user is working with another window. Instead, SetForegroundWindow will activate the window (see SetActiveWindow) and call theFlashWindowEx function to notify the user. Windows CE: The thread that owns the window is not given a priority boost. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winuser.h. Import Library: Use user32.lib. See Also Windows Overview, Window Functions,FlashWindowEx, GetForegroundWindow, SetActiveWindow
孤影品茗 2014-11-24
  • 打赏
  • 举报
回复
引用 2 楼 bleem2014 的回复:
HWND_TOPMOST确实可以让窗口弹出 但窗口是灰的 还是需要鼠标点一下
那就再加一个SetFocus()
bleem2014 2014-11-24
  • 打赏
  • 举报
回复
再详细说一下这个程序的BUG Step1.启动程序,让窗口保持在最前面 Step2.切换到别的程序窗口(这步很重要,很重要) Step3.按F10让窗口隐藏 Step4.按F9,窗口弹不出来
starytx 2014-11-22
  • 打赏
  • 举报
回复
SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧