Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h> // Podstawa do WinAPI
- #include <string>
- using namespace std;
- HWND hwnd, Res ,Pos;
- WNDCLASSEX window; // Zmienna klasy
- MSG msg; // Zmienna wydarzenia
- TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul"); // Tytuly TCHAR
- int NumberOfWindows = 0;
- int PositionX = 0, PositionY = 0;
- int Width = 0, Height = 0;
- RECT rect;
- 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:
- hwnd = CreateWindowEx(0, Class_Name, TEXT("Nowe Okno"), WS_OVERLAPPEDWINDOW, (100+(NumberOfWindows*10)), (100 + (NumberOfWindows * 10)), 500, 300, 0, 0, GetModuleHandle(0), 0);
- ShowWindow(hwnd, SW_SHOW);
- UpdateWindow(hwnd);
- break;
- case WM_SIZE:
- if (GetWindowRect(hwnd, &rect)) {
- Width = rect.right - rect.left;
- Height = rect.bottom - rect.top;
- SetWindowText(Res, TEXT(("Rozdzielczość: " + to_string(Width) + "x" + to_string(Height)).c_str()));
- }
- break;
- case WM_MOVE:
- InvalidateRect(hwnd, &rect, 1);
- PositionX = LOWORD(lParam);
- PositionY = HIWORD(lParam);
- SetWindowText(Pos, TEXT(("Pozycja: " + to_string(PositionY) + "x" + to_string(PositionX)).c_str()));
- 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);
- 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, 200-8, 200-31, 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;
- }
- string s = to_string(Width) + to_string(Height);
- Res = CreateWindowEx(NULL, "STATIC", TEXT(("Rozdzielczość: " + to_string(Width) + "x" + to_string(Height)).c_str()), WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 10, 200, 50, hwnd, NULL, hInstance, NULL);
- Pos = CreateWindowEx(NULL, "STATIC", TEXT(("Pozycja: " + to_string(PositionY) + "x" + to_string(PositionX)).c_str()), WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 60, 200, 50, hwnd, NULL, hInstance, NULL);
- 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