Thread: Performing actions with message loop

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    162

    Performing actions with message loop

    Code:
    LRESULT CALLBACK WndProc ( ...
        case WM_KEYDOWN:
            switch (wParam)
            {
    	        case VK_ESCAPE:
    	        	PostQuitMessage(0);
    	        	return 0;
    
    		case VK_NUMPAD1:
    			AwesomeVar++; // <-- This is what I need help with *
            }
            return 0;
    "AwesomeVar" is sitting within - int WINAPI WinMain ( ...

    Could someone explain how exactly I would go about making the above hypothetical situation work?

  2. #2

  3. #3
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Make a variable global, then you can share it between functions.
    But what I prefer doing is making either a struct or Class that has public variables in it that i use regularly, and then just pass around a pointer to that struct/class. Its much cleaner then using global variables.
    Founder and avid member of the Internationsl Typo Associateion

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  2. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  3. Message loop not working...
    By Hunter2 in forum Windows Programming
    Replies: 24
    Last Post: 07-03-2003, 02:17 PM
  4. Help, the window gets killed......
    By incognito in forum Game Programming
    Replies: 2
    Last Post: 05-28-2002, 02:22 PM