zl程序教程

您现在的位置是:首页 >  前端

当前栏目

将窗口移动到前端, BringWindowToTop() 的问题

前端 移动 窗口 问题
2023-09-27 14:27:57 时间

有一段代码,是在我们的应用程序中将其他应用程序的窗口移动到最前端,当我们的程序在 Vista 下运行的时候遇到了些问题,有时候被移动窗口只是闪动任务栏上的按钮,并未能将窗口移动到前方来. 研究了一下,发现是否能够移动成功和当前自身进程所附加的输入上下文有关, 参见

None.gifWIN32 API AttachThreadInput()dot.gif

 
写了个 MyBringWindowToTop() 如下, 这是个 draft 把我用到过的能把窗口拿到最前方的 API 都罗列在里面了, 也没有正确的返回值, 供参考.

None.gifBOOL MyBringWindowToTop(HWND hWnd)
ExpandedBlockStart.gif{
InBlock.gif
InBlock.gif    HWND hFrgWnd = ::GetForegroundWindow();
InBlock.gif    AttachThreadInput( GetWindowThreadProcessId(hFrgWnd, NULL), GetCurrentThreadId(), TRUE );
InBlock.gif    ::SetForegroundWindow(hWnd);
InBlock.gif    ::BringWindowToTop(hWnd);
InBlock.gif
InBlock.gif    if (!::BringWindowToTop(hWnd))
ExpandedSubBlockStart.gif    {
InBlock.gif        printf("BringWindowToTop Error %d\n", GetLastError());
ExpandedSubBlockEnd.gif    }
InBlock.gif    else
ExpandedSubBlockStart.gif    {
InBlock.gif        printf("BringWindowToTop OK\n");
ExpandedSubBlockEnd.gif    }
InBlock.gif    if (!::SetForegroundWindow(hWnd))
ExpandedSubBlockStart.gif    {
InBlock.gif        printf("SetForegroundWindow Error %d\n", GetLastError());
ExpandedSubBlockEnd.gif    }
InBlock.gif    else
ExpandedSubBlockStart.gif    {
InBlock.gif        printf("SetForegroundWindow OK\n");
ExpandedSubBlockEnd.gif    }
InBlock.gif
InBlock.gif    SwitchToThisWindow(hWnd, TRUE);
InBlock.gif
InBlock.gif    AttachThreadInput(GetWindowThreadProcessId(hFrgWnd, NULL), 
InBlock.gif        GetCurrentThreadId(), FALSE);
InBlock.gif
InBlock.gif    return TRUE;
ExpandedBlockEnd.gif}
推荐一个C#开发的窗口扩展菜单,支持系统所有窗口 一个C#开发的窗口扩展项目,采用.NET Framework 4.0开发,支持Windows Xp以及更高版本的系统,同时支持命令模式,可供代码调用。
小程序滑动、点击切换简洁UI 开发遇到了,就简单的记录下,小程序滑动或者点击切换样式这里不做演示了,直接上代码wxml 需要写的代码放在内容1替换即可,即可实现轻松的点击或者滑动切换窗口,js数据交互统一处理即可,同一加载只是显示的排版布局而已,其他一样的...