Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. using namespace std;
  4. // prozorska procedura
  5. HWND hwnd,hbutton1,hbutton2;
  6. int x = 10, y = 10;
  7. int CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
  8. HDC hdc;
  9. PAINTSTRUCT ps;
  10. int X = 0;
  11.  
  12. switch (iMsg) {
  13. case WM_COMMAND:
  14. break;
  15. case WM_DESTROY: // Sistem javlja pokušaj gašenja prozora
  16. PostQuitMessage(0); // tada postavi poruku za napuštanje reda
  17. break;
  18. case WM_KEYUP:
  19. if (LOWORD (wParam) == VK_RIGHT) x += 10;
  20. else if (LOWORD (wParam) == VK_LEFT) x -= 10;
  21. else if (LOWORD (wParam) == VK_DOWN) y += 10;
  22. else if (LOWORD (wParam) == VK_UP) y -= 10;
  23. SetWindowPos(hbutton2, 0, x, y, 0, 0, 0x0001 | 0x0020 | 0x0040);
  24. break;
  25. case WM_PAINT:
  26. hdc = BeginPaint(hwnd, &ps); // Uzmi oznaku konteksta ure?aja
  27. // Ellipse(hdc,10,10,200,100);
  28. //TextOut(hdc, x, y, "Hello world!", 12); // Prikaži poruku
  29. EndPaint(hwnd, &ps); // Oslobodi kontekst ure?aja
  30. break;
  31. default: // Za ostale poruke standardno iscrtavanje
  32. return DefWindowProc(hwnd, iMsg, wParam,lParam);
  33. }
  34. return 0;
  35. }
  36.  
  37. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) // Ulazna taeka u program
  38. {
  39. //HWND hwnd,hbutton1,hbutton2;
  40. MSG msg;
  41. WNDCLASS wndclass;
  42. // Prozorska klasa je struktura koja se popuni prije kreiranja prozora
  43. wndclass.style = 0;
  44. wndclass.lpfnWndProc =
  45. (WNDPROC) WndProc; // Funkcija koja se izvrši kada ima poruka za prozore ove klase
  46. wndclass.cbClsExtra = 0;
  47. wndclass.cbWndExtra = 0;
  48. wndclass.hInstance = hInstance;
  49. wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  50. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  51. wndclass.hbrBackground =(HBRUSH)GetSysColorBrush(COLOR_3DFACE);
  52. wndclass.lpszMenuName = NULL;
  53. wndclass.lpszClassName = "ExampleClass";
  54. RegisterClass(&wndclass); // Registruj prozorsku klasu
  55. hwnd = CreateWindowEx(512,"ExampleClass", "A joooj, vidi :P", WS_OVERLAPPEDWINDOW,
  56. 0, 0, 500,400, NULL, NULL, hInstance, NULL); // Kreiraj prozor prema klasi
  57. hbutton1 = CreateWindowEx(512,"BUTTON", "Pritisni me", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  58. 200, 200, 80,40, hwnd, (HMENU)1, hInstance, NULL); // Kreiraj prozor prema klasi
  59. hbutton2 = CreateWindowEx(512,"STATIC", "Hello World", WS_CHILD | WS_VISIBLE | ES_LEFT,
  60. 10,10, 170, 30, hwnd, (HMENU)2, hInstance, NULL); // Kreiraj prozor prema klasi
  61.  
  62. ShowWindow(hwnd, iCmdShow); // Prikazi prozor
  63. UpdateWindow(hwnd);
  64. // Izvrsava se petlja koja rasporedjuje poruke
  65. while(GetMessage(&msg, NULL, 0, 0)) { // Kako stizu poruke
  66. TranslateMessage(&msg); // Razbija ih u dodatne
  67. DispatchMessage(&msg); // I salje u druge prozore
  68. }
  69. return msg.wParam;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement