Win32 Api wParam key input problem

This is a discussion on Win32 Api wParam key input problem within the Windows Programming forums, part of the Platform Specific Boards category; So, I've been playing around with WinApi in C++. When i tried some key input i got a problem. I'm ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    2

    Unhappy Win32 Api wParam key input problem

    So, I've been playing around with WinApi in C++. When i tried some key input i got a problem. I'm using WPARAM along with the WM_CHAR case. This is my input function:

    Code:
    case WM_CHAR:
    		 UpdateGameInput(wParam);
    		 break;
    
    //Later on
    
    void UpdateGameInput(WPARAM wParam)
    {
    	if (wParam == VK_LEFT)
    	{
    		pPosition.x += -5;
    	}
    	else if (wParam == VK_UP)
    	{
    		pPosition.y += -5;
    	}
    	else if (wParam == VK_RIGHT)
    	{
    		pPosition.x += 5;
    	}
    	else if (wParam == VK_DOWN)
    	{
    		pPosition.y += 5;
    	}
    	else if (wParam == VK_ESCAPE)
    	{
    		exit(0x1337);
    	}
    }
    The VK_ESCAPE is working perfectly but the other ones doesn't seem to give any effect. pPosition is a point and is declared global in the beginning of the program:
    Code:
    POINT pPosition;
    I'm using pPosition to draw a rectangle with my HDC and PAINTSTRUCT. The rectangle is showing itself, but it isn't moving the way i want it to:

    Code:
    case WM_PAINT:
    hdc = BeginPaint(hwnd, &ps);
                     Rectangle(hdc, 
    			 pPosition.x - 10, pPosition.y - 10,
    			 pPosition.x + 10, pPosition.y + 10);
    		 EndPaint(hwnd, &ps);
    		 break;
    Please help me!

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Check the values in the POINT when you try to draw the rectangle.

    I can't see the POINTs initialisation nor any check to ensure it does not contain valid values (valuse that will not produce a negative coordinate or a point off the screen when drawing the rectangle).

    I also can't see the call that generates a WM_PAINT msg. It may not be invalidating the correct area.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    I'm not sure, but it would be better if u used WM_KEYDOWN instead WM_CHAR. I think WM_CHAR is called only by char input and limited others, like VK_ESCAPE
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with keyboard input
    By fighter92 in forum Game Programming
    Replies: 6
    Last Post: 03-20-2009, 10:41 AM
  2. Problem grabbing k/b input
    By falcon9 in forum C Programming
    Replies: 2
    Last Post: 10-28-2007, 12:47 PM
  3. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 10:09 AM
  4. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 04:51 PM
  5. Input Problem
    By Drew in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2001, 08:19 AM

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