Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h> // Podstawa do WinAPI
- HWND hwnd, NewHwnd;
- WNDCLASSEX window; // Zmienna klasy
- MSG msg; // Zmienna wydarzenia
- TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul"); // Tytuly TCHAR
- int NumberOfWindows = 0, PosuitionX = 0, PositionY = 0;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {//Funkcja eventów
- switch (msg) {
- case WM_CREATE:
- NumberOfWindows++;
- UpdateWindow(hwnd);
- break;
- case WM_COMMAND: break;// Eventy uzytkownika
- case WM_CLOSE:// Event zamkniecia
- if (MessageBox(0, TEXT("Zamknac to okno?"), TEXT("?"), MB_YESNO | MB_ICONQUESTION) == IDYES) {
- NumberOfWindows--;
- DestroyWindow(hwnd);
- }
- break;
- case WM_DESTROY:// Event zamkniecia
- if (NumberOfWindows == 0) {
- MessageBox(0, TEXT("KONIEC!"), TEXT("KONIEC!"), MB_OK);
- PostQuitMessage(0);
- }
- break;
- case WM_LBUTTONDOWN:
- NewHwnd = CreateWindowEx(0, Class_Name, TEXT("Nowe Okno"), WS_OVERLAPPEDWINDOW, 100, 100, 500, 300, 0, 0, GetModuleHandle(0), 0);
- ShowWindow(NewHwnd, SW_SHOW);
- UpdateWindow(NewHwnd);
- break;
- case WM_SIZE:
- break;
- default:// Nieznany event
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- bool Register_Class(HINSTANCE &hInstance) {
- window.cbClsExtra = NULL;// Wypelnianie klasy okna //
- window.cbSize = sizeof(WNDCLASSEX);
- window.cbWndExtra = NULL;
- window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- window.hCursor = LoadCursor(NULL, IDC_ARROW);
- window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- window.hInstance = hInstance;
- window.lpfnWndProc = WndProc;
- window.lpszClassName = Class_Name;
- window.lpszMenuName = 0;
- window.style = CS_VREDRAW | CS_HREDRAW;
- return RegisterClassEx(&window);
- }
- void Unregister_Window(HINSTANCE &hInstance) {
- if (!UnregisterClass(Class_Name, hInstance)) { // Niszczenie okna ....
- MessageBox(NULL, TEXT("Błąd niszczenia okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
- }
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) { // main
- Register_Class(hInstance);
- if (!Register_Class) { // Rejestracja klasy okna .... jesli blad STOP
- MessageBox(NULL, TEXT("Błąd rejestracji okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
- return 0;
- }
- hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL); //Tworzenie okna
- if (hwnd == NULL) {//Sprawdzanie czy okno zostalo stworzeona
- MessageBox(NULL, TEXT("Błąd tworzenia okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow); // Wyswietlenie okna
- UpdateWindow(hwnd); // Aktualizacja okna
- while (GetMessage(&msg, NULL, 0, 0)) { // Petla eventow
- TranslateMessage(&msg); // tlumacznie eventu
- DispatchMessage(&msg); // Wykonywanie eventu
- }
- Unregister_Window(hInstance);
- return msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement