vovan333

ohoohohoh

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