2008年3月1日9时50分

  1. #include    
  2. #include "winevent.hpp"   
  3.   
  4. #include    
  5. #include    
  6.   
  7. int nInt = 0;   
  8. int nStart = 0;   
  9. int nEnd = 0;   
  10. char buf[255];   
  11.   
  12. //////////////////////////////////////////////////////////////   
  13. // Event handlers   
  14.   
  15. template<>   
  16. LRESULT OnMsg(HWND hWnd, WPARAM wParam, LPARAM lParam)   
  17. {   
  18.     strcpy(buf, "Press any key to start test");   
  19.     return DefWindowProc(hWnd, WM_CREATE, wParam, lParam);   
  20. }   
  21.   
  22. template<>   
  23. LRESULT OnMsg(HWND hWnd, WPARAM wParam, LPARAM lParam)   
  24. {   
  25.     nInt = 0;   
  26.     strcpy(buf, "running test, please wait ...");   
  27.     InvalidateRect(hWnd, NULL, true);   
  28.     SendMessage(hWnd, WM_PAINT, 0, 0);   
  29.     nStart = GetTickCount();   
  30.     PostMessage(hWnd, WM_TIMER, 0, 0);   
  31.     return DefWindowProc(hWnd, WM_KEYDOWN, wParam, lParam);   
  32. }   
  33.   
  34. template<>   
  35. LRESULT OnMsg(HWND hWnd, WPARAM wParam, LPARAM lParam)   
  36. {   
  37.     if (nInt++ < 100000) {   
  38.         PostMessage(hWnd, WM_TIMER, 0, 0);   
  39.     } else {   
  40.         nEnd = GetTickCount();   
  41.         sprintf(buf, "Time elapsed = %d msec",    
  42.         ((nEnd - nStart) * 1000) / CLOCKS_PER_SEC);   
  43.         InvalidateRect(hWnd, NULL, true);   
  44.     }   
  45.     return 0;   
  46. }   
  47.   
  48. template<>   
  49. LRESULT OnMsg(HWND hWnd, WPARAM wParam, LPARAM lParam)   
  50. {   
  51.     PostQuitMessage(0);   
  52.     return 0;   
  53. }   
  54.   
  55. template<>   
  56. LRESULT OnMsg(HWND hWnd, WPARAM wParam, LPARAM lParam)   
  57. {   
  58.     PAINTSTRUCT ps;   
  59.     HDC hdc;   
  60.     hdc = BeginPaint(hWnd, &ps);   
  61.     TextOut(hdc, 100, 100, buf, static_cast<int>(strlen(buf)));   
  62.     EndPaint(hWnd, &ps);   
  63.     return DefWindowProc(hWnd, WM_PAINT, wParam, lParam);   
  64. }   
  65.   
  66. /****************************************************  
  67. // Entry point for the application.  
  68. ****************************************************/  
  69.   
  70. int WINAPI WinMain(HINSTANCE hInstance,    
  71. HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)   
  72. {   
  73.     InitMsgHandlers();   
  74.        
  75.     static char szAppName[] = "demo";   
  76.     HWND        hwnd;   
  77.     MSG         msg;   
  78.     WNDCLASSEX  wndclass;   
  79.        
  80.     wndclass.cbSize         = sizeof(wndclass);   
  81.     wndclass.style          = CS_HREDRAW | CS_VREDRAW;   
  82.     wndclass.lpfnWndProc    = WndProc;   
  83.     wndclass.cbClsExtra     = 0;   
  84.     wndclass.cbWndExtra     = 0;   
  85.     wndclass.hInstance      = hInstance;   
  86.     wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);   
  87.     wndclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);   
  88.     wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);   
  89.     wndclass.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);   
  90.     wndclass.lpszClassName  = szAppName;   
  91.     wndclass.lpszMenuName   = NULL;   
  92.        
  93.     RegisterClassEx(&wndclass);   
  94.        
  95.     hwnd = CreateWindow(szAppName, "Static Dispatch Demo",   
  96.     WS_OVERLAPPEDWINDOW,   
  97.     CW_USEDEFAULT, CW_USEDEFAULT,   
  98.     CW_USEDEFAULT, CW_USEDEFAULT,   
  99.     NULL, NULL, hInstance, NULL);   
  100.        
  101.     ShowWindow(hwnd, nCmdShow);   
  102.     UpdateWindow(hwnd);   
  103.        
  104.     while ( GetMessage(&msg, NULL, 0, 0) ) {   
  105.         TranslateMessage(&msg);   
  106.         DispatchMessage(&msg);   
  107.     }   
  108.     return static_cast<int>(msg.wParam);   
  109. }   

投 票

觉得本文不错,投一票   

评 论


验证码: 看不清?换一张