Advertisement
Haifisch7734

mc

Dec 6th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.59 KB | None | 0 0
  1. #include <windows.h>
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <string>
  7. #include "rpacr.hpp"
  8. #include "fo.hpp"
  9. #include "cesr.hpp"
  10. #define losuj 501
  11. #define start 502
  12. #define pole 503
  13.  
  14. LPSTR NazwaKlasy = "Klasa Okienka";
  15. MSG Komunikat;
  16.  
  17. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  18. //deklaracje
  19. HWND hwnd;
  20. HWND przycisk;
  21. HWND start_p;
  22. HWND TextBox;
  23. HWND Static_text;
  24. HWND ramka;
  25.  
  26. city *headUnSor = NULL;
  27. city *headSor = NULL;
  28. city *tailSor = NULL;
  29. float **TRoad;
  30.  
  31.  
  32. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
  33. // WYPELNIANIE STRUKTURY
  34. WNDCLASSEX wc;
  35.  
  36. wc.cbSize = sizeof( WNDCLASSEX );
  37. wc.style = 0;
  38. wc.lpfnWndProc = WndProc;
  39. wc.cbClsExtra = 0;
  40. wc.cbWndExtra = 0;
  41. wc.hInstance = hInstance;
  42. wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  43. wc.hCursor = LoadCursor(NULL,IDC_ARROW);
  44. //wc.hbrBackground =(HBRUSH)(COLOR_WINDOW+1);
  45. wc.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
  46. wc.lpszMenuName = NULL;
  47. wc.lpszClassName = NazwaKlasy;
  48. wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
  49.  
  50. // REJESTROWANIE KLASY OKNA
  51. if(!RegisterClassEx(&wc)){
  52.     MessageBox(NULL,"B³¹d", "Podczas rejestracji okna wyst¹pi³ b³¹d!",MB_ICONEXCLAMATION | MB_OK);
  53.     return 1;
  54.     }
  55.  
  56. // TWORZENIE OKNA
  57. hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, "Komiwoja¿er", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
  58.  
  59. // kontrolki
  60. przycisk = CreateWindowEx(WS_EX_CLIENTEDGE,"button","Losuj punkty",WS_CHILD | WS_VISIBLE | WS_BORDER,600,80,150,30,hwnd,(HMENU) losuj,hInstance,NULL);
  61. start_p = CreateWindowEx(WS_EX_CLIENTEDGE,"button","Start",WS_CHILD | WS_VISIBLE|WS_BORDER,600,120,150,30,hwnd,(HMENU) start,hInstance,NULL);
  62. Static_text= CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE |SS_LEFT, 600, 15, 150, 30, hwnd, NULL, hInstance, NULL);
  63. ramka = CreateWindowEx(WS_EX_CLIENTEDGE,"STATIC","",WS_CHILD | WS_VISIBLE | WS_BORDER | BS_GROUPBOX,10,10,550,550,hwnd,(HMENU) pole,hInstance,NULL);
  64. TextBox = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,600, 40, 150, 30, hwnd, NULL, hInstance, NULL);
  65. SetWindowText(Static_text, "Podaj iloœæ punktów");
  66.  
  67.  
  68. if(hwnd == NULL){
  69.     MessageBox( NULL, "B³¹d w podczas uruchamiania programu ", "Error!!!", MB_ICONEXCLAMATION);
  70.     return 1;
  71.     }
  72.  
  73. ShowWindow(hwnd, nCmdShow); // Pokaz okienko
  74. UpdateWindow(hwnd);
  75.  
  76. // Petla komunikatow
  77. while(GetMessage(&Komunikat,NULL,0,0)){
  78.     TranslateMessage(&Komunikat);
  79.     DispatchMessage(&Komunikat);
  80.     }
  81. return Komunikat.wParam;
  82. }
  83.  
  84. int Rys_punkty(city **h){
  85. HDC hdc = GetDC(hwnd);
  86. city *p = (*h);
  87. POINT oldPt;
  88. HBRUSH GrBr = CreateSolidBrush(0x00FF00);
  89. SelectObject(hdc,GrBr);
  90. while(p!=NULL){
  91.     MoveToEx(hdc,p->x,p->y,&oldPt);
  92.     Ellipse(hdc,p->y-7,p->x-7,p->y+7,p->x+7);
  93.     p=p->next;
  94.     }
  95. ReleaseDC(hwnd,hdc);
  96. return 0;
  97. }
  98.  
  99. int drawRoutes(city **h){
  100. HDC hdc = GetDC(hwnd);
  101. city *p = (*h);
  102. POINT oldPt;
  103. HPEN pen = CreatePen(PS_SOLID,1,0x0000FF);
  104. SelectObject(hdc,pen);
  105. MoveToEx(hdc,p->y+1,p->x,&oldPt);
  106. while(p != NULL){
  107.         Sleep(20);
  108.         LineTo(hdc,p->y,p->x);
  109.         p = p->next;
  110.     }
  111. return 0;
  112. }
  113. // OBSLUGA ZDARZEN
  114. LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
  115. switch(msg){
  116.     case WM_CLOSE:
  117.         DestroyWindow( hwnd );
  118.         break;
  119.     case WM_DESTROY:
  120.         PostQuitMessage(0);
  121.         break;
  122.     case WM_COMMAND:
  123.         switch(wParam){
  124.             case losuj:{
  125.                 srand (time(NULL));
  126.                 char *Bufor;
  127.                 Bufor = (char*)malloc(sizeof(char)*7);
  128.                 GetWindowText(TextBox,Bufor,7);
  129.                 unsigned int qu = atoi(Bufor);
  130.                 randomizePointCoord(qu,&headUnSor);
  131.                 save(headUnSor);
  132.                 TRoad = new float*[qu];
  133.                 for(int i=0;i<qu;i++)
  134.                     TRoad[i] = new float[qu];
  135.                 calcRoadTable(&headUnSor,TRoad);
  136.                 Rys_punkty(&headUnSor);
  137.                 DestroyWindow(przycisk);
  138.                 break;
  139.             }
  140.             case start:
  141.                 noAhead(&headUnSor,&headSor,&tailSor,TRoad);
  142.                 DestroyWindow(start_p);
  143.                 MessageBox(hwnd,"Wyliczono droge","Informacja",MB_OK | MB_ICONASTERISK);
  144.                 drawRoutes(&headSor);
  145.                 MessageBox(hwnd,"Droga zostala narysowana","Informacja",MB_OK | MB_ICONASTERISK);
  146.                 break;
  147.             }
  148.     default:
  149.         return DefWindowProc(hwnd, msg, wParam, lParam);
  150.     }
  151. return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement