【问题标题】:How to bring another window forward that is not owned by the program如何使另一个不属于该程序的窗口前进
【发布时间】:2010-10-07 23:01:21
【问题描述】:

我真的很难找到一种方法来提出另一个程序窗口。

例如,我使用 FindWindow 来查找记事本的句柄。然后我尝试使用 SetWindowPos(hWnd, 0,0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);

但它只是不起作用! ShowWindow 也不行!

你能帮我看一下sn-p的代码吗?

谢谢

【问题讨论】:

    标签: c++ z-index


    【解决方案1】:

    不知道这是否是同一件事,但在 Windows 开发的某个时刻,微软添加了一些过于聪明的“反弹出”代码,这将阻止没有焦点的程序取消-最小化它的窗口......相反,程序栏中的窗口条目只会闪烁。也许有类似的逻辑阻止非前台程序将其窗口向前移动?

    无论如何,这里有一些代码可以尝试,可能有帮助也可能没有帮助:

     // Check to see if we are the foreground thread
     DWORD foregroundThreadID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
     DWORD ourThreadID = GetCurrentThreadId();
    
     // If not, attach our thread's 'input' to the foreground thread's
     if (foregroundThreadID != ourThreadID) AttachThreadInput(foregroundThreadID, ourThreadID, TRUE);
    
     // Bring our window to the foreground
     SetForegroundWindow(hWnd);
    
     // If we attached our thread, detach it now
     if (foregroundThreadID != ourThreadID) AttachThreadInput(foregroundThreadID, ourThreadID, FALSE);
    
     // Force our window to redraw
     InvalidateRect(hWnd, NULL, TRUE);
    

    【讨论】:

    • 嗯,您对 MSFT 为制止“在用户面前开一扇窗”的态度所做的努力不够赞赏。真丢脸。
    • 我非常感谢它。我只是认为他们应该将他们的 SetForegroundWindow() 函数重命名为 SetForegroundWindowButNotUnlessIAddSomeExtraMumboJumboToShowThatIReallyMeanIt(),这样它的名字才能准确地反映它的行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多