Problem with WM_KEYDOWN

This is a discussion on Problem with WM_KEYDOWN within the Windows Programming forums, part of the Platform Specific Boards category; It isnt working for me for some reason.. When i press a key, all it does is Deactivate the window, ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    387

    Problem with WM_KEYDOWN

    It isnt working for me for some reason..
    When i press a key, all it does is Deactivate the window, can someone please try to help:

    Code:
    	case WM_KEYDOWN:
    		{
    			switch((int)wParam)
    			{
    			case VK_LEFT:
    				MessageBox(NULL, "Left Button Pressed", "KEYPRESS", MB_OK);
    				break;
    
    			case VK_RIGHT:
    				MessageBox(NULL, "Right Button Pressed", "KEYPRESS", MB_OK);
    				break;
    
    			case VK_UP:
    				MessageBox(NULL, "Up Button Pressed", "KEYPRESS", MB_OK);
    				break;
    
    			case VK_DOWN:
    				MessageBox(NULL, "Down Button Pressed", "KEYPRESS", MB_OK);
    				break;
    			}
    		}
    		break;
    Thanks to all who try to help
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post This may be what you need...

    Try changing the switch statement to:

    switch(LOWORD(wParam))
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Ok, that LOWORD(wParam) worked, but only after i took out my WM_PAINT message, here it is:

    Code:
    	case WM_PAINT:
    		{
    			HDC Window = GetDC(hwnd);
    			HDC mem = CreateCompatibleDC(Window);
    
    			
    
    			BitBlt(Window, 0, 0, 384, 288, mem, 0, 0, BLACKNESS);
    			BitBlt(Window, 394, 0, 246, 288, mem, 0, 0, BLACKNESS);
    			BitBlt(Window, 0, 298, 640, 177, mem, 0, 0, BLACKNESS);
    
    			DeleteDC(mem);
    		}
    		break;
    		*/
    Is something wrong with that?
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    In other words, you are not merely casting a WPARAM variable ( no doubt a typedef for a long int) to an int. Rather you are extracting the "lower" half of it...
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    Yes! You must CreateCompatibleBitmap a HBITMAP variable, making it compatible to "Window". Then SelectObject(mem, bitmap).

    Really, though, you should call BeginPaint() and EndPaint() in the WM_PAINT handler, too.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Sebastiani
    Really, though, you should call BeginPaint() and EndPaint() in the WM_PAINT handler, too.
    That's very true....Using GetDC will not remove the WM_PAINT Message from the message queue.........

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    WM_PAINT is called because a region has been 'invalidated'. BeginPaint() validates this region. GetUpdateRegion() can be called to find it prior to this.

    This is EVIL!
    Code:
    HDC Window = GetDC(hwnd);
    HDC mem = CreateCompatibleDC(Window);
    BitBlt(Window, 0, 298, 640, 177, mem, 0, 0, BLACKNESS);
    
    DeleteDC(mem);
    This is a mem leak. At no point is the HDC 'Window' released with a call to ReleaseDC(). Be very careful about Creating / Getting GDI resources. They not only must be freed but put back EXACTLY the way you found them.

    Better to use the DC in the paint struct or the return from BeginPaint().

    If you create a BMP ensure you catch the one in the DC and replace it before deleting them both (the DC and the BMP).
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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