Application Example of the mouse and application example of the mouse

Source: Internet
Author: User

Application Example of the mouse and application example of the mouse

1 # include <Windows. h> 2 # include <tchar. h> 3 BOOLEAN InitWindowClass (HINSTANCE hInstance, int nCmdShow); 4 lresult callback WndProc (HWND, UINT, WPARAM, LPARAM); 5 HFONT CreateFont (HDC hDC, int nCharHeight, BOOL bItalic); 6 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 7 {8 MSG; 9 if (! InitWindowClass (hInstance, nCmdShow) 10 {11 MessageBox (NULL, L "window creation failed! ", _ T (" create window "), NULL); 12 return 1; 13} 14 while (GetMessage (& msg, NULL, 0, 0 )) 15 {16 TranslateMessage (& msg); 17 DispatchMessage (& msg); 18} 19 return (int) msg. wParam; 20} 21 lresult callback WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 22 {23 HDC hDC; 24 HFONT hF; 25 PAINTSTRUCT ps; 26 TEXTMETRIC tm; 27 TCHAR str [] = L "Hello World"; 28 int I = 0; 29 static int x [13], y [13]; 30 static int color [13]; 31 POINT pt; 32 switch (message) 33 {34 case WM_CREATE: 35 SetTimer (hWnd, 1111,200, NULL); 36 GetCursorPos (& pt ); 37 ScreenToClient (hWnd, & pt); 38 for (I = 0; I <13; I ++) 39 {40 x [I] = pt. x + (I-1) * 40; 41 y [I] = pt. y; 42 color [I] = 25 * (I-1); 43} 44 break; 45 case WM_PAINT: 46 hDC = BeginPaint (hWnd, & ps ); 47 hF = CreateFont (hDC, 40, 0); 48 SelectObject (hDC, hF ); 49 for (I = 12; I> 1; I --) 50 {51 x [I] = x [I-1] + 40; 52 y [I] = y [I-1]; 53} 54 GetCursorPos (& pt); 55 ScreenToClient (hWnd, & pt); 56 x [1] = pt. x; 57 y [1] = pt. y; 58 for (I = 1; I <13; I ++) 59 {60 SetTextColor (hDC, RGB (255-color [I], color [I], 255); 61 TextOut (hDC, x [I], y [I], & str [I], 1 ); 62} 63 color [1] = color [12]; 64 for (I = 12; I> 1; I --) 65 color [I] = color [I-1]; 66 DeleteObjec T (hF); 67 EndPaint (hWnd, & ps); 68 break; 69 case WM_TIMER: 70 if (wParam = 1111) 71 InvalidateRect (hWnd, NULL, 1 ); 72 break; 73 case WM_DESTROY: 74 PostQuitMessage (0); 75 break; 76 default: 77 return DefWindowProc (hWnd, message, wParam, lParam); 78 break; 79} 80 return 0; 81} 82 BOOLEAN InitWindowClass (HINSTANCE hInstance, int nCmdShow) 83 {84 WNDCLASSEX wcex; 85 HWND hWnd; 86 TCHAR szWindowCl Ass [] = L "window example"; 87 TCHAR szTitle [] = L "Mouse application example"; 88 wcex. cbSize = sizeof (WNDCLASSEX); 89 wcex. style = 0; 90 wcex. lpfnWndProc = WndProc; 91 wcex. cbClsExtra = 0; 92 wcex. cbWndExtra = 0; 93 wcex. hInstance = hInstance; 94 wcex. hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_APPLICATION); 95 wcex. hCursor = LoadCursor (NULL, IDC_ARROW); 96 wcex. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); 97 wc Ex. lpszMenuName = NULL; 98 wcex. lpszClassName = szWindowClass; 99 wcex. hIconSm = LoadIcon (wcex. hInstance, MAKEINTRESOURCE (IDI_APPLICATION); 100 if (! RegisterClassEx (& wcex) 101 return FALSE; 102 hWnd = CreateWindow (103 szWindowClass, 104 szTitle, 105 WS_OVERLAPPEDWINDOW, 106 CW_USEDEFAULT, CW_USEDEFAULT, 107 CW_USEDEFAULT, CW_USEDEFAULT, 108 NULL, 109 NULL, 110 hInstance, 111 NULL112); 113 if (! HWnd) 114 return FALSE; 115 ShowWindow (hWnd, nCmdShow); 116 UpdateWindow (hWnd); 117 return TRUE; 118} 119 HFONT CreateFont (HDC hDC, int nCharHeight, BOOL bItalic) 120 {121 HFONT hFont; 122 hFont = CreateFont (123 nCharHeight, 124 0,125 0,126 0,127 bItalic, 400,128 129 0,130 ANSI_CHARSET, 0,131 OUT_DEFAULT_PRECIS, 132 bytes, 133 DEFAULT_QUALITY, 134 DEFAULT_PITCH | FF_DONTCARE, 136 L "Arial" 137); 138 if (hFont = NULL) 139 return NULL; 140 else141 return hFont; 142}

No effect found ^-^

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.