Jump to content
  • Advertisement
Sign in to follow this  
boogyman19946

Win32 programs without global variables

This topic is 2863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm starting up on my new game, and, having a new approach, I'm trying to restrain from global variables, but it seems to be impossible due to the message procedure functions. I have found global variables to be excruciatingly painful when trying to split a program into multiple source files, but it seems that windows doesn't allow things otherwise. This wouldn't be a problem if you could pass arguments into the WndProc functions. Anyone have any idea how can local scoped variables be accessed from there?

Share this post


Link to post
Share on other sites
Advertisement
To be honest i have just started rewriting in C++ and my project uses only 1 global function. the AppWndProc() i did this;


Window.h

class Window
{
private:
//All my Priv varaibles etc.

public:
//Constructor etc.
long FAR PASCAL HandleEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

};
//Define the Window proc
long FAR PASCAL AppWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);



Window.cpp

long FAR PASCAL Window::HandleEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
break;
}
}

return DefWindowProc(hWnd, msg, wParam, lParam);
}

//The Message procure
long FAR PASCAL AppWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CWindow Wind;
return Wind.HandleEvent(hWnd, msg, wParam, lParam);
}



This means all message are handled inside my Windowclass, nothing is used by the window procedure so no arguments need to be passed.

If there is another arg i need to pass, i pass itinto the Window::HandleEvent(...)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!