Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
- #include <Windows.h>
- #include <stdio.h>
- #include <cstdio>
- #define TIMER_TIME 10
- time_t start, koniec;
- POINT Cur;
- RECT rect;
- char buff[255];
- PAINTSTRUCT PS;
- HDC hdc, hdcNowy;
- HBITMAP bm[10];
- BITMAP bmInfo;
- HBITMAP hbmOld;
- double Out = 1.00;
- bool OutB = false;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
- switch (msg) {
- case WM_PAINT: {
- hdc = BeginPaint(hwnd, &PS);
- hdcNowy = CreateCompatibleDC(hdc);
- bool Left, hMid, Right;
- bool Top, vMid, Bot;
- int BimapX = (rect.right / 2);
- int BimapY = (rect.bottom / 2);
- int BimapW, BimapH;
- for (int i = 0; i < 10; i++) {
- GetObject(bm[i], sizeof(bmInfo), &bmInfo);
- BimapW = (bmInfo.bmWidth / 2);
- BimapH = (bmInfo.bmHeight / 2);
- if (Cur.x <= 0 || Cur.y <= 0 || Cur.x >= rect.right || Cur.y >= rect.bottom) {
- OutB = true;
- }
- else {
- OutB = false;
- }
- Left = (Cur.x >= 0 && Cur.x <= (BimapX - BimapW));
- hMid = (Cur.x >= (BimapX - BimapW) && Cur.x <= (BimapX + BimapW));
- Right = (Cur.x >= (BimapX + BimapW) && Cur.x <= rect.right);
- Top = (Cur.y > 0 && Cur.y <= (BimapY - BimapH));
- vMid = (Cur.y >= (BimapY - BimapH) && Cur.y <= (BimapY + BimapH));
- Bot = (Cur.y >= (BimapY + BimapH) && Cur.y <= rect.bottom);
- if (Left && Top || (OutB && (Out >= 1.00 && Out < 2.00))) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[7]); break; // Left top
- }
- else if (hMid && Top || (OutB && (Out >= 2.00 && Out < 3.00))) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[0]);break; //Top
- }
- else if (Right && Top || (OutB && (Out >= 3.00 && Out < 4.00))) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[1]); break; // R top
- }
- else if (Left && vMid || (OutB && (Out >= 8.00 && Out < 9.00))) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[6]); break; // mid Left
- }
- else if (hMid && vMid) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[8]); break; // mid Mid
- }
- else if (Right && vMid || (OutB && (Out >= 4.00 && Out < 5.00))) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[2]); break; // mid Right
- }
- else if (Left && Bot || (OutB && (Out >= 7.00 && Out < 8.00))) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[5]); break; // Left Bot
- }
- else if (hMid && Bot || (OutB && (Out >= 6.00 && Out < 7.00))) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[4]); break; // Bot
- }
- else if (Right && Bot || (OutB && (Out >=5.00 && Out < 6.00))) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[3]); break; // R bot
- }
- //hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[9]); break; // Error
- }
- BitBlt(hdc, BimapX - BimapW, BimapY - BimapH, bmInfo.bmWidth, bmInfo.bmHeight, hdcNowy, 0, 0, SRCCOPY);
- sprintf(buff, "Pozycja muszy: %5dx%d", Cur.x, Cur.y);
- TextOut(hdc, 0, 0, buff, strlen(buff));
- sprintf(buff, "Rozdzielczosc: %5dx%d", rect.right, rect.bottom);
- TextOut(hdc, 0, 20, buff, strlen(buff));
- sprintf(buff, "Licznik: %5.3lf", Out);
- TextOut(hdc, 0, 40, buff, strlen(buff));
- sprintf(buff, "Czy poza ekranem: %5d", OutB);
- TextOut(hdc, 0,60, buff, strlen(buff));
- SelectObject(hdcNowy, hbmOld);
- DeleteDC(hdcNowy);
- EndPaint(hwnd, &PS);
- }break;
- case WM_TIMER: {
- GetCursorPos(&Cur);
- ScreenToClient(hwnd, &Cur);
- GetClientRect(hwnd, &rect);
- // 1 Hz -> 1 FPS -> 1000 mls
- // 2 Hz -> 2 FPS -> 500 mls
- // .... -> 10 FPS -> 100 mls
- // .... -> 6 FPS -> 60 mls
- // .... -> 100 FPS -> 10 mls
- if (OutB == true) {
- if (Out >= 9.00) {
- Out = 1.00;
- }
- else {
- Out += 0.05;
- }
- }
- else Out = 1.00;
- InvalidateRect(hwnd, &rect, true);
- }break;
- case WM_CLOSE: DestroyWindow(hwnd); break;
- case WM_DESTROY: PostQuitMessage(0); break;
- default: return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- void LoadBitMap() {
- bm[0] = (HBITMAP)LoadImage(NULL, ("BM\\t.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[1] = (HBITMAP)LoadImage(NULL, ("BM\\rt.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[2] = (HBITMAP)LoadImage(NULL, ("BM\\r.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[3] = (HBITMAP)LoadImage(NULL, ("BM\\rb.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[4] = (HBITMAP)LoadImage(NULL, ("BM\\b.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[5] = (HBITMAP)LoadImage(NULL, ("BM\\lb.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[6] = (HBITMAP)LoadImage(NULL, ("BM\\l.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[7] = (HBITMAP)LoadImage(NULL, ("BM\\lt.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[8] = (HBITMAP)LoadImage(NULL, ("BM\\m.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- bm[9] = (HBITMAP)LoadImage(NULL, ("BM\\E.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) {
- WNDCLASSEX window;
- MSG msg;
- TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul");
- window.cbClsExtra = NULL;
- window.cbSize = sizeof(WNDCLASSEX);
- window.cbWndExtra = NULL;
- window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- window.hCursor = LoadCursor(NULL, IDC_ARROW);
- window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- window.hInstance = hInstance;
- window.lpfnWndProc = WndProc;
- window.lpszClassName = Class_Name;
- window.lpszMenuName = 0;
- window.style = CS_VREDRAW | CS_HREDRAW;
- if (!RegisterClassEx(&window)) {
- MessageBox(NULL, TEXT("Błąd rejestracji okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
- return 0;
- }
- HWND hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
- if (hwnd == NULL) {
- MessageBox(NULL, TEXT("Błąd tworzenia okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
- return 0;
- }
- LoadBitMap();
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- SetTimer(hwnd, NULL, TIMER_TIME, NULL);
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- if (!UnregisterClass(Class_Name, hInstance)) {
- MessageBox(NULL, TEXT("Błąd niszczenia okna"), TEXT("Błąd"), MB_ICONEXCLAMATION);
- return 0;
- }
- return msg.wParam;
- }
- /*
- // Samo sledzenia myszy
- case WM_PAINT: {
- hdc = BeginPaint(hwnd, &PS);
- wsprintf(buff, "MouseX: %d ,MouseY: %d ,Resolution: %dx%d", Cur.x, Cur.y, rect.right, rect.bottom);
- TextOut(hdc, 0, 0, buff, strlen(buff));
- hdcNowy = CreateCompatibleDC(hdc);
- bool Left, hMid, Right;
- bool Top, vMid, Bot;
- int BimapX = (rect.right / 2);
- int BimapY = (rect.bottom / 2);
- int BimapW, BimapH;
- for (int i = 0; i < 10; i++) {
- GetObject(bm[i], sizeof(bmInfo), &bmInfo);
- BimapW = (bmInfo.bmWidth / 2);
- BimapH = (bmInfo.bmHeight / 2);
- Left = (Cur.x >= 0 && Cur.x <= (BimapX - BimapW));
- hMid = (Cur.x >= (BimapX - BimapW) && Cur.x <= (BimapX + BimapW));
- Right = (Cur.x >= (BimapX + BimapW) && Cur.x <= rect.right);
- Top = (Cur.y > 0 && Cur.y <= (BimapY - BimapH));
- vMid = (Cur.y >= (BimapY - BimapH) && Cur.y <= (BimapY + BimapH));
- Bot = (Cur.y >= (BimapY + BimapH) && Cur.y <= rect.bottom);
- if (Left && Top) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[7]); break; // Left top
- }
- else if (hMid && Top) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[0]); break; //Top
- }
- else if (Right && Top) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[1]); break; // R top
- }
- else if (Left && vMid) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[6]); break; // Left
- }
- else if (hMid && vMid) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[8]); break; // Mid
- }
- else if (Right && vMid) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[2]); break; // Right
- }
- else if (Left && Bot) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[5]); break; // Left Bot
- }
- else if (hMid && Bot) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[4]); break; // Bot
- }
- else if (Right && Bot) {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[3]); break; // R bot
- }
- else {
- hbmOld = (HBITMAP)SelectObject(hdcNowy, bm[9]); break; // Error
- }
- }
- BitBlt(hdc, (rect.right / 2) - (bmInfo.bmWidth / 2), (rect.bottom / 2) - (bmInfo.bmHeight / 2), bmInfo.bmWidth, bmInfo.bmHeight, hdcNowy, 0, 0, SRCCOPY);
- SelectObject(hdcNowy, hbmOld);
- DeleteDC(hdcNowy);
- EndPaint(hwnd, &PS);
- }break;
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement