C++/(MFC)one application will make opengl drawing to the other application's window
QUESTION: Dear Bill,
I have 2 applications (Visual Studio 6.0). One of them is GUI. It has a picture component. Other application is a console application(MFC based), which makes an opengl drawing. I want to make this console application draw opengl in the picture component of GUI. For that, I am giving HANDLE of picture component to console application. In main of console application, I am getting the HDC of picture component using the available HANDLE. I am doing that as follows:
Firstly I am creating an object from CWnd class.
CWnd *cwnd = new CWnd();
Then I am getting HDC as below:
HDC h = (cwnd->GetDC())->GetSafeHdc();
After these, I am calling ChoosePixelFormat function passing h to set the pixel format. But I am taking error when I come to ChoosePixelFormat. What can be the problem? Can a console application manage HDC kind of things given by another dialog based MFC application? If my console application is not MFC based, how can I do all of these things?
Is your PIXELFORMATDESCRIPTOR structure all OK (test by filling it in the same way in the MFC program and making the same call to ChoosePixelFormat.
It's possible that a console mode program is built such that calls to update the display are blocked? I'm guessing since I've never done what you're doing.
I guess there's a reason to structure the program this way, but did you consider passing a pointer to the drawing function and have the console mode call back into the GUI?
---------- FOLLOW-UP ----------
Actually, I forgot to say that it runs correctly when two applications are MFC(dialog based). That is if I use MFC instead of my console application, it runs as I want.That is, it can set pixel format using received HANDLE from GUI. But, when I do the same things with console application, there is a problem. As a result, some of things supported by MFC application may not be supported by console application for HDC kinds of things. I console mode, calls to update the display can be blocked as you said. If such thing occurs, how can I manage this? As written in the previous question I have a console application which is MFC based. If I have a console application which is NOT MFC based, how can create an object of CWnd class? (CWnd class is not defined in console applications which are NOT MFC based.)
When you created the Console mode application did you check:
Add support for: [X] MFC [ ] ATL.
I would think you'd have to check MFC.
I have not done what you are trying to do (I've created DLLs that create and access Windows) but will help as much as I can.