peterzig

[PIU] Tworzenie okna + MessageBox

Oct 8th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.16 KB | None | 0 0
  1. #include <Windows.h>
  2. //-------Zmienne i funkcje globalne.
  3. //-------Zmienne globalne.
  4. TCHAR EndCaption[] = TEXT("Zamykanie aplikacji");
  5. TCHAR EndText[] = TEXT("Czy chcesz zamknąć aplikację?");
  6.  
  7. //Komunikaty
  8. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  9. {
  10.     HDC hdc;
  11.     switch (msg)
  12.     {
  13.     case WM_PAINT:
  14.     {
  15.         PAINTSTRUCT ps;
  16.         hdc = BeginPaint(hwnd, &ps);
  17.         //Rysowanie:
  18.         EndPaint(hwnd, &ps);
  19.         break;
  20.     }
  21.  
  22.     case WM_LBUTTONDOWN:
  23.         hdc = GetDC(hwnd);
  24.         ReleaseDC(hwnd, hdc);
  25.         break;
  26.  
  27.     case WM_CREATE:
  28.         break;
  29.  
  30.     case WM_CLOSE:
  31.         if (MessageBox(hwnd, EndText, EndCaption, MB_YESNO) == IDYES) {
  32.             DestroyWindow(hwnd);
  33.         }
  34.         break;
  35.  
  36.     case WM_DESTROY:
  37.         PostQuitMessage(0);
  38.         break;
  39.  
  40.     default:
  41.         return DefWindowProc(hwnd, msg, wParam, lParam);
  42.     }
  43.  
  44.     return 0;
  45. }
  46.  
  47. //Main
  48. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow)
  49. {
  50.     WNDCLASSEX window;
  51.     HWND hwnd = NULL;
  52.     MSG msg;
  53.     TCHAR Class_Name[] = TEXT("OKNO_TEST");
  54.     TCHAR Title[] = TEXT("Typowa Aplikacja WinAPI");
  55.  
  56.     window.cbClsExtra = NULL;
  57.     window.cbSize = sizeof(WNDCLASSEX);
  58.     window.cbWndExtra = NULL;
  59.     window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  60.     window.hCursor = LoadCursor(NULL, IDC_ARROW);
  61.     window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  62.     window.hIconSm = NULL;
  63.     window.hInstance = hInstance;
  64.     window.lpfnWndProc = WndProc;
  65.     window.lpszClassName = Class_Name;
  66.     window.lpszMenuName = 0;
  67.     window.style = CS_VREDRAW | CS_HREDRAW;
  68.  
  69.     RegisterClassEx(&window);
  70.  
  71.     hwnd = ((CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title,
  72.         WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
  73.         800, 600, NULL, NULL, hInstance, NULL)));
  74.  
  75.     ShowWindow(hwnd, nCmdShow);
  76.     UpdateWindow(hwnd);
  77.  
  78.     while (GetMessage(&msg, NULL, 0, 0))
  79.     {
  80.         TranslateMessage(&msg);
  81.         DispatchMessage(&msg);
  82.     }
  83.     UnregisterClass(Class_Name, hInstance);
  84.     return msg.wParam;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment