Board index » cppbuilder » Problems Changing Cursor While Modal Form Opens

Problems Changing Cursor While Modal Form Opens

I have a modal form that takes about 5 seconds to open, due to some
processing in its constructor. I want to change Screen->Cursor to
crHourGlass between the time the button that opens the form is
clicked, and the time the form appears. I have unsuccessfully tried
this two different ways:

First, I tried setting the cursor right before the form is opened,
and changing it back to the default when the modal form opened:
TFormMain::ButtonOpenModalFormClick
{
        Screen->Cursor = crHourGlass;
        Application->ProcessMessages();
        FormModal = new TFormModal(this);
        FormModal->ShowModal();

Quote
}

TFormModal::TFormModal
{
        [Do stuff that takes a while to process]
        Screen->Cursor = crDefault;
        Application->ProcessMessages();
Quote
}

This didn't change the cursor to an hourglass.

Then, I moved the change to the hourglass to the modal form's
constructor:
TFormModal::TFormModal
{
        Screen->Cursor = crHourGlass;
        Application->ProcessMessages();
        [Do stuff that takes a while to process]
        Screen->Cursor = crDefault;
        Application->ProcessMessages();

Quote
}

This didn't change the cursor, either.

I think I'm experiencing this issue due to the fact that the form
is modal, but I'm not sure. Any ideas? Thanks in advance.

 

Re:Problems Changing Cursor While Modal Form Opens


Change it in the OnShow event for the modal form.  That should do the trick.
Do your processing in OnShow.  When you're done, set it back to crDefault.
Your OnShow event handler will finish and it'll be ready to roll.

----------------------------------------------------------------------------
Dave Fenwick                                                Asset Software,
Inc.
Nomadic Developer

Quote

> First, I tried setting the cursor right before the form is opened,
> and changing it back to the default when the modal form opened:
> TFormMain::ButtonOpenModalFormClick
> {
>     Screen->Cursor = crHourGlass;
>     Application->ProcessMessages();
>     FormModal = new TFormModal(this);
>     FormModal->ShowModal();
> }
> TFormModal::TFormModal
> {
>     [Do stuff that takes a while to process]
>     Screen->Cursor = crDefault;
>     Application->ProcessMessages();
> }
> This didn't change the cursor to an hourglass.

> Then, I moved the change to the hourglass to the modal form's
> constructor:
> TFormModal::TFormModal
> {
>     Screen->Cursor = crHourGlass;
>     Application->ProcessMessages();
>     [Do stuff that takes a while to process]
>     Screen->Cursor = crDefault;
>     Application->ProcessMessages();
> }
> This didn't change the cursor, either.

> I think I'm experiencing this issue due to the fact that the form
> is modal, but I'm not sure. Any ideas? Thanks in advance.

Re:Problems Changing Cursor While Modal Form Opens


Thanks for the suggestion, Dave. I tried moving things to OnShow(),
but the cursor still doesn't change. This is getting frustrating!

Re:Problems Changing Cursor While Modal Form Opens


I just built a tiny application that does exactly what you posted in your
first message.  I used your first example as a baseline.  It worked
perfectly.

I then did a little tinkering.  I added some Sleep(1000) statements in a
small for loop in the constructor of the modal form.  After each Sleep(1000)
I put in an Application->ProcessMessages().  This had some interesting
results.  If I took my cursor and moved it around in the main window, it
stayed an hourglass.  If I moved it out of the main form (all this while the
child modal dialog was loading) it would change to whatever cursor was used
in the window it was hovering over until I moved back into the main form, at
which point it became an hourglass again.  If I moved it out of the main
form, it would change to that cursor in the underlying window, but if I
moved it back into the main form while slowly moving it over the titlebar,
it would change to crDefault and stay that way.

Do you, by chance, have some Application->ProcessMessages() statements in
the section of code that the dialog box is dealing with?  If so, try and
comment those out and see if it helps.  Seems to me that a windows message
is being sent to the application to modify the cursor if it hovers over
certain elements (particularly the title bar decorations, which are
generated by Windows when the CreateWindow call is invoked.)
Application->ProcessMessages() is then handing them off to the application
and the application is changing the cursor, which is what it's being told to
do.

Remove the Application->ProcessMessages() statements and see what happens.

----------------------------------------------------------------------------
Dave Fenwick                                                Asset Software,
Inc.
Nomadic Developer

"C.R. Hinners" <chinn...@that-microsoft-free-email-service.com> wrote in
message news:Xns91FA624668B05chinnersthatmicrosof@207.105.83.65...

Quote
> Thanks for the suggestion, Dave. I tried moving things to OnShow(),
> but the cursor still doesn't change. This is getting frustrating!

Other Threads