Hidden dialog takes focus for a moment
I have a bit of a problem here.
I have a third party ActiveX control which converts files from one type to another. I want to convert many files, so I need to run it in batch conversion. However this control crashes a lot (I'm not talking about nice C++ exceptions, it does cute things like accessing already freed memory, doing access violation, you name it).
So my problem is the following:
1) I need to wrap this ActiveX control in a separate process, to prevent it from corrupting the memory of my main process.
2) I need to call this process possibly hundreds of times, and with small files on a quick computer it gets called 5-6 times a second
3) I need to make this process completely silent, the user must not be aware that a process is being executed many times
4) However because it's an ActiveX control I also need to create a hidden dialog in the process which hosts the ActiveX control
But when I create the hidden dialog, it seems to take away the focus from the active window for a moment, and then returns it back. As this process can get called 5-6 times a second, it breaks keyboard input for a user, and it also makes the currently active window flicker rapidly, switching from active to inactive state.
I'm using a CDialog-derived class to host the ActiveX control. The Visible flag is turned off from the resourse editor to prevent it from showing. I'm creating the dialog by calling CDialog::Create, not DoModal.
How can I prevent the dialog from taking away the focus?
It's difficult to say without seeing any source code but....If you are overwritting OnInitDialog in your CDialog derived class, try to return FALSE instead of TRUE at the end of the method.
Just guessing...
Good luck.
It turns out the problem was entirely with CDialog. It was stealing focus even without an ActiveX or any modifications. So the solution was to create my own window class that uses DefWindowProc, and use that as the parent of the ActiveX (it did requre a parent, it failed when I specified NULL for pParent).
It may not be the dialog stealing the focus, it may be the ActiveX control. Try it on a dialog without the AX and see if it shows the same behavour. CDialog::Create does create the dialog, but it does not display it until you call ShowWindow/UpdateWindow.
Also, I remember being able to instantiate ActiveX controls without needing a host. VS may create wrapper classes for it that you can use to create dynamically. Does the ActiveX actually require a dialog (say, input controls to display)?
链接地址: http://www.djcxy.com/p/39256.html上一篇: 我想知道在EN之后焦点所在的位置
下一篇: 隐藏的对话框需要关注一会儿