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 9128941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:38:05+00:00 2026-06-17T07:38:05+00:00

I am new to MFC and am making a simple program that will continuously

  • 0

I am new to MFC and am making a simple program that will continuously update two edit boxes. The edit boxes contain the x and y coordinates of the mouse cursor. The program only starts grabbing the cursor coordinates when the start button is clicked, and it’s supposed to stop when the stop button is clicked. But as soon as I click the start button the entire window freezes.

Here is what I have so far:

//Way up high in the code:
#include <windows.h>

//way down low in the code

void CmfcpixelDlg::OnBnClickedButtonStart()
{
POINT p;

CString x;
CString y;

int px;
int py;

while(stop == false){

    GetCursorPos(&p);

    px = p.x;
    //convert x coordinate to a CString
    x.Format(L"%d", px);
    //convert y coordinate to a CString
    py = p.y;
    y.Format(L"%d", py);
    m_x.SetWindowTextW(x.GetBuffer());
    m_y.SetWindowTextW(y.GetBuffer());


}
}
  • 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-17T07:38:06+00:00Added an answer on June 17, 2026 at 7:38 am

    You’re blocking the event loop. You can’t do a loop that requires user intervention to end in the GUI thread – you need to do it in a separate thread.

    In fact, you shouldn’t perform any lengthy operations in the main thread.

    Basically, the same thread that is running your loop is the thread that is responsible for displaying and updating the GUI. Because this thread is now waiting for a GUI update to exit the loop and this thread is the same thread that’s supposed to update the GUI, you have a Catch-22, or in programmer speak, a deadlock.

    To resolve this, you can split your code off into a new thread, or better yet, design it to eliminate the loop entirely. Your code is fairly simple, and this can be done loop free:

    • On click of start: set the flag.
    • On mouse move: update the x, y coordinate text if the flag is set. No loops!
    • On click of stop: unset the flag.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work on an MFC app containing OpenGL context.I am new to MFC that
I have inherited an old C++ (MFC) project and will have to add new
This might be very simple but I am new to MFC. I have a
I'm new to MFC programming. I have to write an application that reads a
I am working on a small MFC application..since am new to MFC I am
new to c#. I'm trying to make a simple system where I can search
New to Node.js and Express, I am trying to understand the two seems overlapping
thank you for you time in advance. Very new to MFC and attempting to
I'm creating a preferences form in VC++ MFC, and I have several textfields that
I have a MFC/C++ project that uses the ActiveX Document (Automation) approach for opening

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.