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 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).