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

  • Home
  • SEARCH
  • 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 8312937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:19:35+00:00 2026-06-08T20:19:35+00:00

In my Delphi / C++Builder app, I have an OnMouseMove handler that lets the

  • 0

In my Delphi / C++Builder app, I have an OnMouseMove handler that lets the user interact with a plot by dragging plot elements. (We’ve manually implemented the necessary drag-and-drop logic instead of using the VCL’s OnDragOver et al.)

The OnMouseMove event updates both the main form and several child forms based on the current state of the plot. However, as long as I’m moving the mouse, neither the main form nor any of the child forms actually redraw their updated state unless I manually call Repaint on the form and each of its child forms. This is somewhat fragile, since it’s easy to miss a child form that needs to be repainted.

The instant I stop moving the mouse, the forms repaint as expected, so it appears that controls are being invalidated as expected, they’re just not getting repainted as long as OnMouseMove events / WM_MOUSEMOVE messages are coming in. (If I drag very slowly, then the screen will also repaint as expected.)

Even manually calling Repaint on each form isn’t always enough, because individual child forms’ controls may not redraw unless I repaint them individually. (For example, a TEdit displays its new value if I call its parent TForm’s Repaint, but a TRadioButton that I disable doesn’t appear disabled unless I call its own Repaint.)

Why is it necessary to call Repaint at all? Why isn’t Windows automatically repainting my app’s windows while I drag the mouse? Is there a better way of redrawing windows than trying to manually enumerate which windows need to have Repaint called?

From playing around with a brief test application, I’m wondering if the problem is that my OnMouseMove event is slow enough that WM_PAINT messages don’t get dispatched because the application is too busy with WM_MOUSEMOVE? I’m not sure if this is indeed the case or, if so, what to do about this.

Here’s some (hopefully not overly simplified) code to illustrate what I’m doing. GraphArea is a TImage whose Canvas contains the plot.

void __fastcall TMachineForm::GraphAreaMouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y)
{
    if (IsNearAdjustableObject(X, Y)) {
        is_adjusting = true;
    }
}

void TMachineForm::GraphAreaMouseMove(TObject *Sender,
    TShiftState Shift, int X, int Y)
{
    if (is_adjusting) {
        AdjustObject(X, Y);

        /* Draws to the GraphArea TImage by calling GraphArea->Canvas methods */
        RedrawGraphArea();

        /* Updates several standard VCL controls on ChildForm1 and ChildForm2;
         * e.g., ChildForm1->Edit1->Text = CalculatedValue(); */
        NotifyChildForm1OfAdjustment();
        NotifyChildForm2OfAdjustment();

        /* This is where I have to manually call Repaint. I don't know why. */
        GraphArea->Repaint();
        ChildForm1->Repaint();
        ChildForm2->Repaint();
    }
}

void TMachineForm::GraphAreaMouseUp(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y)
{
    is_adjusting = false;
}
  • 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-08T20:19:38+00:00Added an answer on June 8, 2026 at 8:19 pm

    Raymond Chen explains how WM_PAINT messages work. Invalidating a window (whether by setting VCL methods or properties that cause the window to be invalidated, or manually, by calling Invalidate) effectively causes a flag to be set saying that a WM_PAINT message should be delivered the next time GetMessage is called and no messages are available.

    As far as I can tell, if messages are being generated fast enough (for example, the WM_MOUSEMOVE messages) and processing these messages is taking long enough, then the message queue may never be empty, so WM_PAINT messages are never delivered.

    The solution is to manually call Update (which should perform a bit better than Repaint) or similar. Additional considerations:

    • Repainting all owned forms: I haven’t found a clean solution here, so I’ll probably continue manually tracking owned forms and manually invoking Repaint on them. (If I wanted, I can iterate over the TForm’s Components looking for TForms, but that adds measurable overhead.)
    • Handling child controls (such as the TRadioButton that doesn’t redraw itself as disabled in my example): Instead of calling Repaint or Update, use RedrawWindow, which can instruct child windows to redraw themselves as well.
      RedrawWindow(ChildForm1->Handle, NULL, NULL,
          RDW_UPDATENOW | RDW_ALLCHILDREN);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++ Builder DLL that must link against a Delphi package (BPL),
Delphi 2010 Windows 7 - 64 bit. I have an app which is reasonably
I inherited some Delphi components/code that currently compiles with C++ Builder 2007. I'm simply
We have a .lib file with functionality that must be included in a Delphi
We have a lot of dll-libraries written in both delphi and c++ builder, and
Delphi part: I have a class with the event and from that event I
Delphi 2010 reportedly supports gestures for user interaction (mouse or touch interface), primarily through
Delphi XE2, so I guess that is Indy 10(?). One server, 10 clients. I
Delphi 7 SQLSERVER 2000 I am having a problem with a legacy application that
I've got a Delphi 2007 VM which includes a reasonably up-to-date Report Builder and

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.