Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. /*************************************************************/
  2. /* Programowanie Interfejsu Użytkownika - Dawid Tomczyk */
  3. /*************************************************************/
  4.  
  5. #include <Windows.h>
  6.  
  7. TCHAR nazwa[] = TEXT ("Cwiczenie przed laborkami 2");
  8. TCHAR buff[128];
  9. HWND okno[10];
  10. HINSTANCE hInstance_global;
  11. short int x = 0, y = 0, sizex = 0, sizey = 0, szerokosc = 0, width = 0, height = 0, startPos = 0, wysokosc = 0, startPosH = 0;
  12. static int hwnd_count, i;
  13.  
  14. LRESULT CALLBACK Procedura ( HWND aplikacja, UINT wiadomosc, WPARAM wParam, LPARAM lParam )
  15. {
  16. switch( wiadomosc )
  17. {
  18. case WM_CREATE:
  19. {
  20. ++hwnd_count;
  21.  
  22. break;
  23. }
  24.  
  25. case WM_LBUTTONDOWN:
  26. {
  27. if( hwnd_count < 10 )
  28. {
  29. okno[++i] = CreateWindowEx (0, nazwa, TEXT("Okno Pochodne"), WS_OVERLAPPEDWINDOW, 50, 50, 500, 500, 0, 0, hInstance_global, 0);
  30. ShowWindow( okno[i], SW_SHOW );
  31. UpdateWindow( okno[i] );
  32. }
  33.  
  34. else
  35. {
  36. MessageBox( HWND_DESKTOP, TEXT( "Nie można dodać kolejnego okna, wyczerpałeś swój limit!" ), TEXT("ERROR!"), MB_OK | MB_ICONERROR );
  37. }
  38.  
  39. break;
  40. }
  41.  
  42. case WM_RBUTTONDOWN:
  43. {
  44. width = GetSystemMetrics( SM_CXFULLSCREEN );
  45. height = GetSystemMetrics( SM_CYFULLSCREEN );
  46. szerokosc = width / hwnd_count;
  47. wysokosc = height / hwnd_count;
  48.  
  49. if( GetKeyState( VK_SHIFT ) < 0 )
  50. {
  51. for( size_t i = 0; i < hwnd_count; ++i )
  52. {
  53. MoveWindow( okno[i], startPos , 0, szerokosc, height+24, true );
  54. startPos += szerokosc;
  55. }
  56. }
  57. else
  58. {
  59. for( size_t i = 0; i < hwnd_count; ++i )
  60. {
  61. MoveWindow( okno[i], 0 , startPosH, width, wysokosc, true );
  62. startPosH += wysokosc;
  63. }
  64. }
  65. break;
  66. }
  67.  
  68. case WM_SIZE:
  69. {
  70. sizex = LOWORD( lParam );
  71. sizey = HIWORD( lParam );
  72.  
  73. break;
  74. }
  75.  
  76. case WM_MOVE:
  77. {
  78. x = LOWORD( lParam );
  79. y = HIWORD( lParam );
  80.  
  81. break;
  82. }
  83.  
  84. case WM_DESTROY:
  85. {
  86. PostQuitMessage( 0 );
  87. return 0;
  88. }
  89.  
  90. default:
  91. return DefWindowProc( aplikacja, wiadomosc, wParam, lParam );
  92. }
  93.  
  94. wsprintf( buff, L"Pozycja okna: x = %d, y = %d || Rozmiar okna sizex = %d, sizey = %d", x, y, sizex, sizey );
  95. SetWindowText( aplikacja, buff );
  96.  
  97. return 0;
  98. }
  99.  
  100. static bool RejestrujKlase ( WNDCLASSEX& wndclass )
  101. {
  102. wndclass.cbClsExtra = 0;
  103. wndclass.cbSize = sizeof (WNDCLASSEX);
  104. wndclass.cbWndExtra = 0;
  105. wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  106. wndclass.hCursor = 0;
  107. wndclass.hIcon = 0;
  108. wndclass.hIconSm = 0;
  109. wndclass.hInstance = hInstance_global;
  110. wndclass.lpfnWndProc = Procedura;
  111. wndclass.lpszClassName = nazwa;
  112. wndclass.lpszMenuName = 0;
  113. wndclass.style = 0;
  114. if (!RegisterClassEx(&wndclass))
  115. {
  116. MessageBox(NULL, TEXT("Nie udało się zarejestrować klasy okna!"), nazwa, MB_ICONSTOP | MB_OK);
  117. return 0;
  118. }
  119. }
  120.  
  121. static void WyrejestrujKlase()
  122. {
  123. UnregisterClass ( nazwa, GetModuleHandle(NULL) );
  124. }
  125.  
  126. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow )
  127. {
  128.  
  129. hInstance_global = hInstance;
  130.  
  131. WNDCLASSEX wndclass;
  132. RejestrujKlase(wndclass);
  133.  
  134. okno[0] = CreateWindowEx (0, nazwa, TEXT("Okno Główne"), WS_OVERLAPPEDWINDOW, 50, 50, 500, 500, 0, 0, hInstance, 0);
  135.  
  136. if (okno[0] == NULL)
  137. {
  138. MessageBox(NULL, TEXT("Wystąpił błąd podczas tworzenia okna!"), TEXT("BŁĄD!"), MB_ICONSTOP | MB_OK);
  139.  
  140. return 0;
  141. }
  142.  
  143. ShowWindow (okno[0], SW_SHOW);
  144. UpdateWindow (okno[0]);
  145.  
  146. MSG wiadomosc;
  147.  
  148. while( GetMessage( &wiadomosc, NULL, 0, 0 ) )
  149. {
  150. TranslateMessage( &wiadomosc );
  151. DispatchMessage( &wiadomosc );
  152. }
  153.  
  154. WyrejestrujKlase();
  155.  
  156. return wiadomosc.wParam;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement