Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disabled button sends messages

153 views
Skip to first unread message

Eberhard Schefold

unread,
Oct 16, 1997, 3:00:00 AM10/16/97
to

I have a strange problem using EnableWindow() in a dialog-based
MFC application.

In the BN_CLICKED handler of a button I disable it for a while
using EnableWindow( FALSE ) and enable it again with
EnableWindow( TRUE ). I can see how the button surface changes
to the usual disabled style as expected. But if I press the button
while it's disabled I still get new BN_CLICKED messages.

The documentation says, "EnableWindow() enables or disables mouse
and keyboard input", so how can this happen?

I'd appreciate any hint. Thanks!

Ciao,
-- Eberhard

Andreas Schmidt

unread,
Oct 16, 1997, 3:00:00 AM10/16/97
to Eberhard Schefold

Hi Eberhard,
I use
GetDlgItem(ID_BUTTON)->EnableWindow(bEnable);
and it works inside my Dialogs.
Greetings from Hannover, Andreas

Eberhard Schefold

unread,
Oct 16, 1997, 3:00:00 AM10/16/97
to

Hallo Andreas,

thanks for your reply! I'm sorry about having been imprecise in
my description: Sure I have to access the button in some way,
either through GetDlgItem() or a CButton variable and DDX_Control()
in DoDataExchange() -- but the error occurs either way. Thank
you anyway!

-- Eberhard

Andreas Schmidt <a...@intra-sys.de> schrieb im Beitrag <34462693...@intra-sys.de>...

David Lowndes

unread,
Oct 17, 1997, 3:00:00 AM10/17/97
to

>In the BN_CLICKED handler of a button I disable it for a while
>using EnableWindow( FALSE ) and enable it again with
>EnableWindow( TRUE ).

Eberhard,

Is the disable/enable section during a single message processing -
i.e. is it a time when no message processing occurs in your
application? If that is the case, then I can believe that you'd get
the effect you see, because by the time your application processes the
mouse clicks you've re-enabled your button.

Dave
----
Address is altered to discourage junk mail.
Remove ".---" for the real address.
http://www.bj.co.uk

Eberhard Schefold

unread,
Oct 20, 1997, 3:00:00 AM10/20/97
to

Hallo David,

thanks for your thoughts on this issue. In fact, the disable/enable section
is located in a single message handler.

I guess I have to accept that the described behaviour is by design. I still
can get it together with the Win32 documentation of EnableWindow() that
states:

A disabled control cannot receive the keyboard focus, nor can a user
gain access to it.

I thought from this description that EnableWindow() would block the control
in such a way that Windows wouldn't send messages like WM_CLICK from this
very moment on. But in reality it seems that further message processing is
needed. If I try code like

CMyView::OnClickButtonInQuestion
{
GetDlgItem( IDC_BUTTON_IN_QUESTION )->EnableWindow( FALSE );

DoSomethingLenghtyButStillPeekAndPumpMessages();
// instead of DoSomethingLenghtyWithoutPeakAndPumpMessages()

GetDlgItem( IDC_BUTTON_IN_QUESTION )->EnableWindow( TRUE );
} ,

further button clicks in the disabled period are actually discarded.

Thanks again!

Servus,
-- Eberhard
____________________________________________________________________________

David Lowndes <dav...@mvps.org.---> wrote in
<344a62fa...@sparcone.bj.co.uk>...

0 new messages