Advertisement

Question About NeHeGL1 Basecode

Started by June 20, 2002 12:42 PM
7 comments, last by Mike23423 22 years, 8 months ago
My question is about Nehe''s draw function being in WM_PAINT. Aren''t you supposed to declare variables in WinMain? So if I''ve declared an object in WinMain, how would I send it to WindowProc so the Draw function can use it? Thanks!
Anyone?
Advertisement
You can declare variables in any function you want. There is no way for one function to use variables declared in another function.
---visit #directxdev on afternet <- not just for directx, despite the name
Unless you specifically pass them to another function. You can do that, or declare your variables globally.
Yeah, I know functions can''t use variables declared in other functions. I was thinking that the windows messaging system (which I don''t know very well) might provide a way to pass things from WinMain to WndProc. Yes, I could declare them globally, but that isn''t a very elegant solution.

I haven''t worked much in Windows, but I''m assuming it''s good programming practice to declare one''s variables in WinMain. So, is there any way for me to send my objects declared there to WndProc so that WM_PAINT can draw them?

Thanks!
what are you trying to do and why isn''t a global variable viable?
what are you declaring (an x or y value I presume?, what are you passing to paint?) ???

Im just a beginner!!!

http://www.actsofgord.com
~~~~~~~~~~~~~~~~~~~~~~~~~http://on.to/oni
Advertisement
I don''t know exactly what your level of expertise is . . .

But how about just posting a message from WndProc to WinMain? So, inside WndProc:

switch (uMsg)
{
case WM_PAINT:
PostMessage (hWnd, WM_USER + 1, 0, 0);
return;

/* etc */
}

And inside WinMain (or other equivalent function):

while (game_active)
{
while (PeekMessage (&ciMSG, ciHWND, 0, 0, PM_REMOVE))
{
if (ciMSG.message == WM_USER + 1)
RunPaintCode ();

/* etc */
}

/* other code */
}

Just an idea. In my opinion it makes for much neater code, as WndProc seems to run in a different thread to your normal program anyhow. (Is this true? Or does PeekMessage or such invoke WndProc? Somebody help me! )
I think it''s DispatchMessage that calls WndProc
Thanks, Mr Sam. That''s exactly what I was looking for.

This topic is closed to new replies.

Advertisement