Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==++ Here's the full source code (file 1/1) of "main.cpp"::++==
- #include <vector>
- #include <windows.h>
- //#include <iostream>
- #include "resource.h" // Add this with your other includes
- using namespace std;
- // Forward Declarations
- struct Brushstroke;
- struct Eraserstroke;
- void DrawBrush(HDC hdc, int x, int y);
- void Erase(HDC hdc, int x, int y);
- void ClearDrawing(HDC hdc, int width, int height);
- void DrawSmoothBrush(HDC hdc, int x, int y, bool isScreenDC);
- // Add these global variables at the top
- int scrollX = 0;
- int scrollY = 0;
- bool isSpacePressed = false;
- POINT lastMousePos = { 0, 0 };
- POINT dragStart = { 0, 0 };
- int virtualWidth = 10000;
- int virtualHeight = 10000;
- // Add these global variables if not already present
- std::vector<Brushstroke> storedBrushstrokes;
- std::vector<Eraserstroke> storedEraserstrokes;
- HDC hMemoryDC = NULL;
- HBITMAP hMemoryBitmap = NULL;
- HBITMAP hOldBitmap = NULL; // Add this to store the old bitmap
- int canvasWidth = 10000;
- int canvasHeight = 10000;
- bool isPaintbrushSelected = true; // Add a global variable to track the selected tool
- // Define a vector to store the doodle points for the Paintbrush tool
- //std::vector<POINT> paintbrushDoodlePoints;
- //new mod code
- POINT previousPoint; // Add a new global variable to track the previous point
- // Declare hdc as a global variable
- HDC hdc;
- HWND hWnd; // Declare the window handle variable globally or within the appropriate scope
- //bool needsRedraw = true; // Add this line at the top of your file
- // Declare a global variable to specify the grid spacing
- //int gridSpacing = 20;
- // Define a struct to store brushstroke information
- struct Brushstroke {
- int x;
- int y;
- int size;
- COLORREF color;
- // Add any other necessary properties for the brushstroke
- };
- // Define a struct to store eraserstroke information
- struct Eraserstroke {
- int x;
- int y;
- int size;
- COLORREF color;
- // Add any other necessary properties for the eraserstroke
- };
- // Declare a vector to store the brushstrokes
- //std::vector<Brushstroke> storedBrushstrokes;
- //std::vector<Eraserstroke> storedEraserstrokes;
- // Global variables to store the minimized brushstrokes
- std::vector<Brushstroke> minimizedDrawnBrushstrokes;
- std::vector<Eraserstroke> minimizedErasedBrushstrokes;
- // Function declaration for DrawGrid
- //void DrawGrid(HDC hdc, int spacing, COLORREF color); //drawgrid disableddefault
- // Optimized DrawGrid function to efficiently draw both vertical and horizontal lines
- // Add this function to initialize the memory bitmap
- // Add this function
- void InitializeMemoryBitmap(HWND hwnd) {
- HDC hdc = GetDC(hwnd);
- // Delete old objects if they exist
- if (hMemoryDC) {
- if (hOldBitmap) {
- SelectObject(hMemoryDC, hOldBitmap);
- }
- DeleteDC(hMemoryDC);
- }
- if (hMemoryBitmap) {
- DeleteObject(hMemoryBitmap);
- }
- // Create new memory DC and bitmap
- hMemoryDC = CreateCompatibleDC(hdc);
- hMemoryBitmap = CreateCompatibleBitmap(hdc, virtualWidth, virtualHeight);
- hOldBitmap = (HBITMAP)SelectObject(hMemoryDC, hMemoryBitmap);
- // Fill with white background
- HBRUSH whiteBrush = CreateSolidBrush(RGB(255, 255, 255));
- RECT rect = { 0, 0, virtualWidth, virtualHeight };
- FillRect(hMemoryDC, &rect, whiteBrush);
- DeleteObject(whiteBrush);
- ReleaseDC(hwnd, hdc);
- }
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- HINSTANCE hInst;
- bool isDrawing = false;
- bool isErasing = false;
- bool isClearing = false;
- //bool isPaintbrushSelected = false;
- bool isEraserSelected = false;
- int brushSize = 10;
- //POINT previousPoint;
- //old pre-gpt
- /*void DrawBrush(HDC hdc, int x, int y) {
- HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 0)); // Set the brush color to fully red
- SelectObject(hdc, GetStockObject(NULL_PEN)); // Set the pen to null to remove the border
- SelectObject(hdc, hBrush);
- Ellipse(hdc, x - brushSize, y - brushSize, x + brushSize, y + brushSize);
- DeleteObject(hBrush);
- }*/
- //new gpt broken?
- void DrawBrush(HDC hdc, int x, int y) {
- HRGN hRgn = CreateEllipticRgn(x - brushSize, y - brushSize, x + brushSize, y + brushSize);
- FillRgn(hdc, hRgn, CreateSolidBrush(RGB(255, 0, 0)));
- DeleteObject(hRgn);
- }
- /*void DrawBrush(HDC hdc, int x, int y) {
- HRGN hRgn = CreateEllipticRgn(x - brushSize, y - brushSize, x + brushSize, y + brushSize);
- FillRgn(hdc, hRgn, CreateSolidBrush(RGB(255, 0, 0)));
- DeleteObject(hRgn);
- }*/
- //broken old
- void Erase(HDC hdc, int x, int y) {
- HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255));
- SelectObject(hdc, GetStockObject(NULL_PEN));
- SelectObject(hdc, hBrush);
- Ellipse(hdc, x - brushSize, y - brushSize, x + brushSize, y + brushSize);
- DeleteObject(hBrush);
- }
- /*void Erase(HDC hdc, int x, int y) {
- HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255)); // Set the brush color to white
- HGDIOBJ hOldBrush = SelectObject(hdc, hBrush);
- Ellipse(hdc, x - brushSize, y - brushSize, x + brushSize, y + brushSize);
- SelectObject(hdc, hOldBrush);
- DeleteObject(hBrush);
- }*/
- //start test of new eraser
- /*void Erase(HDC hdc, int x, int y) {
- HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255));
- SelectObject(hdc, GetStockObject(NULL_PEN));
- SelectObject(hdc, hBrush);
- Ellipse(hdc, x - brushSize, y - brushSize, x + brushSize, y + brushSize);
- DeleteObject(hBrush);
- }*/
- //end test of new eraser
- //start commented out testing new gpt function eraser
- /*void Erase(HDC hdc, int x, int y) {
- // HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255)); // Set the brush color to white
- // HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); // Set the brush color to black
- HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255)); // Set the brush color to white
- HPEN hPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255)); // Set the pen color to white
- HGDIOBJ hOldBrush = SelectObject(hdc, hBrush);
- HGDIOBJ hOldPen = SelectObject(hdc, hPen);
- Ellipse(hdc, x - brushSize, y - brushSize, x + brushSize, y + brushSize);
- SelectObject(hdc, hOldBrush);
- SelectObject(hdc, hOldPen);
- DeleteObject(hBrush);
- DeleteObject(hPen);
- }*/
- //end commented out testing new gpt function eraser
- //newgptdelete
- void ClearDrawing(HWND hwnd) {
- // Clear the memory DC
- RECT rect = { 0, 0, virtualWidth, virtualHeight };
- HBRUSH whiteBrush = CreateSolidBrush(RGB(255, 255, 255));
- FillRect(hMemoryDC, &rect, whiteBrush);
- DeleteObject(whiteBrush);
- // Clear all stored strokes
- storedBrushstrokes.clear();
- storedEraserstrokes.clear();
- // Reset scroll position (optional)
- scrollX = 0;
- scrollY = 0;
- // Force a redraw
- InvalidateRect(hwnd, NULL, FALSE);
- }
- /*void ClearDrawing(HDC hdc, int width, int height) {
- RECT rect = { 0, 0, width, height };
- // HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255)); // Set the color to white
- // HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); // Set the color to black
- HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255)); // Set the color to white
- FillRect(hdc, &rect, hBrush);
- DeleteObject(hBrush);
- }*/
- //removing drawgrid
- /*void DrawGrid(HDC hdc, int spacing, COLORREF color) {
- RECT rect;
- GetClientRect(hWnd, &rect);
- HPEN hPen = CreatePen(PS_SOLID, 1, color);
- HPEN hOldPen = (HPEN)SelectObject(hdc, hPen);
- // Draw vertical lines
- for (int x = 0; x <= rect.right; x += spacing) {
- MoveToEx(hdc, x, 0, NULL);
- LineTo(hdc, x, rect.bottom);
- }
- // Draw horizontal lines
- for (int y = 0; y <= rect.bottom; y += spacing) {
- MoveToEx(hdc, 0, y, NULL);
- LineTo(hdc, rect.right, y);
- }
- SelectObject(hdc, hOldPen);
- DeleteObject(hPen);
- }*/
- //gpts old drawgrid
- /*void DrawGrid(HDC hdc, int spacing, COLORREF color) {
- RECT rect;
- GetClientRect(hWnd, &rect);
- HPEN hPen = CreatePen(PS_SOLID, 1, color);
- HPEN hOldPen = (HPEN)SelectObject(hdc, hPen);
- // Draw vertical lines
- for (int x = 0; x < rect.right; x += spacing) {
- MoveToEx(hdc, x, 0, NULL);
- LineTo(hdc, x, rect.bottom);
- }
- // Draw horizontal lines
- for (int y = 0; y < rect.bottom; y += spacing) {
- MoveToEx(hdc, 0, y, NULL);
- LineTo(hdc, rect.right, y);
- }
- SelectObject(hdc, hOldPen);
- DeleteObject(hPen);
- }*/
- //chatgpt disabled
- /*void DrawGrid(HDC hdc, int spacing, COLORREF color) {
- RECT rect;
- GetClientRect(hWnd, &rect);
- HPEN hPen = CreatePen(PS_SOLID, 1, color);
- HPEN hOldPen = (HPEN)SelectObject(hdc, hPen);
- // Draw vertical lines
- for (int x = 0; x < rect.right; x += spacing) {
- MoveToEx(hdc, x, 0, NULL);
- LineTo(hdc, x, rect.bottom);
- }
- // Draw horizontal lines
- for (int y = 0; y < rect.bottom; y += spacing) {
- MoveToEx(hdc, 0, y, NULL);
- LineTo(hdc, rect.right, y);
- }
- SelectObject(hdc, hOldPen);
- DeleteObject(hPen);
- }*/
- //temp disabled for relocated code
- /*int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
- const wchar_t CLASS_NAME[] = L"DoodleAppClass";
- WNDCLASS wc = { };
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = hInstance;
- wc.lpszClassName = CLASS_NAME;
- RegisterClass(&wc);
- hInst = hInstance;
- HWND hwnd = CreateWindowEx(
- 0,
- CLASS_NAME,
- L"Doodle App",
- WS_OVERLAPPEDWINDOW | WS_MAXIMIZE, //& ~WS_MINIMIZEBOX, Add WS_MAXIMIZE style
- // Disable the Minimize button
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- //hdc = GetDC(hWnd); //gptadded
- if (hwnd == NULL) {
- return 0;
- }
- ShowWindow(hwnd, SW_SHOWMAXIMIZED); // Show the window maximized
- //old code
- //ShowWindow(hwnd, nCmdShow);
- MSG msg = { };
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }*/
- //new code
- void DrawSmoothBrush(HDC hdc, int x, int y, bool isScreenDC) {
- if (!isDrawing) return;
- POINT currentPoint = { x, y };
- int numPoints = 3;
- // Convert previous point to current coordinate system if needed
- POINT drawPrevPoint = previousPoint;
- if (isScreenDC) {
- // For screen DC, add scroll offset to stored canvas coordinates
- drawPrevPoint.x = previousPoint.x + scrollX;
- drawPrevPoint.y = previousPoint.y + scrollY;
- }
- for (int i = 1; i <= numPoints; i++) {
- float t = (float)i / (float)numPoints;
- int smoothX = (int)(drawPrevPoint.x + t * (currentPoint.x - drawPrevPoint.x));
- int smoothY = (int)(drawPrevPoint.y + t * (currentPoint.y - drawPrevPoint.y));
- if (isPaintbrushSelected) {
- DrawBrush(hdc, smoothX, smoothY);
- // Only store strokes once, in canvas coordinates
- if (!isScreenDC) {
- Brushstroke newBrushstroke;
- newBrushstroke.x = smoothX;
- newBrushstroke.y = smoothY;
- newBrushstroke.size = brushSize;
- newBrushstroke.color = RGB(255, 0, 0);
- storedBrushstrokes.push_back(newBrushstroke);
- }
- }
- else if (isEraserSelected) {
- Erase(hdc, smoothX, smoothY);
- if (!isScreenDC) {
- Eraserstroke newEraserStroke;
- newEraserStroke.x = smoothX;
- newEraserStroke.y = smoothY;
- newEraserStroke.size = brushSize;
- newEraserStroke.color = RGB(255, 255, 255);
- storedEraserstrokes.push_back(newEraserStroke);
- }
- }
- }
- // Store the current point in canvas coordinates
- if (!isScreenDC) {
- previousPoint = currentPoint;
- }
- }
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
- switch (uMsg) {
- {
- InitializeMemoryBitmap(hwnd);
- isPaintbrushSelected = true;
- break;
- }
- case WM_CREATE:
- {
- InitializeMemoryBitmap(hwnd);
- isPaintbrushSelected = true;
- break;
- }
- case WM_KEYDOWN:
- if (wParam == VK_ADD) { // Press "+" key to increase brush size
- brushSize += 5;
- }
- else if (wParam == VK_SUBTRACT) { // Press "-" key to decrease brush size
- if (brushSize > 5) {
- brushSize -= 5;
- }
- }
- else if (wParam == 0x43) { // Press "C" key to clear drawing
- if (!(GetKeyState(VK_CONTROL) & 0x8000)) {
- if (!(GetKeyState(VK_CONTROL) & 0x8000)) {
- isClearing = true;
- ClearDrawing(hwnd);
- }
- }
- break;
- }
- else if (wParam == 0x50) { // Press "P" key to select paintbrush
- isPaintbrushSelected = true;
- isEraserSelected = false;
- }
- else if (wParam == 0x45) { // Press "E" key to select eraser
- isEraserSelected = true;
- isPaintbrushSelected = false;
- }
- else if (wParam == VK_ESCAPE) {
- if (hMemoryDC) {
- if (hOldBitmap) {
- SelectObject(hMemoryDC, hOldBitmap);
- }
- DeleteDC(hMemoryDC);
- }
- if (hMemoryBitmap) {
- DeleteObject(hMemoryBitmap);
- }
- PostQuitMessage(0);
- }
- else if (wParam == VK_F1) {
- MessageBox(hwnd, TEXT("I made an Infinite Canvas app using GDI and Memory DC, no need for bloated Godot Engine/ Frameworks or M$ Infinite Canvas Control! Eternity of effort paid off! (763 lines of code) by Entisoft Software (c) Evans Thorpemorton"), TEXT("Information"), MB_OK | MB_ICONINFORMATION);
- return 0;
- }
- // Add this to your existing WM_KEYDOWN handler
- if (wParam == VK_SPACE && !isSpacePressed) {
- isSpacePressed = true;
- GetCursorPos(&lastMousePos);
- ScreenToClient(hwnd, &lastMousePos);
- dragStart = lastMousePos; // Store the starting point of the drag
- SetCursor(LoadCursor(NULL, IDC_SIZEALL));
- }
- break;
- case WM_KEYUP:
- if (wParam == VK_SPACE) {
- isSpacePressed = false;
- SetCursor(LoadCursor(NULL, IDC_ARROW));
- }
- break;
- // Update WM_LBUTTONDOWN handler:
- case WM_LBUTTONDOWN:
- {
- if (isPaintbrushSelected || isEraserSelected) {
- int x = LOWORD(lParam);
- int y = HIWORD(lParam);
- // Store initial point in canvas coordinates
- previousPoint.x = x - scrollX;
- previousPoint.y = y - scrollY;
- isDrawing = true;
- }
- }
- break;
- // Optional: Add this to WM_LBUTTONUP to ensure smooth lines start fresh:
- case WM_LBUTTONUP:
- {
- isDrawing = false;
- break;
- }
- //new code
- // Modified WM_MOUSEMOVE handler:
- // Modify the WM_MOUSEMOVE handler:
- case WM_MOUSEMOVE:
- {
- int x = LOWORD(lParam);
- int y = HIWORD(lParam);
- if (isSpacePressed) {
- int deltaX = x - lastMousePos.x;
- int deltaY = y - lastMousePos.y;
- scrollX += deltaX;
- scrollY += deltaY;
- RECT clientRect;
- GetClientRect(hwnd, &clientRect);
- scrollX = min(0, max(-virtualWidth + clientRect.right, scrollX));
- scrollY = min(0, max(-virtualHeight + clientRect.bottom, scrollY));
- lastMousePos.x = x;
- lastMousePos.y = y;
- InvalidateRect(hwnd, NULL, FALSE);
- }
- else if (isDrawing) {
- if (isPaintbrushSelected || isEraserSelected) {
- // Draw to memory DC first (in canvas coordinates)
- DrawSmoothBrush(hMemoryDC, x - scrollX, y - scrollY, false);
- // Then draw to screen DC (in screen coordinates)
- HDC hdc = GetDC(hwnd);
- DrawSmoothBrush(hdc, x, y, true);
- ReleaseDC(hwnd, hdc);
- }
- }
- if (isSpacePressed) {
- SetCursor(LoadCursor(NULL, IDC_SIZEALL));
- }
- else if (isPaintbrushSelected || isEraserSelected) {
- SetCursor(LoadCursor(NULL, IDC_CROSS));
- }
- }
- break;
- /* case WM_MOUSEMOVE:
- if (isDrawing) {
- HDC hdc = GetDC(hwnd);
- DrawBrush(hdc, LOWORD(lParam), HIWORD(lParam));
- ReleaseDC(hwnd, hdc);
- }
- else if (isErasing) {
- HDC hdc = GetDC(hwnd);
- Erase(hdc, LOWORD(lParam), HIWORD(lParam));
- ReleaseDC(hwnd, hdc);
- }
- else if (isClearing) {
- HDC hdc = GetDC(hwnd);
- RECT rect;
- GetClientRect(hwnd, &rect);
- ClearDrawing(hdc, rect.right, rect.bottom);
- ReleaseDC(hwnd, hdc);
- isClearing = false;
- }
- break;
- */
- case WM_SIZE:
- {
- //old code
- //InvalidateRect(hwnd, NULL, true);
- //LASTLAST::
- static bool isMinimized = false;
- if (wParam == SIZE_MINIMIZED)
- {
- isMinimized = true;
- }
- else if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED)
- {
- if (isMinimized)
- {
- minimizedDrawnBrushstrokes = storedBrushstrokes;
- minimizedErasedBrushstrokes = storedEraserstrokes;
- isMinimized = false;
- }
- // Redraw the window
- InvalidateRect(hwnd, NULL, TRUE);
- }
- //LASTCLASS::
- /*if (wParam == SIZE_MINIMIZED) {
- minimizedDrawnBrushstrokes = storedBrushstrokes;
- minimizedErasedBrushstrokes = storedEraserstrokes;
- }
- else if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED) {
- storedBrushstrokes = minimizedDrawnBrushstrokes;
- storedEraserstrokes = minimizedErasedBrushstrokes;
- // Redraw the window
- InvalidateRect(hwnd, NULL, TRUE);
- }*/
- //gonnareplace winner!
- /*if (wParam == SIZE_MINIMIZED) {
- minimizedDrawnBrushstrokes = storedBrushstrokes;
- minimizedErasedBrushstrokes = storedEraserstrokes;
- }
- else if (wParam == SIZE_RESTORED) {
- storedBrushstrokes = minimizedDrawnBrushstrokes;
- storedEraserstrokes = minimizedErasedBrushstrokes;
- InvalidateRect(hwnd, NULL, TRUE);
- }*/
- //start chatgpt new modified code
- /*if (wParam == SIZE_MINIMIZED) {
- // Save the drawn and erased brushstrokes when minimizing
- minimizedDrawnBrushstrokes = storedBrushstrokes;
- minimizedErasedBrushstrokes = storedEraserstrokes;
- }
- else if (wParam == SIZE_RESTORED) {
- // Restore the minimized brushstrokes when restoring
- storedBrushstrokes = minimizedDrawnBrushstrokes;
- storedEraserstrokes = minimizedErasedBrushstrokes;
- // Trigger a repaint to redraw the brushstrokes
- InvalidateRect(hwnd, NULL, TRUE);
- }*/
- //end chatgpt new modified code
- //start working but no erase history code (adding brushstruct for eraser logic) fallbackcode
- /*if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED) {
- RECT rect;
- GetClientRect(hwnd, &rect);
- //ClearDrawing(hdc, rect.right, rect.bottom);
- }*/
- //end working but no erase history code fallbackcode
- //new replaced chatgpt
- /*if (wParam == SIZE_MAXIMIZED) {
- RECT rect;
- GetClientRect(hwnd, &rect);
- ClearDrawing(hdc, rect.right, rect.bottom);
- }*/
- /*else if (wParam == SIZE_RESTORED) {
- RECT rect;
- GetClientRect(hwnd, &rect);
- if (isPaintbrushSelected) {
- // Redraw the stored doodle contents for the Paintbrush tool
- for (const auto& point : paintbrushDoodlePoints) {
- // Use the stored points to redraw the doodle contents for the Paintbrush tool
- // Example: Draw a small circle at each point
- Ellipse(hdc, point.x - 2, point.y - 2, point.x + 2, point.y + 2);
- }
- }
- }*/
- //old code
- //new replaced chatgpt
- /*else if (wParam == SIZE_RESTORED) {
- RECT rect;
- GetClientRect(hwnd, &rect);
- // Handle resizing of contents when the window is restored
- // Add code to restore doodle contents here
- }
- else if (wParam == SIZE_MINIMIZED) {
- // Handle content when the window is minimized
- }*/
- }
- break;
- // Modified WM_PAINT handler:
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hwnd, &ps);
- // Create temporary DC for double buffering
- HDC tempDC = CreateCompatibleDC(hdc);
- RECT clientRect;
- GetClientRect(hwnd, &clientRect);
- HBITMAP tempBitmap = CreateCompatibleBitmap(hdc, clientRect.right, clientRect.bottom);
- HBITMAP oldTempBitmap = (HBITMAP)SelectObject(tempDC, tempBitmap);
- // Fill with white background
- HBRUSH whiteBrush = CreateSolidBrush(RGB(255, 255, 255));
- FillRect(tempDC, &clientRect, whiteBrush);
- DeleteObject(whiteBrush);
- // Copy visible portion from memory DC to temp DC
- BitBlt(tempDC, 0, 0, clientRect.right, clientRect.bottom,
- hMemoryDC, -scrollX, -scrollY, SRCCOPY);
- // Copy from temp DC to screen
- BitBlt(hdc, 0, 0, clientRect.right, clientRect.bottom,
- tempDC, 0, 0, SRCCOPY);
- // Cleanup
- SelectObject(tempDC, oldTempBitmap);
- DeleteObject(tempBitmap);
- DeleteDC(tempDC);
- EndPaint(hwnd, &ps);
- }
- break;
- // added newly to set Normal Pointer & not Busy Pointer
- case WM_SETCURSOR:
- if (LOWORD(lParam) == HTCLIENT) {
- SetCursor(LoadCursor(NULL, IDC_ARROW)); // Change to normal pointer
- return TRUE;
- }
- break;
- case WM_DESTROY:
- {
- if (hMemoryDC) {
- if (hOldBitmap) {
- SelectObject(hMemoryDC, hOldBitmap);
- }
- DeleteDC(hMemoryDC);
- }
- if (hMemoryBitmap) {
- DeleteObject(hMemoryBitmap);
- }
- PostQuitMessage(0);
- break;
- }
- default:
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
- const wchar_t CLASS_NAME[] = L"DoodleAppClass";
- WNDCLASS wc = { };
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = hInstance;
- wc.lpszClassName = CLASS_NAME;
- wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); // Add this line
- RegisterClass(&wc);
- hInst = hInstance;
- HWND hwnd = CreateWindowEx(
- 0,
- CLASS_NAME,
- L"[Infinite Canvas] Doodle App (P=Brush E=Eraser C=Clear +-=BrushSize Space+Drag=Scroll F1=About)",
- WS_OVERLAPPEDWINDOW | WS_MAXIMIZE,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- hdc = GetDC(hwnd);
- if (hwnd == NULL) {
- return 0;
- }
- ShowWindow(hwnd, SW_SHOWMAXIMIZED);
- //start chatgpt new modified code
- /*MSG msg = {};
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if (msg.message == WM_SIZE) {
- if (msg.wParam == SIZE_MINIMIZED) {
- // Save the drawn and erased brushstrokes when minimizing
- std::vector<Brushstroke> minimizedDrawnBrushstrokes = storedBrushstrokes;
- std::vector<Eraserstroke> minimizedErasedBrushstrokes = storedEraserStrokes;
- }
- else if (msg.wParam == SIZE_RESTORED) {
- // Restore the minimized brushstrokes when restoring
- storedBrushstrokes = minimizedDrawnBrushstrokes;
- storedEraserStrokes = minimizedErasedBrushstrokes;
- // Trigger a repaint to redraw the brushstrokes
- InvalidateRect(hwnd, NULL, TRUE);
- }
- }
- }*/
- //end chatgpt new modified code
- //start working but no erase history code (adding brushstruct for eraser logic) fallbackcode
- MSG msg = {};
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- //end working but no erase history code fallbackcode
- return 0;
- }
Add Comment
Please, Sign In to add comment