将窗口置顶的方法:SetWindowPos、AttachThreadInput、SwitchToThisWindow
2014-12-05 14:03
387 查看
将窗口置顶的方法:SetWindowPos、AttachThreadInput、SwitchToThisWindow
[转]http://hi.baidu.com/neil_danky/item/f9dca0ca36a79811515058d3方法一:
使用定时器,然后在定时器响应函数中定时调用,SetWindowPos()函数,第一个参数写HWND_TOPMOST
方法二:
因为2000/XP改变了SetForegroundWindow的执行方式,不允许随便把窗口提前,打扰用户的工作。可以用附加本线程到最前面窗口的线程,从而欺骗windows。
AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL), GetCurrentThreadId(),TRUE);
SetForegroundWindow();
SetFocus();
AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL), GetCurrentThreadId(),FALSE);
方法三:
如何激活指定的窗口事件 ●
我们知道,Windows 9x/2000中SetForegroundWindow函数当用户正在操作其他窗口时是不能强制某个窗口为前景窗口的,而是激活窗口并调用FlashWindowEx函数来通知用户。但是很多实际情况要求将激活窗口的同时将创建这个窗口的线程置为前景状态。碰到这种情况我们可以使用USER32.DLL中的几个未公开API函数。
void SwitchToThisWindow (
HWND hWnd, // 被激活的窗口句柄
BOOL bRestore // 如果被极小化,则恢复窗口
);
必须动态加载这个函数。
typedef void (WINAPI *PROCSWITCHTOTHISWINDOW) (HWND, BOOL);
PROCSWITCHTOTHISWINDOW SwitchToThisWindow;
HMODULE hUser32 = GetModuleHandle("user32");
SwitchToThisWindow = ( PROCSWITCHTOTHISWINDOW)
GetProcAddress(hUser32, "SwitchToThisWindow");
接下来只要用任何现存窗口的句柄调用这个函数即可,第二个参数指定如果窗口极小化,是否恢复其原状态。
SwitchToThisWindow(hWnd, TRUE);
相关文章推荐
- 将窗口置顶的方法:SetWindowPos、AttachThreadInput、SwitchToThisWindow
- 将窗口置顶的方法:SetWindowPos、AttachThreadInput、SwitchToThisWindow
- 将后台窗口激活到前台的方法(使用AttachThreadInput和SetForegroundWindow两个API)
- 无焦点显示窗口解决方法 [转]AttachThreadInput的用法
- 一些窗口API函数,比如SetForegroundWindow,SwitchToThisWindow
- 设置活动窗口 AttachThreadInput SetForegroundWindow
- [转]无焦点显示窗口解决方法 [转]AttachThreadInput的用法
- VC获取其它程序窗口焦点方法 AttachThreadInput的用法
- SwitchToThisWindow
- web自动化测试第11步:切换窗口、frame、alert的新方法:switch_to包详解
- [Windows编程] 使用AttachThreadInput 来捕捉其它窗口的键盘输入
- [Windows编程] 使用AttachThreadInput 来捕捉其它窗口的键盘输入
- [Windows编程] 使用AttachThreadInput 来捕捉其它窗口的键盘输入
- 窗口置顶之SetWindowPos与SetForegroundWindow的区别
- (You don't have permission to access / on this server. )解决方法
- 移动项目开发笔记(模式窗口,非模式窗口用window.open造成Session丢失的解决方法)
- window.parent与window.opener的区别 javascript调用主窗口方法
- Delphi 窗口置顶的方法
- RBTray, Minimize window to tray || RBTray, 最小化 窗口 到 系统任务栏
- VC6编辑时提示This file has been modified outside of the source of editor.Do you want to reload it?解决方法