Performing actions with message loop

This is a discussion on Performing actions with message loop within the Windows Programming forums, part of the Platform Specific Boards category; Code: LRESULT CALLBACK WndProc ( ... case WM_KEYDOWN: switch (wParam) { case VK_ESCAPE: PostQuitMessage(0); return 0; case VK_NUMPAD1: AwesomeVar++; // ...

  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
    Registered User
    Join Date
    May 2006
    Posts
    903
    Make it global.

  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, 01: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, 03:17 PM
  4. Help, the window gets killed......
    By incognito in forum Game Programming
    Replies: 2
    Last Post: 05-28-2002, 03:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21