Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- using namespace std;
- // prozorska procedura
- HWND hwnd,hbutton1,hbutton2;
- int x = 10, y = 10;
- int CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
- HDC hdc;
- PAINTSTRUCT ps;
- int X = 0;
- switch (iMsg) {
- case WM_COMMAND:
- break;
- case WM_DESTROY: // Sistem javlja pokušaj gašenja prozora
- PostQuitMessage(0); // tada postavi poruku za napuštanje reda
- break;
- case WM_KEYUP:
- if (LOWORD (wParam) == VK_RIGHT) x += 10;
- else if (LOWORD (wParam) == VK_LEFT) x -= 10;
- else if (LOWORD (wParam) == VK_DOWN) y += 10;
- else if (LOWORD (wParam) == VK_UP) y -= 10;
- SetWindowPos(hbutton2, 0, x, y, 0, 0, 0x0001 | 0x0020 | 0x0040);
- break;
- case WM_PAINT:
- hdc = BeginPaint(hwnd, &ps); // Uzmi oznaku konteksta ure?aja
- // Ellipse(hdc,10,10,200,100);
- //TextOut(hdc, x, y, "Hello world!", 12); // Prikaži poruku
- EndPaint(hwnd, &ps); // Oslobodi kontekst ure?aja
- break;
- default: // Za ostale poruke standardno iscrtavanje
- return DefWindowProc(hwnd, iMsg, wParam,lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) // Ulazna taeka u program
- {
- //HWND hwnd,hbutton1,hbutton2;
- MSG msg;
- WNDCLASS wndclass;
- // Prozorska klasa je struktura koja se popuni prije kreiranja prozora
- wndclass.style = 0;
- wndclass.lpfnWndProc =
- (WNDPROC) WndProc; // Funkcija koja se izvrši kada ima poruka za prozore ove klase
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wndclass.hbrBackground =(HBRUSH)GetSysColorBrush(COLOR_3DFACE);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = "ExampleClass";
- RegisterClass(&wndclass); // Registruj prozorsku klasu
- hwnd = CreateWindowEx(512,"ExampleClass", "A joooj, vidi :P", WS_OVERLAPPEDWINDOW,
- 0, 0, 500,400, NULL, NULL, hInstance, NULL); // Kreiraj prozor prema klasi
- hbutton1 = CreateWindowEx(512,"BUTTON", "Pritisni me", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- 200, 200, 80,40, hwnd, (HMENU)1, hInstance, NULL); // Kreiraj prozor prema klasi
- hbutton2 = CreateWindowEx(512,"STATIC", "Hello World", WS_CHILD | WS_VISIBLE | ES_LEFT,
- 10,10, 170, 30, hwnd, (HMENU)2, hInstance, NULL); // Kreiraj prozor prema klasi
- ShowWindow(hwnd, iCmdShow); // Prikazi prozor
- UpdateWindow(hwnd);
- // Izvrsava se petlja koja rasporedjuje poruke
- while(GetMessage(&msg, NULL, 0, 0)) { // Kako stizu poruke
- TranslateMessage(&msg); // Razbija ih u dodatne
- DispatchMessage(&msg); // I salje u druge prozore
- }
- return msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement