WIN32/MFC window class registration question...

All,

I’ve come to enjoy the ease of creating an OpenGL-ready framework via the MFC app wizard in Visual C++. However, one thing that I don’t do is register the window class. So, no CS_OWNDC is called. Can anyone speak to the drawbacks/bugs associated with not registering a window class?

Regards,

Glossifah

Actually, I can… I could even write a book on that !!! No, kidding… .

Well, I had one problem when removing the CS_OWNDC bit in my 3D Modeller.

Let me just tell you a bit about my architecture: I use one Rendering Context (RC) per document and then one Device Context (DC) per view. That enables me to share Display Lists and textures without using wglShareLists and save memory.

Then, I can pick / transform objects (hey, that’s a modeller !). When removing the CS_OWNDC bit, I sometimes had glitches in the other views while transforming in one of them… Those glitches did never happen when using CS_OWNDC…

I must say I do not know for sure why these things happen… but they do !

So, stay on the safe side, and register your window class with the CS_OWNDC bit !!!

Regards.

Eric

Thanks Eric.

Could I declare CS_OWNDC in the CMainFrame::PreCreateWindow() function? Like cs.style |= CS_OWNDC ? Is that the proper method, or should I be looking elsewhere?

The cs.style method won’t work. That will pass CS_OWNDC to CreateWindow which isn’t what you want. Instead, you should use the AfxRegisterWndClass() function. You can use it something like so…

cs.lpszClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW |CS_OWNDC);

There are also optional parameters for specifying the default brush, icon, and cursor if you wish to use them.

Deiussum is right !

Here is the exact code I use in my PreCreateWindow member:

BOOL C3DModellerView::PreCreateWindow(CREATESTRUCT& cs)
{

cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS|CS_OWNDC,LoadCursor(NULL,IDC_ARROW),NULL,NULL);
cs.style|=WS_CLIPSIBLINGS|WS_CLIPCHILDREN;
return CView::PreCreateWindow(cs);

}

Regards.

Eric

Great information! Thanks. I’ll make it a habit to register my window class from now on, using these methods.

Glossifah

>>> Let me just tell you a bit about my architecture: I use one Rendering Context (RC) per document and then one Device Context (DC) per view. That enables me to share Display Lists and textures without using wglShareLists and save memory.

I Eric,

Above you mentioned you use one RC per doc and one DC per view - I was just wondering how you got that to work. I tried it and no joy. If you could explain I would be most greatful as I’m writing an editor that suffers alot from having an RC per view. It effectively halves the frame rate per extra view (I have 4 standard views).

TIA,

Mr Gawd

Hi MrGawd !

Well, the easiest way to solve your problem is to tell me which bug you have (you said that having one RC per document does not work for you !).

As far as I am concerned, I just create the RC with the first view… Then, each time I want to render something in a view, I use wglMakeCurrent with the document’s RC and the view’s DC… Nothing really clever…

The main bug I ever had was to forget about a wglMakeCurrent (which made OpenGL render everywhere except where I expected it !)…

If you can tell us what the bug is when you try to use this technique, we might be able to tell you why !

Best Regards.

Eric