Guest User

Untitled

a guest
Apr 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.74 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <tchar.h>
  5.  
  6. // Global variables
  7.  
  8. // The main window class name.
  9. static TCHAR szWindowClass[] = _T("win32app");
  10.  
  11. // The string that appears in the application's title bar.
  12. static TCHAR szTitle[] = _T("my_app");
  13.  
  14. HINSTANCE hInst;
  15.  
  16. // Forward declarations of functions included in this code module:
  17. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  18.  
  19. int WINAPI WinMain(HINSTANCE hInstance,
  20.                    HINSTANCE hPrevInstance,
  21.                    LPSTR lpCmdLine,
  22.                    int nCmdShow)
  23. {
  24.     WNDCLASSEX wcex;
  25.  
  26.     wcex.cbSize = sizeof(WNDCLASSEX);
  27.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  28.     wcex.lpfnWndProc    = WndProc;
  29.     wcex.cbClsExtra     = 0;
  30.     wcex.cbWndExtra     = 0;
  31.     wcex.hInstance      = hInstance;
  32.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  33.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  34.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  35.     wcex.lpszMenuName   = NULL;
  36.     wcex.lpszClassName  = szWindowClass;
  37.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  38.  
  39.     if (!RegisterClassEx(&wcex))
  40.     {
  41.         MessageBox(NULL,
  42.             _T("Call to RegisterClassEx failed!"),
  43.             _T("my_app"),
  44.             NULL);
  45.  
  46.         return 1;
  47.     }
  48.  
  49.     hInst = hInstance; // Store instance handle in our global variable
  50.  
  51.     // The parameters to CreateWindow explained:
  52.     // szWindowClass: the name of the application
  53.     // szTitle: the text that appears in the title bar
  54.     // WS_OVERLAPPEDWINDOW: the type of window to create
  55.     // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
  56.     // 500, 100: initial size (width, length)
  57.     // NULL: the parent of this window
  58.     // NULL: this application does not have a menu bar
  59.     // hInstance: the first parameter from WinMain
  60.     // NULL: not used in this application
  61.     HWND hWnd = CreateWindow(
  62.         szWindowClass,
  63.         szTitle,
  64.         WS_OVERLAPPEDWINDOW,
  65.         CW_USEDEFAULT, CW_USEDEFAULT,
  66.         640, 480,
  67.         NULL,
  68.         NULL,
  69.         hInstance,
  70.         NULL
  71.     );
  72.  
  73.     if (!hWnd)
  74.     {
  75.         MessageBox(NULL,
  76.             _T("Call to CreateWindow failed!"),
  77.             _T("Win32 Guided Tour"),
  78.             NULL);
  79.  
  80.         return 1;
  81.     }
  82.  
  83.     // The parameters to ShowWindow explained:
  84.     // hWnd: the value returned from CreateWindow
  85.     // nCmdShow: the fourth parameter from WinMain
  86.     ShowWindow(hWnd,
  87.         nCmdShow);
  88.     UpdateWindow(hWnd);
  89.  
  90.     // Main message loop:
  91.     MSG msg;
  92.     while (GetMessage(&msg, NULL, 0, 0))
  93.     {
  94.         TranslateMessage(&msg);
  95.         DispatchMessage(&msg);
  96.     }
  97.  
  98.     return (int) msg.wParam;
  99. }
  100.  
  101. //
  102. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  103. //
  104. //  PURPOSE:  Processes messages for the main window.
  105. //
  106. //  WM_PAINT    - Paint the main window
  107. //  WM_DESTROY  - post a quit message and return
  108. //
  109. //
  110. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  111. {
  112.     PAINTSTRUCT ps;
  113.     HDC hdc;
  114.     TCHAR greeting[] = _T("Hello, World!");
  115.  
  116.     switch (message)
  117.     {
  118.     case WM_PAINT:
  119.         hdc = BeginPaint(hWnd, &ps);
  120.  
  121.         // Here your application is laid out.
  122.         // For this introduction, we just print out "Hello, World!"
  123.         // in the top left corner.
  124.         TextOut(hdc,
  125.             100, 200,
  126.             greeting, _tcslen(greeting));
  127.         // End application-specific layout section.
  128.  
  129.         EndPaint(hWnd, &ps);
  130.         break;
  131.     case WM_DESTROY:
  132.         PostQuitMessage(0);
  133.         break;
  134.     default:
  135.         return DefWindowProc(hWnd, message, wParam, lParam);
  136.         break;
  137.     }
  138.  
  139.     return 0;
  140. }
Add Comment
Please, Sign In to add comment