Question About NeHeGL1 Basecode
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!
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!
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
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
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!
)
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!

This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement