开发者

C# Application loaded without focus still steals it on the first injected mouse event

I have two applications, the first is a full directX application written in c++, the second application is written in c# and renders flash videos, avi's, pdf's etc using ActiveX COM objects. The first application then captures the content of this c# app, and renders it into the 3d environment as a texture. This all works as intended, and I have code in the directX app to allow me to send key and mouse events to the c# app via SendMessage and PostMessage.

My problem lies with initial startup. I have the c# app set to start up without activation, using:

protected override bool ShowWithoutActivation
{
开发者_StackOverflow社区    get { return true; }
}

which is the equivalent of SW_SHOWNOACTIVATE in the CreateProcess call. The application launches fine, and renders fine on the c++ app's texture. However, the very first mouse click forces the c# application to steal focus, and thus drops my directx context. Does anybody know why this happens, or if there's any way around it?

If I launch the c# app and dont ever click on it, the c++ app when launched still runs as intended, its only when launching it through 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
}

Cheers in advance for any help, Wayne


you an also try to make the main c# form hidden by setting its properties as WindowState=Minimized and ShowInTaskbar=false.

then at a certain moment, if you want, you can change the above properties to bring the application form to front.

In this case, the application will be running doing all its jobs but it will not be visible. you can then capture its active region without making it visible on the screen.


Sending key presses doesn't sound like the proper way to do communication between two programs. Could you set up some sort of COM interface between the two programs? Here's a Microsoft page on Interprocess Communication with some other techniques too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜