Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #include <algorithm>
- #include <commctrl.h>
- #include <vector>
- #include <fstream>
- //#include "resource.h"
- typedef struct
- {
- POINT smallestCoords;
- POINT bigestCoords;
- }Coords;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- std::wstring OpenDialog(HWND hwnd);
- void ResetWindow(HWND hwnd);
- void DrawLines(HWND hwnd);
- void ReDrawCross(HWND hwnd);
- void DrawCrossOnClick(HWND hwnd);
- void DrawRect(HWND hwnd);
- void DrawLine(HWND hwnd);
- void saveCoords(POINT smallestCoords, POINT bigestCoords);
- void DrawAllRect(HWND hwnd);
- void DrawAllLine(HWND hwnd);
- bool isMouseInrect();
- int getRect();
- double getSwFract(int mouseX);
- double getShFract(int mouseY);
- #define ID_BUTTON 1
- #define ID_DROPLIST 2
- HWND hwndButton, hwndComboBox;
- TCHAR NPath[MAX_PATH];
- LPCWSTR Path;
- bool FSon;
- bool drawLine;
- bool delLastCross;
- bool drawRect;
- bool savePhase;
- bool drawAllRect;
- bool crossIsDrawing;
- bool lineMod = false;
- bool rectangleMod = false;
- bool loadCoords = false;
- int crossCounter;
- std::vector<int> xCoords;
- std::vector<int> yCoords;
- std::vector<Coords> CoordsList;
- int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow)
- {
- crossCounter = -1;
- FSon = false;
- drawLine = false;
- delLastCross = false;
- drawRect = false;
- savePhase = false;
- drawAllRect = false;
- crossIsDrawing = false;
- MSG msg;
- HWND hwnd;
- WNDCLASSEXW wc;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = NULL; //wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- wc.hCursor = NULL;
- wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //(HBRUSH)(COLOR_WINDOW+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = L"ImgFractionCalc";
- wc.hIconSm = NULL; //wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
- if (!RegisterClassExW(&wc))
- {
- MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- hwnd = CreateWindowExW(NULL, L"ImgFractionCalc", L"ImgFrac", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, GetSystemMetrics(SM_CXSCREEN) / 2, GetSystemMetrics(SM_CYSCREEN) / 2, 150, 108, 0, 0, hInstance, 0); //WS_OVERLAPPEDWINDOW //WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
- if (hwnd == NULL)
- {
- MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- DOUBLE dwRet = GetCurrentDirectory(MAX_PATH, NPath);
- if (dwRet == 0)
- {
- wchar_t buff[256];
- FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buff, 256, NULL);
- MessageBoxW(NULL, buff, L"Error", MB_OK);
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int)msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- TCHAR BPath[MAX_PATH];
- strcpy_s(BPath, NPath);
- static HBITMAP hBitmap;
- HDC hdc;
- PAINTSTRUCT ps;
- BITMAP bitmap;
- HDC hdcMem;
- HGDIOBJ oldBitmap;
- std::wstring Path;
- switch (msg)
- {
- case WM_LBUTTONDOWN:
- if (FSon)
- {
- drawLine = true;
- RedrawWindow(hwnd, NULL, NULL, RDW_INTERNALPAINT);
- }
- break;
- case WM_RBUTTONDOWN:
- if (FSon)
- {
- if (xCoords.size() > 0 && yCoords.size() > 0)
- {
- delLastCross = true;
- RECT theRect;
- GetClientRect(hwnd, &theRect);
- InvalidateRect(hwnd, &theRect, TRUE);
- //redraw all rect here
- //DrawRect(hwnd); //not working
- //DrawAllRect(hwnd); //not working
- /*if ((CoordsList.size() != 0) && !crossIsDrawing)
- {
- drawAllRect = true;
- }
- drawRect = true;*/
- savePhase = false;
- }
- }
- break;
- case WM_MBUTTONDOWN:
- if (FSon && isMouseInrect())
- {
- CoordsList.erase(CoordsList.begin() + getRect());
- drawAllRect = true;
- }
- break;
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- {
- int rekt = MessageBoxW(hwnd, L"Save and quit?", L"", MB_YESNOCANCEL);
- if (rekt == IDYES)
- {
- if (CoordsList.size() != 0)
- {
- if (!SetCurrentDirectory(BPath))
- {
- wchar_t buff[256];
- FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buff, 256, NULL);
- MessageBoxW(hwnd, buff, L"Error", MB_OK);
- }
- std::ifstream infile("C:\\Temp\\coordinates.txt");
- if (infile.good())
- {
- int rek = MessageBoxW(hwnd, L"File exists, do you want to replace it?", L"", MB_YESNO);
- if (rek == IDYES)
- {
- std::ofstream file("coordinates.txt", std::ios::out | std::ios::trunc);
- for (size_t CoordsListSize = 0, size = CoordsList.size(); CoordsListSize < size; ++CoordsListSize)
- {
- file << getSwFract(CoordsList.at(CoordsListSize).smallestCoords.x) << " " << getShFract(CoordsList.at(CoordsListSize).smallestCoords.y) << " " << getSwFract(CoordsList.at(CoordsListSize).bigestCoords.x) << " " << getShFract(CoordsList.at(CoordsListSize).bigestCoords.y) << "\n";
- }
- file.close();
- }
- }
- else
- {
- std::ofstream file("C:\\Temp\\coordinates.txt", std::ios::out | std::ios::trunc);
- for (size_t CoordsListSize = 0, size = CoordsList.size(); CoordsListSize < size; ++CoordsListSize)
- {
- file << getSwFract(CoordsList.at(CoordsListSize).smallestCoords.x) << " " << getShFract(CoordsList.at(CoordsListSize).smallestCoords.y) << " " << getSwFract(CoordsList.at(CoordsListSize).bigestCoords.x) << " " << getShFract(CoordsList.at(CoordsListSize).bigestCoords.y) << "\n";
- }
- file.close();
- }
- }
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- else if (rekt == IDNO)
- {
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- }
- else if (wParam == 'S' && GetAsyncKeyState(VK_CONTROL))
- {
- if (!SetCurrentDirectory(BPath))
- {
- wchar_t buff[256];
- FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buff, 256, NULL);
- MessageBoxW(hwnd, buff, L"Error", MB_OK);
- }
- std::ofstream file("C:\\Temp\\coordinates.txt", std::ios::out | std::ios::trunc);
- for (size_t CoordsListSize = 0, size = CoordsList.size(); CoordsListSize < size; ++CoordsListSize)
- {
- file << getSwFract(CoordsList.at(CoordsListSize).smallestCoords.x) << " " << getShFract(CoordsList.at(CoordsListSize).smallestCoords.y) << " " << getSwFract(CoordsList.at(CoordsListSize).bigestCoords.x) << " " << getShFract(CoordsList.at(CoordsListSize).bigestCoords.y) << "\n";
- }
- file.close();
- }
- else if ((wParam == VK_RETURN) && FSon)
- {
- if (!savePhase)
- {
- /*if ((CoordsList.size() != 0) && !crossIsDrawing)
- {
- drawAllRect = true;
- }*/
- drawRect = true;
- drawAllRect = true;
- RECT theRect;
- GetClientRect(hwnd, &theRect);
- InvalidateRect(hwnd, &theRect, TRUE);
- }
- else if (savePhase)
- {
- /*int rektt = MessageBoxW(hwnd, L"Save Rectangle coordinates?", L"", MB_OKCANCEL);
- if (rektt != IDOK)
- {
- CoordsList.pop_back();
- }
- RECT theRect;
- GetClientRect(hwnd, &theRect);
- InvalidateRect(hwnd, &theRect, TRUE);
- savePhase = false;
- drawAllRect = true;*/
- }
- }
- break;
- case WM_CREATE:
- hwndComboBox = CreateWindow(WC_COMBOBOX, TEXT("ComboBox"), CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | CBS_HASSTRINGS, 20, 9, 100, 200, hwnd, (HMENU)ID_DROPLIST, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); // | WS_OVERLAPPED | CBS_HASSTRINGS
- SendMessage(hwndComboBox, CB_ADDSTRING, (UINT)0, (LPARAM)"Lines");
- SendMessage(hwndComboBox, CB_ADDSTRING, (UINT)1, (LPARAM)"Rectangles");
- SendMessage(hwndComboBox, CB_SETCURSEL, 0, 0);
- hwndButton = CreateWindowW(L"Button", L"Open file", WS_VISIBLE | WS_CHILD, 30, 39, 75, 23, hwnd, (HMENU)ID_BUTTON, NULL, NULL);
- SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_MAXIMIZEBOX);
- break;
- case WM_PAINT:
- hdc = BeginPaint(hwnd, &ps);
- hdcMem = CreateCompatibleDC(hdc);
- oldBitmap = SelectObject(hdcMem, hBitmap);
- GetObject(hBitmap, sizeof(bitmap), &bitmap);
- BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
- SetStretchBltMode(hdc, HALFTONE);
- StretchBlt(hdc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
- if (drawLine && !savePhase)
- {
- DrawCrossOnClick(hwnd);
- drawLine = false;
- }
- else if (delLastCross && !savePhase)
- {
- ReDrawCross(hwnd);
- if (lineMod)
- {
- DrawAllLine(hwnd);
- }
- else
- {
- DrawAllRect(hwnd);
- }
- delLastCross = false;
- }
- else if (drawRect && !savePhase)
- {
- if (lineMod)
- {
- DrawLine(hwnd);
- DrawAllLine(hwnd);
- }
- else
- {
- DrawRect(hwnd);
- DrawAllRect(hwnd);
- }
- drawRect = false;
- }
- else if (loadCoords && !savePhase)
- {
- if (lineMod)
- {
- DrawLine(hwnd);
- DrawAllLine(hwnd);
- }
- else
- {
- DrawRect(hwnd);
- DrawAllRect(hwnd);
- }
- }
- else if (drawAllRect)
- {
- /*if (lineMod)
- {
- DrawAllLine(hwnd);
- }
- else
- {
- DrawAllRect(hwnd);
- }*/
- drawAllRect = false;
- }
- SelectObject(hdcMem, oldBitmap);
- DeleteDC(hdcMem);
- EndPaint(hwnd, &ps);
- break;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_BUTTON)
- {
- int ItemIndex = SendMessage(hwndComboBox, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
- if (ItemIndex == 0)
- {
- lineMod = true;
- }
- else
- {
- rectangleMod = true;
- }
- ShowWindow(hwndComboBox, SW_HIDE);
- Path = OpenDialog(hwnd);
- ResetWindow(hwnd);
- hBitmap = (HBITMAP)LoadImageW(NULL, Path.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);//Path.c_str() //L"C:\\worlda.bmp"
- if (hBitmap == NULL)
- {
- wchar_t buff[256];
- FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buff, 256, NULL);
- MessageBoxW(hwnd, buff, L"Error", MB_OK);
- }
- break;
- }
- break;
- case WM_DESTROY:
- DeleteObject(hBitmap);
- PostQuitMessage(0);
- break;
- default:
- break;
- }
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- std::wstring OpenDialog(HWND hwnd)
- {
- std::wstring Path;
- OPENFILENAME ofn;
- TCHAR szFile[MAX_PATH];
- ZeroMemory(&ofn, sizeof(ofn));
- ofn.lStructSize = sizeof(ofn);
- ofn.lpstrFile = szFile;
- ofn.lpstrFile[0] = '\0';
- ofn.hwndOwner = hwnd;
- ofn.nMaxFile = sizeof(szFile);
- ofn.lpstrFilter = TEXT("Image Files\0*.bmp\0Any File\0*.*\0");
- ofn.nFilterIndex = 1;
- ofn.lpstrTitle = TEXT("Select an image");
- ofn.lpstrInitialDir = NPath;
- ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
- if (GetOpenFileName(&ofn))
- {
- OutputDebugString(ofn.lpstrFile);
- std::string str = ofn.lpstrFile;
- int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
- std::wstring wPath(size_needed, 0);
- MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wPath[0], size_needed);
- Path = wPath;
- }
- return Path;
- }
- void ResetWindow(HWND hwnd)
- {
- HDC hdc;
- hdc = GetDC(hwnd);
- RECT theRect;
- ReleaseDC(hwnd, hdc);
- GetClientRect(hwnd, &theRect);
- InvalidateRect(hwnd, &theRect, TRUE);
- DestroyWindow(hwndButton);
- InvalidateRect(hwndButton, NULL, TRUE);
- UpdateWindow(hwndButton);
- SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_THICKFRAME);
- SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & WS_MAXIMIZEBOX);
- //SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST);
- SetWindowLongPtr(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
- SetWindowPos(hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW); //HWND_TOPMOST
- FSon = true;
- std::string usedString, coords;
- std::string delimiter = " ";
- size_t pos = 0;
- std::ifstream infile("C:\\Temp\\coordinates.txt");
- int counter = 0;
- Coords C1;
- int screenW = GetSystemMetrics(SM_CXSCREEN);
- int screenH = GetSystemMetrics(SM_CYSCREEN);
- if (infile.good())
- {
- while (getline(infile, usedString, '\n'))
- {
- while ((pos = usedString.find(delimiter)) != std::string::npos)
- {
- coords = usedString.substr(0, pos);
- switch (counter)
- {
- case 0:
- C1.smallestCoords.x = (int)(std::stod(coords) * (double)screenW);
- break;
- case 1:
- C1.smallestCoords.y = (int)(std::stod(coords) * (double)screenH);
- break;
- case 2:
- C1.bigestCoords.x = (int)(std::stod(coords) * (double)screenW);
- break;
- default:
- break;
- }
- usedString.erase(0, pos + delimiter.length());
- counter++;
- if ((pos = usedString.find(delimiter)) == std::string::npos)
- {
- coords = usedString.substr(0, pos);
- C1.bigestCoords.y = (int)(std::stod(coords) * (double)screenH);
- }
- }
- }
- CoordsList.push_back(C1);
- infile.close();
- loadCoords = true;
- }
- }
- void DrawLines(HWND hwnd)
- {
- HDC hdc = GetDC(hwnd);
- HPEN hPen = CreatePen(PS_SOLID, 20, RGB(255, 0, 0));
- HPEN holdPen = static_cast<HPEN>(SelectObject(hdc, hPen));
- MoveToEx(hdc, 50, 350, NULL);
- LineTo(hdc, 500, 350);
- SelectObject(hdc, holdPen);
- DeleteObject(hPen);
- }
- void DrawCrossOnClick(HWND hwnd)
- {
- crossCounter++;
- POINT mouseCoords;
- GetCursorPos(&mouseCoords);
- xCoords.push_back(mouseCoords.x);
- yCoords.push_back(mouseCoords.y);
- HDC hdc = GetDC(hwnd);
- HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
- HPEN holdPen = static_cast<HPEN>(SelectObject(hdc, hPen));
- MoveToEx(hdc, mouseCoords.x - 8, mouseCoords.y, NULL);
- LineTo(hdc, mouseCoords.x + 7, mouseCoords.y);
- MoveToEx(hdc, mouseCoords.x, mouseCoords.y - 7, NULL);
- LineTo(hdc, mouseCoords.x, mouseCoords.y + 7);
- SelectObject(hdc, holdPen);
- DeleteObject(hPen);
- crossIsDrawing = true;
- }
- void ReDrawCross(HWND hwnd)
- {
- if (xCoords.size() > 0 && yCoords.size() > 0)
- {
- crossCounter--;
- HDC hdc = GetDC(hwnd);
- HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
- HPEN holdPen = static_cast<HPEN>(SelectObject(hdc, hPen));
- for (size_t h = 0, size = xCoords.size(); h < size - 1; ++h)
- {
- MoveToEx(hdc, xCoords.at(h) - 8, yCoords.at(h), NULL);
- LineTo(hdc, xCoords.at(h) + 7, yCoords.at(h));
- MoveToEx(hdc, xCoords.at(h), yCoords.at(h) - 7, NULL);
- LineTo(hdc, xCoords.at(h), yCoords.at(h) + 7);
- }
- xCoords.pop_back();
- yCoords.pop_back();
- SelectObject(hdc, holdPen);
- DeleteObject(hPen);
- }
- }
- void DrawRect(HWND hwnd)
- {
- if (xCoords.size() == 4 && yCoords.size() == 4)
- {
- HDC hdc = GetDC(hwnd);
- HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
- HPEN holdPen = static_cast<HPEN>(SelectObject(hdc, hPen));
- POINT smallestCoords;
- POINT bigestCoords;
- std::sort(xCoords.begin(), xCoords.end());
- std::sort(yCoords.begin(), yCoords.end());
- smallestCoords.x = xCoords.at(0);
- smallestCoords.y = yCoords.at(0);
- bigestCoords.x = xCoords.at(3);
- bigestCoords.y = yCoords.at(3);
- saveCoords(smallestCoords, bigestCoords);
- MoveToEx(hdc, smallestCoords.x, smallestCoords.y, NULL);
- LineTo(hdc, bigestCoords.x, smallestCoords.y);
- MoveToEx(hdc, bigestCoords.x, smallestCoords.y, NULL);
- LineTo(hdc, bigestCoords.x, bigestCoords.y);
- MoveToEx(hdc, smallestCoords.x, bigestCoords.y, NULL);
- LineTo(hdc, bigestCoords.x, bigestCoords.y);
- MoveToEx(hdc, smallestCoords.x, smallestCoords.y, NULL);
- LineTo(hdc, smallestCoords.x, bigestCoords.y);
- xCoords.clear();
- yCoords.clear();
- SelectObject(hdc, holdPen);
- DeleteObject(hPen);
- if (CoordsList.size() != 0)
- {
- DrawAllRect(hwnd);
- }
- //savePhase = true;
- }
- }
- void DrawLine(HWND hwnd)
- {
- if (xCoords.size() == 2 && yCoords.size() == 2)
- {
- HDC hdc = GetDC(hwnd);
- HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
- HPEN holdPen = static_cast<HPEN>(SelectObject(hdc, hPen));
- POINT firstPoint;
- POINT secondPoint;
- int xDiff, yDiff;
- xDiff = xCoords.at(0) - xCoords.at(1);
- yDiff = yCoords.at(0) - yCoords.at(1);
- if (std::signbit((double)xDiff))
- {
- xDiff = -xDiff;
- }
- else if (std::signbit((double)yDiff))
- {
- yDiff = -yDiff;
- }
- if (xDiff < yDiff)
- {
- firstPoint.x = xCoords.at(0);
- firstPoint.y = yCoords.at(0);
- secondPoint.x = xCoords.at(0);
- secondPoint.y = yCoords.at(1);
- }
- else
- {
- firstPoint.x = xCoords.at(0);
- firstPoint.y = yCoords.at(0);
- secondPoint.x = xCoords.at(1);
- secondPoint.y = yCoords.at(0);
- }
- saveCoords(firstPoint, secondPoint);
- MoveToEx(hdc, firstPoint.x, firstPoint.y, NULL);
- LineTo(hdc, secondPoint.x, secondPoint.y);
- xCoords.clear();
- yCoords.clear();
- SelectObject(hdc, holdPen);
- DeleteObject(hPen);
- }
- }
- void saveCoords(POINT smallestCoords, POINT bigestCoords)
- {
- Coords C1;
- C1.smallestCoords.x = smallestCoords.x;
- C1.smallestCoords.y = smallestCoords.y;
- C1.bigestCoords.x = bigestCoords.x;
- C1.bigestCoords.y = bigestCoords.y;
- CoordsList.push_back(C1);
- }
- void DrawAllRect(HWND hwnd)
- {
- if (CoordsList.size() != 0)
- {
- HDC hdc = GetDC(hwnd);
- HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
- HPEN holdPen = static_cast<HPEN>(SelectObject(hdc, hPen));
- for (size_t CoordsListSize = 0, size = CoordsList.size(); CoordsListSize < size; ++CoordsListSize)
- {
- MoveToEx(hdc, CoordsList.at(CoordsListSize).smallestCoords.x, CoordsList.at(CoordsListSize).smallestCoords.y, NULL);
- LineTo(hdc, CoordsList.at(CoordsListSize).bigestCoords.x, CoordsList.at(CoordsListSize).smallestCoords.y);
- MoveToEx(hdc, CoordsList.at(CoordsListSize).bigestCoords.x, CoordsList.at(CoordsListSize).smallestCoords.y, NULL);
- LineTo(hdc, CoordsList.at(CoordsListSize).bigestCoords.x, CoordsList.at(CoordsListSize).bigestCoords.y);
- MoveToEx(hdc, CoordsList.at(CoordsListSize).smallestCoords.x, CoordsList.at(CoordsListSize).bigestCoords.y, NULL);
- LineTo(hdc, CoordsList.at(CoordsListSize).bigestCoords.x, CoordsList.at(CoordsListSize).bigestCoords.y);
- MoveToEx(hdc, CoordsList.at(CoordsListSize).smallestCoords.x, CoordsList.at(CoordsListSize).smallestCoords.y, NULL);
- LineTo(hdc, CoordsList.at(CoordsListSize).smallestCoords.x, CoordsList.at(CoordsListSize).bigestCoords.y);
- }
- SelectObject(hdc, holdPen);
- DeleteObject(hPen);
- }
- }
- void DrawAllLine(HWND hwnd)
- {
- if (CoordsList.size() != 0)
- {
- HDC hdc = GetDC(hwnd);
- HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
- HPEN holdPen = static_cast<HPEN>(SelectObject(hdc, hPen));
- for (size_t CoordsListSize = 0, size = CoordsList.size(); CoordsListSize < size; ++CoordsListSize)
- {
- MoveToEx(hdc, CoordsList.at(CoordsListSize).smallestCoords.x, CoordsList.at(CoordsListSize).smallestCoords.y, NULL);
- LineTo(hdc, CoordsList.at(CoordsListSize).bigestCoords.x, CoordsList.at(CoordsListSize).bigestCoords.y);
- }
- SelectObject(hdc, holdPen);
- DeleteObject(hPen);
- }
- }
- bool isMouseInrect()
- {
- bool InRect = false;
- POINT mouseCoords;
- GetCursorPos(&mouseCoords);
- for (size_t CoordsListSize = 0, size = CoordsList.size(); CoordsListSize < size; ++CoordsListSize)
- {
- POINT vectorSmallestCoords;
- POINT vectorBigestCoords;
- vectorSmallestCoords = CoordsList.at(CoordsListSize).smallestCoords;
- vectorBigestCoords = CoordsList.at(CoordsListSize).bigestCoords;
- if (((mouseCoords.x >= CoordsList.at(CoordsListSize).smallestCoords.x) && (mouseCoords.x <= CoordsList.at(CoordsListSize).bigestCoords.x)) && ((mouseCoords.y >= CoordsList.at(CoordsListSize).smallestCoords.y) && (mouseCoords.y <= CoordsList.at(CoordsListSize).bigestCoords.y)))
- {
- InRect = true;
- }
- }
- return InRect;
- }
- int getRect()
- {
- int rectNumber = 0;
- POINT mouseCoords;
- GetCursorPos(&mouseCoords);
- for (size_t CoordsListSize = 0, size = CoordsList.size(); CoordsListSize < size; ++CoordsListSize)
- {
- if ((mouseCoords.x >= CoordsList.at(CoordsListSize).smallestCoords.x) && (mouseCoords.x <= CoordsList.at(CoordsListSize).bigestCoords.x)
- && (mouseCoords.y >= CoordsList.at(CoordsListSize).smallestCoords.y) && (mouseCoords.y <= CoordsList.at(CoordsListSize).bigestCoords.y))
- {
- rectNumber = CoordsListSize;
- }
- }
- return rectNumber;
- }
- double getSwFract(int mouseX)
- {
- double MouseX = 0;
- int screenW = GetSystemMetrics(SM_CXSCREEN);
- MouseX = (double)(mouseX) / (double)screenW;
- return MouseX;
- }
- double getShFract(int mouseY)
- {
- double MouseY = 0;
- int screenH = GetSystemMetrics(SM_CYSCREEN);
- MouseY = (double)(mouseY) / (double)screenH;
- return MouseY;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement