Tranvick

Task4.cpp

Mar 9th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.09 KB | None | 0 0
  1. // Task4.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Task4.h"
  6.  
  7. #define MAX_LOADSTRING 100
  8.  
  9. // Global Variables:
  10. HINSTANCE hInst;                                // current instance
  11. TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  12. TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  13.  
  14. // Forward declarations of functions included in this code module:
  15. ATOM                MyRegisterClass(HINSTANCE hInstance);
  16. BOOL                InitInstance(HINSTANCE, int);
  17. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  18. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  19.  
  20. int APIENTRY _tWinMain(HINSTANCE hInstance,
  21.                      HINSTANCE hPrevInstance,
  22.                      LPTSTR    lpCmdLine,
  23.                      int       nCmdShow)
  24. {
  25.     UNREFERENCED_PARAMETER(hPrevInstance);
  26.     UNREFERENCED_PARAMETER(lpCmdLine);
  27.  
  28.     // TODO: Place code here.
  29.     MSG msg;
  30.     HACCEL hAccelTable;
  31.  
  32.     // Initialize global strings
  33.     LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  34.     LoadString(hInstance, IDC_TASK4, szWindowClass, MAX_LOADSTRING);
  35.     MyRegisterClass(hInstance);
  36.  
  37.     // Perform application initialization:
  38.     if (!InitInstance (hInstance, nCmdShow))
  39.     {
  40.         return FALSE;
  41.     }
  42.  
  43.     hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TASK4));
  44.  
  45.     // Main message loop:
  46.     while (GetMessage(&msg, NULL, 0, 0))
  47.     {
  48.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  49.         {
  50.             TranslateMessage(&msg);
  51.             DispatchMessage(&msg);
  52.         }
  53.     }
  54.  
  55.     return (int) msg.wParam;
  56. }
  57.  
  58.  
  59.  
  60. //
  61. //  FUNCTION: MyRegisterClass()
  62. //
  63. //  PURPOSE: Registers the window class.
  64. //
  65. //  COMMENTS:
  66. //
  67. //    This function and its usage are only necessary if you want this code
  68. //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
  69. //    function that was added to Windows 95. It is important to call this function
  70. //    so that the application will get 'well formed' small icons associated
  71. //    with it.
  72. //
  73. ATOM MyRegisterClass(HINSTANCE hInstance)
  74. {
  75.     WNDCLASSEX wcex;
  76.  
  77.     wcex.cbSize = sizeof(WNDCLASSEX);
  78.  
  79.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  80.     wcex.lpfnWndProc    = WndProc;
  81.     wcex.cbClsExtra     = 0;
  82.     wcex.cbWndExtra     = 0;
  83.     wcex.hInstance      = hInstance;
  84.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TASK4));
  85.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  86.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  87.     wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_TASK4);
  88.     wcex.lpszClassName  = szWindowClass;
  89.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  90.  
  91.     return RegisterClassEx(&wcex);
  92. }
  93.  
  94. //
  95. //   FUNCTION: InitInstance(HINSTANCE, int)
  96. //
  97. //   PURPOSE: Saves instance handle and creates main window
  98. //
  99. //   COMMENTS:
  100. //
  101. //        In this function, we save the instance handle in a global variable and
  102. //        create and display the main program window.
  103. //
  104. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  105. {
  106.    HWND hWnd;
  107.  
  108.    hInst = hInstance; // Store instance handle in our global variable
  109.  
  110.    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  111.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  112.  
  113.    if (!hWnd)
  114.    {
  115.       return FALSE;
  116.    }
  117.  
  118.    ShowWindow(hWnd, nCmdShow);
  119.    UpdateWindow(hWnd);
  120.  
  121.    return TRUE;
  122. }
  123.  
  124. //
  125. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  126. //
  127. //  PURPOSE:  Processes messages for the main window.
  128. //
  129. //  WM_COMMAND  - process the application menu
  130. //  WM_PAINT    - Paint the main window
  131. //  WM_DESTROY  - post a quit message and return
  132. //
  133. //
  134. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  135. {
  136.     int wmId, wmEvent;
  137.     PAINTSTRUCT ps;
  138.     RECT RC;
  139.     GetClientRect(hWnd, &RC);
  140.     HDC hdc;
  141.  
  142.     switch (message)
  143.     {
  144.     case WM_COMMAND:
  145.         wmId    = LOWORD(wParam);
  146.         wmEvent = HIWORD(wParam);
  147.         // Parse the menu selections:
  148.         switch (wmId)
  149.         {
  150.         case IDM_ABOUT:
  151.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  152.             break;
  153.         case IDM_EXIT:
  154.             DestroyWindow(hWnd);
  155.             break;
  156.         default:
  157.             return DefWindowProc(hWnd, message, wParam, lParam);
  158.         }
  159.         break;
  160.     case WM_PAINT:
  161.         hdc = BeginPaint(hWnd, &ps);
  162.         DrawText(hdc, L"Мама мыла раму", 15, &RC, DT_LEFT | DT_SINGLELINE);
  163.         DrawText(hdc, L"Мама мыла раму", 15, &RC, DT_RIGHT | DT_SINGLELINE);
  164.         DrawText(hdc, L"Мама мыла раму", 15, &RC, DT_RIGHT | DT_BOTTOM | DT_SINGLELINE);
  165.         DrawText(hdc, L"Мама мыла раму", 15, &RC, DT_LEFT | DT_SINGLELINE | DT_BOTTOM);
  166.         DrawText(hdc, L"Мама мыла раму", 15, &RC, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
  167.         EndPaint(hWnd, &ps);
  168.         break;
  169.     case WM_DESTROY:
  170.         PostQuitMessage(0);
  171.         break;
  172.     default:
  173.         return DefWindowProc(hWnd, message, wParam, lParam);
  174.     }
  175.     return 0;
  176. }
  177.  
  178. // Message handler for about box.
  179. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  180. {
  181.     UNREFERENCED_PARAMETER(lParam);
  182.     switch (message)
  183.     {
  184.     case WM_INITDIALOG:
  185.         return (INT_PTR)TRUE;
  186.  
  187.     case WM_COMMAND:
  188.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  189.         {
  190.             EndDialog(hDlg, LOWORD(wParam));
  191.             return (INT_PTR)TRUE;
  192.         }
  193.         break;
  194.     }
  195.     return (INT_PTR)FALSE;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment