创建不可见且无模态的属性表会导致焦点更改? [英] Creating invisible and modeless property sheet causes focus change?

查看:87
本文介绍了创建不可见且无模态的属性表会导致焦点更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调查与失去焦点和更改Windows激活有关的问题.我发现,如果创建一个不可见的属性表,则活动/前景窗口会更改,焦点窗口也会更改.这是一些示例MFC代码:

I was investigating an issue related to losing focus and changing activation of windows. What I found was that if I create an invisible property sheet, the active/foreground window changes and so does the focus window. Here is some sample MFC code:

   // ignore CAutoDeleter, just a template that calls "delete this " in PostNcDestroy()
   CPropertySheet* pSheet = new CAutoDeleter<CPropertySheet>(_T("Test Sheet"));
   CTestPage* pPage = new CAutoDeleter<CTestPage>();
   pSheet->AddPage(pPage);

   DWORD style = WS_SYSMENU | WS_POPUP | WS_CAPTION | DS_MODALFRAME | DS_CONTEXTHELP;
   // style |= WS_DISABLED; //does nothing to help

   DWORD exStyle = 0;
   //exStyle = WS_EX_NOPARENTNOTIFY|WS_EX_NOACTIVATE; // does nothing to help
   pSheet->Create(AfxGetMainWnd(), style, exStyle); // adding 

在调用pSheet-> Create()之后,活动/前景/焦点窗口已更改,应用程序窗口位于顶部.如果我使用Spy ++并查看创建的窗口,事实证明属性表是DIALOG窗口类.我当然假设它具有不同的WNDPROC.有趣的是,如果我使用创建不可见的无模式对话框,它不会出现问题.如果创建不可见的无模式对话框,则活动/前景/焦点窗口将保持不变.

After the call to pSheet->Create(), the active/foreground/focus window has changed and the application window is on top. If I use Spy++ and look at the window that is created, it turns out that a property sheet is a DIALOG window class. I am assuming it has a different WNDPROC, of course. What is interesting, is if I create an invisible modeless dialog using, it does not exhibit the problem. If I create the invisible modeless dialog, the active/foreground/focus window remains the same.

我尝试像代码片段中那样设置各种标志,但是可惜它们没有任何明显的效果-我仍然对闪烁和激活毫无意义.

I tried setting various flags as in the code snippet, but alas they did not have any discernible effect--I still had the flashing and activation non-sense.

我可以通过在pSheet->Create()之前和之后设置并清除一个钩子(WH_CBT)并获得激活消息来获得一些改进.当我这样做时,我没有可怕的闪烁,并且我的应用程序窗口没有显示在顶部.但是,焦点(以及带有尖号的窗口的尖号)的确会偏离Create()之前的那个窗口.

I could get some improvement by setting and clearing a hook (WH_CBT) before and after pSheet->Create()--and then eating the activation messages. When I do that, I don't have the horrible flashing and my application window does not come to the top. However, the focus (and caret for windows that have carets) does go away from whichever window had it before the Create().

在创建不可见的属性表时,有人知道保持焦点和激活不变的方法吗? (有时,属性表可能设置为可见或不可见.并且,如果属性表在销毁时不可见,也会导致闪烁和激活更改.)

Does anyone know a way to keep the focus and activation unchanged when creating an invisible property sheet? (At some point, the property sheet may or may not be set visible. And, if the property sheet is invisible when being destroyed, it also causes the blinking and activation changes.)

我尝试使用GetUIThreadInfo()中返回的值来尝试在调用Create()之后恢复内容,但这也会引起一些闪烁.

I tried using the values returned in GetUIThreadInfo() to try and restore things after the call to Create(), but it causes some flashing as well.

我只想知道如何创建不可见的属性表,而不会导致活动窗口,前景窗口和焦点窗口发生变化.

I just want to know how to create an invisible Property Sheet which won't cause the active, foreground, and focus window to change.

推荐答案

不幸的是,基础API函数 SetForegroundWindow .解决这个问题没有简单的方法-带WH_CBT钩的合并可能是您的最佳选择.

Unfortunately the underlying API function PropertySheet calls SetForegroundWindow on the main property sheet dialog after creation. There's no easy way around this - your kludge with the WH_CBT hook is probably your best option.

如@stephen在此重复问题的评论中所建议的那样,则可以使用

As suggested by @stephen in the comments on this duplicate question, you may be able to prevent the activation/focus change using LockSetForegroundWindow.

这篇关于创建不可见且无模态的属性表会导致焦点更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆