CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Join Date
    Feb 2011
    Location
    UK
    Posts
    73

    Re: Virtual Key Codes

    Ok then... Where are you telling me to put "return 0;"???

  2. #17
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Virtual Key Codes

    Right after your processing code for VK_LEFT/VK_RIGHT of WM_KEYDOWN message.
    Victor Nijegorodov

  3. #18
    Join Date
    Feb 2011
    Location
    UK
    Posts
    73

    Re: Virtual Key Codes

    Thanks

    The left and right arrow key is now working as it should, although when i press a key such as 'S' or any other key which I have not defined code for makes my icon move right.

  4. #19
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Virtual Key Codes

    Show your actual code.
    Victor Nijegorodov

  5. #20
    Join Date
    Feb 2011
    Location
    UK
    Posts
    73

    Re: Virtual Key Codes

    Code:
    case WM_KEYDOWN:
    
    			switch(wParam)
    			
    				case VK_LEFT:
    			{
    					X -= 5;
    					InvalidateRect(hWnd, NULL, TRUE);
    					return 0;
    
    					
    					
    			}
    				case VK_RIGHT:
    			{
    					X += 5;
    					InvalidateRect(hWnd, NULL, TRUE);
    					return 0;
    					
    					
    			}
    
    			break;

  6. #21
    Join Date
    Apr 2009
    Posts
    598

    Re: Virtual Key Codes

    Try:
    Code:
    case WM_KEYDOWN:
    {
      switch(wParam) {
        case VK_LEFT:
            X -= 5;
            InvalidateRect(hWnd, NULL, TRUE);
            break;
        case VK_RIGHT:
            X += 5;
            InvalidateRect(hWnd, NULL, TRUE);
            break;
      }
    }
    return(0);
    break;
    Besides, the line, hInstance = LoadLibrary (TEXT("Application01.exe"));, is run every time a message arrives, which might occur several dozen of times per seconds. That line might take a lot of time and resources. I would advise you to load that library only in WM_CREATE, and declare hInstance as a static variable.
    Last edited by olivthill2; July 18th, 2011 at 05:01 AM.

  7. #22
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Virtual Key Codes

    Actually, GetModuleHandle(NULL) would be enough, as long as it is about getting main .exe instance handle.
    Best regards,
    Igor

  8. #23
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Virtual Key Codes

    Quote Originally Posted by Igor Vartanov View Post
    Actually, GetModuleHandle(NULL) would be enough, as long as it is about getting main .exe instance handle.
    If it is, the instance handle is passed into WinMain(), and is typically saved in a global variable.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  9. #24
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Virtual Key Codes

    I'm almost sure it is, as nobody loads external .exe to the process.
    Best regards,
    Igor

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured