How to set CS_OWNDC in MFC, info here!

Well, read the subject, and I have the answer.

It seems that everyone programming in OpenGL knows that you’re supposed to set a window style of CS_OWNDC if you’re programming in Windows. All of you real programmers know how to do that, because you’re all doing the right thing and programming in Win32.

But what about us lowly persons that are enslaved in the wackey world of MFC (sic)? Well, I’ve asked many, but no one has known. Most people say, “Duh, set it on your PreCreateWindow’s attribute.” Well, they’re wrong. Read some books and you’ll find out that is indeed for window styles, but the idiots that keep referring to the CS_ attributes as windows styles are confusing the hell out of everybody!

What the CS_ attributes should more accurately be referred to as are “Creation Styles” or “Class Styles”. The second one should give a clue as to how to set it now in MFC. Read on! :stuck_out_tongue:

PreCreateWindow of your OpenGL view (or CWnd) is indeed the right place to do it. But not using or cs.dwExStyle…

You do something akin to the following:

cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);

Basically, this is the same thing as what the folks in Win32 land do right at the beginning of their code. They “Register the class”. Notice the CS_OWNDC. Its there! Woo! By the way, the second to last NULL (from what MSDN tells, and its been known to lie) causes the handler for WM_ERASEBKGND to NOT redraw the window, effectively allowing you to not have to override WM_ERASEBKGND to support flicker-free double buffering. Bonus!

Now, you may be asking “Uhh, why do I care about some stupid CS_OWN… CS_OWN… CS_WHATEVER?”

Well, if your target platform is going to be Windows 95, Windows 98 or Windows ME (god forbid), it is a potential problem. I won’t go into all the details, because any good OpenGL book that covers Windows GL programming will tell you why. Just know that this isn’t an issue for Windows NT and Windows 2000, but its still good practice. After all, you never know what you’re going to be running you program on!

Alrighty then… now that I’ve used my quota of smiles for the day, go forth and use the force wisely, lest it poke your eye out.

I hope this info is useful to somebody. I’ve personally been looking for it for the past 4 months, and no one has been able to help me. Digest, enjoy, and discuss amongst yourselves…


PS - Here’s a topic, the Holy Roman Empire was neither Holy, nor Roman, nor an Empire… discuss!

[This message has been edited by Siwko (edited 10-24-2000).]


Did you ask here ?

I happen to have seen such a topic in a coding forum not long ago… Actually I knew we had to do that with MFC (that’s what I am doing in my framework…).

Sorry if I missed it…



Originally posted by Eric:

Did you ask here ?

Oh god… I asked maybe 2 or 3 months ago, and nobody had the answer. I even asked the nvidia folks when I had another problem, just to see if they might know, and they said “ask microsoft”. I’ve searched for it a ton of times in the forum and never found it either.

Oh well… I just thought it’d be helpful.


Actually, the way I realized that there was a problem was when I tried this “New Window” command that all MS applications have (built-in MFC)…

In my framework, you can select/move/rotate objects like in 3DS… When I had two views opened on the same document, I had ‘flickering’ or should I say ‘jumps’ when I moved an object… It was as if OpenGL was not drawing to the correct view (although the proper DC was selected with wglMakeCurrent !).

I then searched the web (quite a lot) and found a topic about that where the guy was explaining how to use CS_OWNDC correctly…

Now I do not have the problem anymore…

Once again, sorry for not having picked your question up… Actually, perhaps I had my problem after you had yours so perhaps that wouldn’t have helped… (I do not remember when all this took place !).