C++ method for handling keyboard input

  • 2020-04-02 02:52:40
  • OfStack

In this paper, the example of C++ processing keyboard input method, can achieve a simple process of keyboard input, to share for your reference. The specific implementation method is as follows:

Need to respond to WM_CHAR message:

#include <string>
static std::string str;

In the wm_char:
str = str + char(wParam);  
::InvalidateRect(hWnd, NULL, 0); 
return 0;
 
In the wm_paint:
case WM_PAINT:  
    hdc = BeginPaint(hWnd, &ps); 
    //TODO: add arbitrary drawing code here... & have spent < br / >     ::TextOut(hdc, 0, 0, str.c_str(),str.length()); 
    EndPaint(hWnd, &ps); 
    break;

Hope that the article described in the C++ programming to help you.


Related articles: