A C # application downloaded without focus still steals it the first time a mouse event is introduced

I have two applications, the first is a full directX application written in C ++, the second application is written in C # and displays flash movies, avi, pdf, etc. using COM ActiveX objects. The first application then captures the contents of this C # application and displays it in a 3D environment as a texture. It all works as intended, and I have the code in the directX application to allow me to send key and mouse events to the C # application via SendMessage and PostMessage.

My problem is the initial start up. I have a set of C # applications to run without activation using:

protected override bool ShowWithoutActivation
{
    get { return true; }
}

which is the equivalent of SW_SHOWNOACTIVATE in a call to CreateProcess. The application runs fine and perfectly displays the texture of the C ++ application. However, the very first mouse click causes the C # application to steal focus and, thus, reduces my directx context. Does anyone know why this is happening, or if there is any way around it?

If I run a C # application and never click on it, the C ++ application at startup still works as intended, only when launched through the code:

STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));

si.cb   = sizeof(si);
si.dwFlags  = STARTF_USESHOWWINDOW | STARTF_USESIZE;
si.wShowWindow = SW_SHOWNORMAL;
si.dwXSize  = 400;
si.dwYSize  = 400;
if(!::CreateProcess(program, arguments, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
    return false;
}
else
{
    // use EnumWindows to conforim the app is open and get its HANDLE
}

Welcomes in advance for any help, Wayne

+3
source share
2 answers

you will also try to hide the main C # form by setting its properties as WindowState = Minimized and ShowInTaskbar = false.

, , , .

, . , .

0

. - COM ? Microsoft Interprocess Communication .

0

Source: https://habr.com/ru/post/1760598/


All Articles