Click here to Skip to main content
Click here to Skip to main content

How to draw OpenGL to a window you created in a dialog box with the resource editor

, 24 Oct 2001
Rate this:
Please Sign up or sign in to vote.
How to draw OpenGL to a window you created in a dialog box with the resource editor without manually using CreateWindow.

Sample Image - screenshot.jpg

Introduction

This example code I created explains and shows how you can draw OpenGL into a window that you created with the resource editor, without having to call CreateWindow. In my example, I used VC 6's New project creator wizard to start my project and then created a dialog box. In the dialog box, I have created 4 edit style windows. The technique used is simply retrieve the handle of the edit windows, retrieve the HDC for each window and pass them into your regular OpenGL initialization and rendering. What is important to note in my example is you have to set the current rendering context to the desired window before painting to it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Chong Hin Ooi

United States United States
No Biography provided

Comments and Discussions

 
GeneralPlease check this article PinmemberSharjith9-Nov-10 12:16 
GeneralBUG: This code is unsafe without CS_OWNDC PinmemberMember 122382917-Nov-09 15:03 
While what you've done works *most of the time*, it's unsafe and could cause fatal errors under certain conditions.
 
OpenGL windows need to have the CS_OWNDC window style set. Without this, under low-memory conditions Windows (may) recycle your HDC even if you have not released it. While you will not lose the HDC--the handle remains valid--subhandle setup within the context may change making your render context invalid and (possibly) crashing the driver.
 
I was curious about the example specifically *because* I was looking for some way to use dialog-editor created windows without running into the CS_OWNDC problem and without using SetWindowLong to alter the window style: merely flagging CS_OWNDC with SetWindowLong is not enough, as some other window styles that may already be attached to the class such as WS_EX_COMPOSITED are unsafe to use with CS_OWNDC.
 
I'm bummed. I'd still love an (easy) way to do this.
 
You might still use dialog editor created windows if you created your own subclassed custom control that set the CS_OWNDC style appropriately, but that's a lot more code, aargh.
Questionbackground color Pinmemberlabs132423-Aug-06 7:16 
GeneralRe: background color PinmemberGita.Bairavi12-Mar-08 20:52 
QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pinmemberwerter13-May-04 21:20 
QuestionHow to make a multi-viewport in OpenGL with MFC? PinmemberVicher21-Apr-04 1:41 
QuestionHowto Draw something in an edit box? Pinmemberszlivkab@freemail.hu25-Oct-03 23:55 
Generalmouse events PinsussAnonymous21-Jan-03 10:24 
GeneralRe: mouse events PinsussAnonymous8-Jun-03 1:33 
GeneralRuns well the first time . . . PinmemberAnonymous4-Apr-02 8:34 
GeneralRe: Runs well the first time . . . PinmemberAnonymous21-Apr-02 12:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 25 Oct 2001
Article Copyright 2001 by Chong Hin Ooi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid