Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8005037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:06:14+00:00 2026-06-04T17:06:14+00:00

I’m having a bit of a hard time figuring out, how to remove a

  • 0

I’m having a bit of a hard time figuring out, how to remove a drawn ellipse after it has been drawn somewhere else. I need a circle to follow my mouse all the time and this is all the program should do. I get the mousepositions and draw my circle but how can I remove the last one?

#include <Windows.h>
#include <iostream>

void drawRect(int a1, int a2){
HDC screenDC = ::GetDC(0);
//Draw circle at mouse position
::Ellipse(screenDC, a1, a2+5, a1+9, a2+14);
::ReleaseDC(0, screenDC);
//::InvalidateRect(0, NULL, TRUE); //<- I tried that but then everything flickers
//Also, the refresh rate is not fast enough... still some circles left
}

int main(void)
{

int a1;
int a2;
bool exit=false;
while (exit!=true)
    {
    POINT cursorPos;
    GetCursorPos(&cursorPos);
    float x = 0;
    x = cursorPos.x; 
    float y = 0;
    y = cursorPos.y;

    a1=(int)cursorPos.x;
    a2=(int)cursorPos.y; 
    drawRect(a1, a2);

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:06:16+00:00Added an answer on June 4, 2026 at 5:06 pm

    You’d better use transparent window above all over the screen. This will be much easier. Windows is not designed to be acting the way you’ve just described. For optimizing the speed you have two ways:

    1. Using two DCs – one memory DC created by CreateCompatibleDC. In this way you can first prepare your image and then quickly draw it instead of your window’s DC.
    2. Remembering the rectangle, where you’ve drawn your circle and invalidating only this rectangle.

    Also note, that you should implement a hook over WM_MOUSEMOVE messages in order to receive them. The program with the loop will eat 99% of processor time for nothing. Look MSDN for mouse hooks.

    Ok, this will be WinAPI. Hope, you know how to write a WinAPI application basic stuff like message cycle and other. In any case you can use Visual Studio template for WinAPI applications. I’ll do so.
    First, remove the uninteresting code concerning About dialog and the staff (you can skip it, if you don’t know what to do). Next, you should create your window:

    • Update the MyRegisterClass function. Replace

      wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
      wcex.lpszMenuName = MAKEINTRESOURCE(IDC_…);

    with

    wcex.hbrBackground = CreateSolidBrush(RGB(128, 128, 128));
    wcex.lpszMenuName = NULL;
    
    • Update the InitInstance function. Replace

      hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

    with

    hWnd = CreateWindowEx(WS_EX_TOPMOST|WS_EX_LAYERED, szWindowClass, szTitle, WS_POPUP|WS_VISIBLE, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    

    Add following lines of code just after the hWnd is checked for consistency:

    SetLayeredWindowAttributes(hWnd, RGB(128, 128, 128), 255, LWA_COLORKEY);
    

    Replace

    ShowWindow(hWnd, nCmdShow);
    

    with

    ShowWindow(hWnd, SW_MAXIMIZE);
    
    • Now, implement the drawing in WM_PAINT section of WndProc.

      hdc = BeginPaint(hWnd, &ps);
      POINT ptNew;
      GetCursorPos(&ptNew);
      HBRUSH hbr = CreateSolidBrush(RGB(255, 255, 255));
      HBRUSH hold = (HBRUSH)SelectObject(hdc, hbr);
      Ellipse(hdc, ptNew.x + 15, ptNew.y + 15, ptNew.x + 30, ptNew.y + 30);
      SelectObject(hdc, hold);
      DeleteObject(hbr);
      ptOld = ptNew;
      EndPaint(hWnd, &ps);

    • Will continue with hooking tomorrow. Today is too late. Or, look at this article manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.