Win32 App problem

Started by
10 comments, last by Whackjack 21 years, 5 months ago
Hey all. I''ve been visiting this site for some time, but I''m new to the forums. I finally got the motivation to try and make a game using OpenGL. Well, I was going through the introductory OpenGL tutorial that NeHe has on it''s site. I decided to try and add a simple dialog box front end to add some functionality and to hone my Visual C++ skills. After fighting off mounds of errors, compile and linking, I finally got it to compile. Unfortunately when I run it, it crashes instantly. I tried to debug it, but it got so deep into MFC libraries and such, I got lost quickly. I was wondering if anyone could tell me what I''m doing wrong. Below is a link to a zip file containing my project and source files. Any feedback is greatly appreciated. Thanks in advance for you help. http://www.xtremelywyld.com/ddsoft/OpenGLInit.zip
Advertisement
Your topic says win32, but you are having problems with mfc?

Well anyway, download the project and source files from nehe.gamedev.net then use those as a framework for learning.

You can debug applications by pressing "Go" instead of Execute in Visual C++ which may help you find where your program goes bad.

___________________________
Freeware development:
ruinedsoft.com
___________________________Freeware development:ruinedsoft.com
add an AfxWinInit call as the first line in winmain. i''ll let you figure out how to get rid of the asserts yourself. hint: you can''t create controls before you process WM_INITDIALOG message.
I did use "Go" to debug my app, but that''s when it took me into the 7th circle of VC++ hell.
Anyway, I looked up the AfxWinInit call in MSDN. Must''ve been something I overlooked. I got that added.
And I think I know what to do about creating controls before processing WM_INITDIALOG. The only question is, is there anyway for me to create and initialize the dialog box before my program enters its main message loop? I thought about just making a call to WndProc, but I highly doubt that will work, and I''m unsure what I would pass besides the handle and the message.
Thank you very much for your suggestions.
quote:Original post by Whackjack
And I think I know what to do about creating controls before processing WM_INITDIALOG.

this is impossible. dialog doesn''t exist until dlgproc gets wm_initdialog, therefore its window handle is invalid and cannot be used as a parent window handle.
quote:
The only question is, is there anyway for me to create and initialize the dialog box before my program enters its main message loop?

just create your dialog box before the message loop, it''s that simple.
Okay, I think I worded my question incorrectly. I understand that it''s impossible to create the controls before WM_INITDIALOG. I''m a little lost on this though.
I do believe that I did create the dialog box before I entered the main loop routine. What I don''t understand is the creating of controls before WM_INITDIALOG. I''m still very new at this, so please bear with me.
I didn''t use any wizard or anything in Visual Studio, so my file doesn''t have any of the extras that are usually included. So that means I''m probably missing an important part of the process.
I don''t mind the hints you''re giving, in fact I quite like them much more than the direct answer, as I can figure out why it works that way on my own.
Thanks once more for your help.
objects of type CWnd (mfc window) and its derivatives, such as frame windows, dialog boxes, and controls, don''t really exist right after construction. in fact, most mfc constructors do nothing. to actually create an object, one calls either Create() or Attach() functions. the former does most of the work, be that creating a new window, opening a file, or something else. the latter makes the object use an existing object handle, such as a HWND, HDC or similar.

now, to your code. even though CdlgOpenGLInit has three child windows you declared, the corresponding windows do not exist until dialog box receives WM_INITDIALOG. what this means is that dialog box''s m_hWnd is NULL before that point, as are m_hWnds of m_rbWindowed and company.

first thing you want to do is to initialize m_rbWindowed and the rest by giving them existing control handles for the child windows that are present in the dialog. you do this by calling UpdateData(FALSE), which in turn will use your AFX_DATA map to attach control objects to window handles. call UpdateData from your WM_INITDIALOG handler, which you''ll need to add if you don''t already have it.

once you called UpdateData, you can use SetCheck and the such.
It took me a while, but I finally figured out what you''re talking about. It got rid of those asserts. Unfortunately, when I run it, it crashes for no explainable reason. I tried to debug it, and I stepped all the way through to where the message pump begins. That''s where it stopped working.
I think I''ll create a new project using the same files and see if that gets rid of the error. Otherwise, I''ll probably scrap it and start fresh, with cleaner code and all. Thanks for your help, niyaw.

Btw, if you want to see what the error I''m getting is, I''ll put up the newest files on my site. Just ask. Thanks again.
sure, isn''t debugging mfc fun?
Here ya go...

OpenGLInit.zip

I tried to make a really simple dialog box application w/o using the wizard. It too crashes at the same spot this one does, so I'm obviously missing something important.
Again, many thanks for you assistance.

[Edit] You'll have to right click and Save As.. to download the archive. Sorry 'bout that, but my main site isn't working properly at the moment.

[edited by - Whackjack on October 29, 2002 10:24:11 PM]

This topic is closed to new replies.

Advertisement