views:

96

answers:

2

The titles says the most of it really.

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 { 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

A: 

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.

inam101
Its actually not possible (or at least to my knowledge) to capture the window contents when its minimised. The drawing context contains a 0 sized BITMAP.
Wayne Smith
If you transfer the control/windowform handle to the graphics object, then it can draw the control content as bitmap. i have already done it for my game of life application for animations at http://inam101.wordpress.com/2009/02/26/some-game-of-life-animations/I will show you the code for capturing control-content as bitmap the next day, as i have not that at this time.
inam101
A: 

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.

Slapout
Looking into this now, thanks for the tip.
Wayne Smith
Hmm, I've had a look at the IPC, seems more suited to sending actual data rather than the user input that I'm currently injecting: When I say Im injecting mouse and key events, I mean the events the application would have received if I were interacting directly with it. ie, user types a word on the keyboard in a form text field, or clicks a button with the mouse, etc.
Wayne Smith