⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboardtest.cpp

📁 WINCE ARM9三星2440下的按键驱动验证程序
💻 CPP
字号:
// KeyBoardTest.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "KeyBoardTest.h"

// Program entry point
int WINAPI WinMain (HINSTANCE hInstance, 
					HINSTANCE hPrevInstance,
                    LPWSTR lpCmdLine, 
					int nCmdShow) 
{
    MSG msg;
    int rc = 0;
    HWND hwndMain;

    // init application
    rc = InitApp (hInstance);
    if (rc) return rc;


    // Initialize this instance.
    hwndMain = InitInstance (hInstance, lpCmdLine, nCmdShow);
    if (hwndMain == 0)
        return 0x10;

    // Application message loop
    while (GetMessage (&msg, NULL, 0, 0)) 
	{
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }
    return msg.wParam;
}
//----------------------------------------------------------------------
// InitApp - Application initialization
//
int InitApp (HINSTANCE hInstance) 
{
    WNDCLASS wc;

    // Register application main window class.
    wc.style = CS_HREDRAW | CS_VREDRAW,//0;                             // Window style
    wc.lpfnWndProc = MainWndProc;             // Callback function
    wc.cbClsExtra = 0;                        // Extra class data
    wc.cbWndExtra = 0;                        // Extra window data
    wc.hInstance = hInstance;                 // Owner handle
    wc.hIcon = NULL,                          // Application icon
    wc.hCursor = NULL;                        // Default cursor
    wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName =  NULL;                  // Menu name
    wc.lpszClassName = szAppName;             // Window class name

    if ( !RegisterClass (&wc)) 
	{
	    MessageBox(NULL, _T("program requires Windows NT!"),_T("error"), MB_ICONERROR);
		return 1;
	}
	return 0;
}


//----------------------------------------------------------------------
// InitInstance - Instance initialization
//
HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine,
                   int nCmdShow) 
{
    HWND hWnd;

    // Save program instance handle in global variable.
    hInst = hInstance;

    // Create main window.
    hWnd = CreateWindow (szAppName,               // Window class
                         NULL,                    // Window title
                         WS_VISIBLE,              // Style flags
                         0,//CW_USEDEFAULT,       // x position
                         0,//CW_USEDEFAULT,       // y position
                         320,//CW_USEDEFAULT,     // Initial width
                         240,//CW_USEDEFAULT,     // Initial height
                         NULL,                    // Parent
                         NULL,                    // Menu, must be null
                         hInstance,               // Application instance
                         NULL);                   // Pointer to create parameters

    // Return fail code if window not created.
    if (!IsWindow (hWnd)) return 0;
    // Standard show and update calls
    ShowWindow (hWnd, nCmdShow);
    UpdateWindow (hWnd);
    return hWnd;
}
//======================================================================
// Message handling procedures for main window
//----------------------------------------------------------------------
// MainWndProc - Callback function for application window
//
LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,LPARAM lParam) 
{
  HDC          hdc;//hdcMem ;
  HINSTANCE    hInstance = NULL ;
  int          X_mouse,Y_mouse;
  PAINTSTRUCT  ps ;

  BOOL resurt = FALSE ;

  switch (wMsg)      
    {       
    case   WM_CREATE:     //  hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;//通过CREATESTRUCT结构获得	                  
		                  hInstance = hInst;  //获得窗体的实例句柄						  
                          return 0 ;      
    case   WM_PAINT:      hdc = BeginPaint (hWnd, &ps) ;					
						  LoadResourceImage(hWnd, MAKEINTRESOURCE(IDR_BackGround), _T("JPG"), 0, 0, 320, 240);                        				 
						  EndPaint (hWnd, &ps) ;	
                          return 0 ;   
	case   WM_SIZE:       return 0 ;   
	case   WM_ACTIVATE:   DoActivateMain (hWnd, wMsg, wParam, lParam); //发此消息给应用程序哪个窗口是激活的,哪个是非激活的;
						  return 0 ;  
    case   WM_DESTROY:    PostQuitMessage (0);                         //一个窗口被销毁    
                          return 0 ;
    case   WM_LBUTTONDOWN: 	
//			              MessageBox(NULL, _T("program requires Windows NT!"),_T("error"), MB_ICONERROR);
//					      DEBUGMSG(1, (TEXT("Key: DLL_PROCESS_ATTACH\r\n")));
						  X_mouse = LOWORD (lParam) ;
						  Y_mouse = HIWORD (lParam) ;                         
/******************* get the position of mouse*********************/
//   					  TCHAR buffer[1024]; 
//                        wsprintf(buffer, TEXT("X_mouse is %d,Y_mouse is %d"), X_mouse, Y_mouse); 
//						  MessageBox(NULL, buffer, TEXT("Data Report"), MB_OK | MB_ICONASTERISK); 
/********************the end**************************************/
						  if(X_mouse > 160)
						  {
							 LoadKeyboardDriver() ;
						     OpenKeyboardDriver(hWnd) ;
						  }

						  else 
						  {							  
							  CloseKeyboardDriver();							  
						      UnLoadKeyboardDriver();
						  }
						  return 0 ;
     case   WM_LBUTTONUP: 
		                  return 0 ;
	 case   WM_COMMAND:   return 0 ;
  }        
	return DefWindowProc (hWnd, wMsg, wParam, lParam);
}

//----------------------------------------------------------------------
// DoActivateMain - Process WM_ACTIVATE message for window.
// X 栏
LRESULT DoActivateMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                        LPARAM lParam) 
{
    HWND hwndCB;

    // If activating and no command bar, create it.
    if ((LOWORD (wParam) != WA_INACTIVE) &&
        (GetDlgItem (hWnd, IDC_CMDBAR) == 0)) {

        // Create a command bar.
        hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);

        // Add exit button to command bar. 
        CommandBar_AddAdornments (hwndCB, 0, 0);
    }
    return 0;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -