vakho

Win API 1

Mar 12th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.04 KB | None | 0 0
  1. // Win32Project1.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Win32Project1.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(_In_ HINSTANCE hInstance, // Application identificator
  21.                      _In_opt_ HINSTANCE hPrevInstance,
  22.                      _In_ LPTSTR    lpCmdLine, // Command line params: "myApp [params]"
  23.                      _In_ int       nCmdShow) // State of application window (minimized, maximized and etc.)
  24. {
  25.     UNREFERENCED_PARAMETER(hPrevInstance);
  26.     UNREFERENCED_PARAMETER(lpCmdLine);
  27.  
  28.     // TODO: Place code here.
  29.     MSG msg; // Message to hold messages from message queue
  30.     HACCEL hAccelTable; // hold accelerator table addresses (Ctrl + R and etc.)
  31.  
  32.     // Initialize global strings
  33.  
  34.     // Move data in array...
  35.     LoadString(hInstance, VAKHO_TITLE, szTitle, MAX_LOADSTRING); // Load string from application resources (.rc) - String Table
  36.     LoadString(hInstance, IDC_WIN32PROJECT1, szWindowClass, MAX_LOADSTRING);
  37.     MyRegisterClass(hInstance);
  38.  
  39.     // Perform application initialization:
  40.     if (!InitInstance(hInstance, nCmdShow))
  41.     {
  42.         return FALSE;
  43.     }
  44.  
  45.     hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT1));
  46.  
  47.     // Main message loop:
  48.     while (GetMessage(&msg, NULL, 0, 0))
  49.     {
  50.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  51.         {
  52.             TranslateMessage(&msg);
  53.             DispatchMessage(&msg);
  54.         }
  55.     }
  56.  
  57.     return (int) msg.wParam;
  58. }
  59.  
  60.  
  61.  
  62. //
  63. //  FUNCTION: MyRegisterClass()
  64. //
  65. //  PURPOSE: Registers the window class.
  66. //
  67. ATOM MyRegisterClass(HINSTANCE hInstance)
  68. {
  69.     WNDCLASSEX wcex;
  70.  
  71.     wcex.cbSize = sizeof(WNDCLASSEX);
  72.  
  73.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  74.     wcex.lpfnWndProc    = WndProc;
  75.     wcex.cbClsExtra     = 0;
  76.     wcex.cbWndExtra     = 0;
  77.     wcex.hInstance      = hInstance;
  78.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32PROJECT1)); // Gets from our resources
  79.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW); // Gets from windows
  80.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  81.     wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_WIN32PROJECT1);
  82.     wcex.lpszClassName  = szWindowClass;
  83.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  84.  
  85.     return RegisterClassEx(&wcex); // WinAPI function returns unsigned char
  86. }
  87.  
  88. //
  89. //   FUNCTION: InitInstance(HINSTANCE, int)
  90. //
  91. //   PURPOSE: Saves instance handle and creates main window
  92. //
  93. //   COMMENTS:
  94. //
  95. //        In this function, we save the instance handle in a global variable and
  96. //        create and display the main program window.
  97. //
  98. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  99. {
  100.    HWND hWnd;
  101.  
  102.    hInst = hInstance; // Store instance handle in our global variable
  103.  
  104.    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  105.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  106.  
  107.    if (!hWnd)
  108.    {
  109.       return FALSE;
  110.    }
  111.  
  112.    ShowWindow(hWnd, nCmdShow);
  113.    UpdateWindow(hWnd);
  114.  
  115.    return TRUE;
  116. }
  117.  
  118. //
  119. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  120. //
  121. //  PURPOSE:  Processes messages for the main window.
  122. //
  123. //  WM_COMMAND  - process the application menu
  124. //  WM_PAINT    - Paint the main window
  125. //  WM_DESTROY  - post a quit message and return
  126. //
  127. //
  128. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  129. {
  130.     int wmId, wmEvent;
  131.     PAINTSTRUCT ps;
  132.     HDC hdc;
  133.  
  134.     switch (message)
  135.     {
  136.     case WM_CREATE:
  137.         MessageBox(hWnd, L"Hello!", L"Title", 0);
  138.         break;
  139.     case WM_COMMAND:
  140.         wmId    = LOWORD(wParam);
  141.         wmEvent = HIWORD(wParam);
  142.         // Parse the menu selections:
  143.         switch (wmId)
  144.         {
  145.         case IDM_ABOUT:
  146.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  147.             break;
  148.         case IDM_EXIT:
  149.             DestroyWindow(hWnd);
  150.             break;
  151.         default:
  152.             return DefWindowProc(hWnd, message, wParam, lParam);
  153.         }
  154.         break;
  155.     case WM_PAINT:
  156.         hdc = BeginPaint(hWnd, &ps);
  157.         // TODO: Add any drawing code here...
  158.         EndPaint(hWnd, &ps);
  159.         break;
  160.     case WM_DESTROY:
  161.         PostQuitMessage(0); // Add exit message to queue!
  162.         break;
  163.     case WM_CLOSE:
  164.         if (MessageBox(hWnd, L"მართლა?", L"კითხვა მაქვს :დ", 4) == IDYES) {
  165.             DestroyWindow(hWnd);
  166.         }
  167.         break;
  168.     default:
  169.         return DefWindowProc(hWnd, message, wParam, lParam);
  170.     }
  171.     return 0;
  172. }
  173.  
  174. // Message handler for about box.
  175. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  176. {
  177.     UNREFERENCED_PARAMETER(lParam);
  178.     switch (message)
  179.     {
  180.     case WM_INITDIALOG:
  181.         return (INT_PTR)TRUE;
  182.  
  183.     case WM_COMMAND:
  184.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  185.         {
  186.             EndDialog(hDlg, LOWORD(wParam));
  187.             return (INT_PTR)TRUE;
  188.         }
  189.         break;
  190.     }
  191.     return (INT_PTR)FALSE;
  192. }
Advertisement
Add Comment
Please, Sign In to add comment