Advertisement
Alan468

You Spin Bitmapa Right Round

Nov 19th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
  2. #include <Windows.h>
  3. #include <stdio.h>
  4. #include <cstdio>
  5. #define TIMER_TIME 10
  6. time_t start, koniec;
  7. POINT Cur;
  8. RECT rect;
  9. char buff[255];
  10. PAINTSTRUCT PS;
  11. HDC hdc, hdcNowy;
  12. HBITMAP bm[10];
  13. BITMAP bmInfo;
  14. HBITMAP hbmOld;
  15.  
  16. double Out = 1.00;
  17. bool OutB = false;
  18.  
  19. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  20.     switch (msg) {
  21.     case WM_PAINT: {
  22.         hdc = BeginPaint(hwnd, &PS);
  23.  
  24.         hdcNowy = CreateCompatibleDC(hdc);
  25.  
  26.         bool Left, hMid, Right;
  27.         bool Top, vMid, Bot;
  28.  
  29.         int BimapX = (rect.right / 2);
  30.         int BimapY = (rect.bottom / 2);
  31.  
  32.         int BimapW, BimapH;
  33.  
  34.         for (int i = 0; i < 10; i++) {
  35.             GetObject(bm[i], sizeof(bmInfo), &bmInfo);
  36.  
  37.             BimapW = (bmInfo.bmWidth / 2);
  38.             BimapH = (bmInfo.bmHeight / 2);
  39.  
  40.             if (Cur.x <= 0 || Cur.y <= 0 || Cur.x >= rect.right || Cur.y >= rect.bottom) {
  41.                 OutB = true;
  42.             }
  43.             else {
  44.                 OutB = false;
  45.             }
  46.  
  47.             Left = (Cur.x >= 0 && Cur.x <= (BimapX - BimapW));
  48.             hMid = (Cur.x >= (BimapX - BimapW) && Cur.x <= (BimapX + BimapW));
  49.             Right = (Cur.x >= (BimapX + BimapW) && Cur.x <= rect.right);
  50.  
  51.             Top = (Cur.y > 0 && Cur.y <= (BimapY - BimapH));
  52.             vMid = (Cur.y >= (BimapY - BimapH) && Cur.y <= (BimapY + BimapH));
  53.             Bot = (Cur.y >= (BimapY + BimapH) && Cur.y <= rect.bottom);
  54.  
  55.             if (Left && Top || (OutB && (Out >= 1.00 && Out < 2.00))) {
  56.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[7]); break; // Left top
  57.             }
  58.             else if (hMid && Top || (OutB && (Out >= 2.00 && Out < 3.00))) {
  59.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[0]);break; //Top
  60.             }
  61.             else if (Right && Top || (OutB && (Out >= 3.00 && Out < 4.00))) {
  62.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[1]); break; // R top
  63.             }
  64.             else if (Left && vMid || (OutB && (Out >= 8.00 && Out < 9.00))) {
  65.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[6]); break; // mid Left
  66.             }
  67.             else if (hMid && vMid) {
  68.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[8]);  break; // mid Mid
  69.             }
  70.             else if (Right && vMid || (OutB && (Out >= 4.00 && Out < 5.00))) {
  71.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[2]); break; // mid Right
  72.             }
  73.             else if (Left && Bot || (OutB && (Out >= 7.00 && Out < 8.00))) {
  74.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[5]); break; // Left Bot
  75.             }
  76.             else if (hMid && Bot || (OutB && (Out >= 6.00 && Out < 7.00))) {
  77.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[4]);  break; // Bot
  78.             }
  79.             else if (Right && Bot || (OutB && (Out >=5.00 && Out < 6.00))) {
  80.                 hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[3]);  break; // R bot
  81.             }
  82.             //hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[9]); break; // Error
  83.            
  84.         }
  85.         BitBlt(hdc, BimapX - BimapW, BimapY - BimapH, bmInfo.bmWidth, bmInfo.bmHeight, hdcNowy, 0, 0, SRCCOPY);
  86.  
  87.         sprintf(buff, "Pozycja muszy:         %5dx%d", Cur.x, Cur.y);
  88.         TextOut(hdc, 0, 0, buff, strlen(buff));
  89.        
  90.         sprintf(buff, "Rozdzielczosc:          %5dx%d", rect.right, rect.bottom);
  91.         TextOut(hdc, 0, 20, buff, strlen(buff));
  92.  
  93.         sprintf(buff, "Licznik:                        %5.3lf", Out);
  94.         TextOut(hdc, 0, 40, buff, strlen(buff));
  95.  
  96.         sprintf(buff, "Czy poza ekranem: %5d", OutB);
  97.         TextOut(hdc, 0,60, buff, strlen(buff));
  98.  
  99.         SelectObject(hdcNowy, hbmOld);
  100.         DeleteDC(hdcNowy);
  101.  
  102.         EndPaint(hwnd, &PS);
  103.     }break;
  104.  
  105.     case WM_TIMER: {
  106.             GetCursorPos(&Cur);
  107.             ScreenToClient(hwnd, &Cur);
  108.             GetClientRect(hwnd, &rect);
  109.             // 1 Hz -> 1   FPS -> 1000 mls
  110.             // 2 Hz -> 2   FPS -> 500  mls
  111.             // .... -> 10  FPS -> 100  mls
  112.             // .... -> 6   FPS -> 60   mls
  113.             // .... -> 100 FPS -> 10   mls
  114.             if (OutB == true) {
  115.                 if (Out >= 9.00) {
  116.                     Out = 1.00;
  117.                 }
  118.                 else {
  119.                     Out += 0.05;
  120.                 }
  121.             }
  122.             else Out = 1.00;
  123.  
  124.             InvalidateRect(hwnd, &rect, true);
  125.     }break;
  126.  
  127.     case WM_CLOSE: DestroyWindow(hwnd); break;
  128.     case WM_DESTROY: PostQuitMessage(0); break;
  129.     default: return DefWindowProc(hwnd, msg, wParam, lParam);
  130.     }
  131.     return 0;
  132. }
  133.  
  134. void LoadBitMap() {
  135.     bm[0] = (HBITMAP)LoadImage(NULL, ("BM\\t.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  136.     bm[1] = (HBITMAP)LoadImage(NULL, ("BM\\rt.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  137.     bm[2] = (HBITMAP)LoadImage(NULL, ("BM\\r.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  138.     bm[3] = (HBITMAP)LoadImage(NULL, ("BM\\rb.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  139.     bm[4] = (HBITMAP)LoadImage(NULL, ("BM\\b.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  140.     bm[5] = (HBITMAP)LoadImage(NULL, ("BM\\lb.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  141.     bm[6] = (HBITMAP)LoadImage(NULL, ("BM\\l.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  142.     bm[7] = (HBITMAP)LoadImage(NULL, ("BM\\lt.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  143.     bm[8] = (HBITMAP)LoadImage(NULL, ("BM\\m.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  144.     bm[9] = (HBITMAP)LoadImage(NULL, ("BM\\E.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  145. }
  146.  
  147. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) {
  148.     WNDCLASSEX window;
  149.     MSG msg;
  150.     TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul");
  151.  
  152.     window.cbClsExtra = NULL;
  153.     window.cbSize = sizeof(WNDCLASSEX);
  154.     window.cbWndExtra = NULL;
  155.     window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  156.     window.hCursor = LoadCursor(NULL, IDC_ARROW);
  157.     window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  158.     window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  159.     window.hInstance = hInstance;
  160.     window.lpfnWndProc = WndProc;
  161.     window.lpszClassName = Class_Name;
  162.     window.lpszMenuName = 0;
  163.     window.style = CS_VREDRAW | CS_HREDRAW;
  164.  
  165.     if (!RegisterClassEx(&window)) {
  166.         MessageBox(NULL, TEXT("Błąd rejestracji okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
  167.         return 0;
  168.     }
  169.  
  170.     HWND hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
  171.  
  172.     if (hwnd == NULL) {
  173.         MessageBox(NULL, TEXT("Błąd tworzenia okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
  174.         return 0;
  175.     }
  176.  
  177.     LoadBitMap();
  178.  
  179.     ShowWindow(hwnd, nCmdShow);
  180.     UpdateWindow(hwnd);
  181.     SetTimer(hwnd, NULL, TIMER_TIME, NULL);
  182.  
  183.     while (GetMessage(&msg, NULL, 0, 0)) {
  184.         TranslateMessage(&msg);
  185.         DispatchMessage(&msg);
  186.     }
  187.  
  188.     if (!UnregisterClass(Class_Name, hInstance)) {
  189.         MessageBox(NULL, TEXT("Błąd niszczenia okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
  190.         return 0;
  191.     }
  192.     return msg.wParam;
  193. }
  194.  
  195. /*
  196. // Samo sledzenia myszy
  197. case WM_PAINT: {
  198. hdc = BeginPaint(hwnd, &PS);
  199.  
  200. wsprintf(buff, "MouseX: %d ,MouseY: %d ,Resolution: %dx%d", Cur.x, Cur.y, rect.right, rect.bottom);
  201. TextOut(hdc, 0, 0, buff, strlen(buff));
  202.  
  203. hdcNowy = CreateCompatibleDC(hdc);
  204.  
  205. bool Left, hMid, Right;
  206. bool Top, vMid, Bot;
  207.  
  208. int BimapX = (rect.right / 2);
  209. int BimapY = (rect.bottom / 2);
  210.  
  211. int BimapW, BimapH;
  212.  
  213. for (int i = 0; i < 10; i++) {
  214. GetObject(bm[i], sizeof(bmInfo), &bmInfo);
  215.  
  216. BimapW = (bmInfo.bmWidth / 2);
  217. BimapH = (bmInfo.bmHeight / 2);
  218.  
  219. Left =  (Cur.x >= 0                 && Cur.x <= (BimapX - BimapW));
  220. hMid =  (Cur.x >= (BimapX - BimapW) && Cur.x <= (BimapX + BimapW));
  221. Right = (Cur.x >= (BimapX + BimapW) && Cur.x <= rect.right);
  222.  
  223. Top =  (Cur.y > 0                   && Cur.y <= (BimapY - BimapH));
  224. vMid = (Cur.y >= (BimapY - BimapH)  && Cur.y <= (BimapY + BimapH));
  225. Bot =  (Cur.y >= (BimapY + BimapH)  && Cur.y <= rect.bottom);
  226.  
  227. if (Left && Top) {
  228. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[7]); break; // Left top
  229. }
  230. else if (hMid && Top) {
  231. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[0]); break; //Top
  232. }
  233. else if (Right && Top) {
  234. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[1]); break; // R top
  235. }
  236. else if (Left && vMid) {
  237. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[6]); break; // Left
  238. }
  239. else if (hMid && vMid) {
  240. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[8]); break; // Mid
  241. }
  242. else if (Right && vMid) {
  243. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[2]); break; // Right
  244. }
  245. else if (Left && Bot) {
  246. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[5]); break; // Left Bot
  247. }
  248. else if (hMid && Bot) {
  249. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[4]); break; // Bot
  250. }
  251. else if (Right && Bot) {
  252. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[3]); break; // R bot
  253. }
  254. else {
  255. hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[9]); break; // Error
  256. }
  257. }
  258. BitBlt(hdc, (rect.right / 2) - (bmInfo.bmWidth / 2), (rect.bottom / 2) - (bmInfo.bmHeight / 2), bmInfo.bmWidth, bmInfo.bmHeight, hdcNowy, 0, 0, SRCCOPY);
  259.  
  260.  
  261. SelectObject(hdcNowy, hbmOld);
  262. DeleteDC(hdcNowy);
  263.  
  264. EndPaint(hwnd, &PS);
  265. }break;
  266.  
  267. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement