Advertisement
peterzig

[PIU] Tworzenie okna + MessageBox v2

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