Strange behavior when subclassing a static control in modal dialog 
Author Message
 Strange behavior when subclassing a static control in modal dialog

I have written a MFC program which uses a modal dialog window.
There is a static control in the dialog window. In order to
paint on this static control, I subclassed it by using
CMyStatic::SubclassDlgItem() and defined a OnPaint() in
CMyStatic. (CMyStatic is derived from CStatic.)  This works
fine.  But when I want this subclassed static control to do
something special when it is clicked, I add a OnLButtonDown()
in CMyStatic. To my surprise, CMyStatic::OnLButtonDown() is not
called when I clicked on the static control. Instead, the
CMyDialog::OnLButtonDown() is called.  Why?

Anybody can explain this for me?



Tue, 31 May 2005 08:38:44 GMT  
 Strange behavior when subclassing a static control in modal dialog

Quote:

>Anybody can explain this for me?

You have to work with notifications here:

1. set the windows style of the class to SS_NOTIFY

2. enter something like     ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)

3. declare and implement        afx_msg void OnClicked(); which is
your OnlButtonDown thing.

Normally CStatics are used only for navigation, you click it and the
focus is set its neighbor. So the click has to handled by the parent!

HTH

---
Thomas Gawehns
www.softwaremeister.com/daily_backup.html
daily backup changed/new files into zip archives



Tue, 31 May 2005 09:17:09 GMT  
 Strange behavior when subclassing a static control in modal dialog
Not surprising. Do you know what "static" means? It means "DOES NOT RESPOND TO USER
INPUT". Now, in later versions of Windows that has been modified somewhat; you can set the
SS_NOTIFY flag. So that should solve your problem.

You should not need SubclassDlgItem at all. Just create a member variable of your subclass
in your modal dialog. If you already have
        CStatic c_MySpecialControl;
then jjust hand-edit it to be
        CMyStatic c_MySpecialControl;
read my essay on avoiding GetDlgItem. The same techniques apply here.

Quote:

>I have written a MFC program which uses a modal dialog window.
>There is a static control in the dialog window. In order to
>paint on this static control, I subclassed it by using
>CMyStatic::SubclassDlgItem() and defined a OnPaint() in
>CMyStatic. (CMyStatic is derived from CStatic.)  This works
>fine.  But when I want this subclassed static control to do
>something special when it is clicked, I add a OnLButtonDown()
>in CMyStatic. To my surprise, CMyStatic::OnLButtonDown() is not
>called when I clicked on the static control. Instead, the
>CMyDialog::OnLButtonDown() is called.  Why?

>Anybody can explain this for me?

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Tue, 31 May 2005 11:31:42 GMT  
 Strange behavior when subclassing a static control in modal dialog
Thank you, Joseph. Your reply helps a lot. But I still have something
I don't understand.

I have defined a virtual function CMyStatic::WindowProc() which
overrides CWnd::WindowProc(). In MFC, this means all the messages
sent to the static control I subclassed will be received by
CMyStatic::WindowProc(). I use some if-statement in it to check what
messages it receives. It do receive WM_PAINT, but it don't receive
WM_LBUTTIODOWN when I click on the static control. That's what
really surprised me.

I know "static" means "DOES NOT RESPOND TO USER INPUT". I think it
behaves like that because its WndProc simply ignores messages related
to user input. But in fact I found that the WndProc doesn't receive
WM_LBUTTONDOWN at all. That's strange.

Any inspirations?



--

Quote:
>Not surprising. Do you know what "static" means? It means "DOES NOT RESPOND TO USER
>INPUT". Now, in later versions of Windows that has been modified somewhat; you can set the
>SS_NOTIFY flag. So that should solve your problem.

>You should not need SubclassDlgItem at all. Just create a member variable of your subclass
>in your modal dialog. If you already have
>    CStatic c_MySpecialControl;
>then jjust hand-edit it to be
>    CMyStatic c_MySpecialControl;
>read my essay on avoiding GetDlgItem. The same techniques apply here.


>>I have written a MFC program which uses a modal dialog window.
>>There is a static control in the dialog window. In order to
>>paint on this static control, I subclassed it by using
>>CMyStatic::SubclassDlgItem() and defined a OnPaint() in
>>CMyStatic. (CMyStatic is derived from CStatic.)  This works
>>fine.  But when I want this subclassed static control to do
>>something special when it is clicked, I add a OnLButtonDown()
>>in CMyStatic. To my surprise, CMyStatic::OnLButtonDown() is not
>>called when I clicked on the static control. Instead, the
>>CMyDialog::OnLButtonDown() is called.  Why?

>>Anybody can explain this for me?

>Joseph M. Newcomer [MVP]

>Web: http://www3.pgh.net/~newcomer
>MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Wed, 01 Jun 2005 10:42:57 GMT  
 Strange behavior when subclassing a static control in modal dialog

Quote:
> I have defined a virtual function CMyStatic::WindowProc() which
> overrides CWnd::WindowProc(). In MFC, this means all the messages
> sent to the static control I subclassed will be received by
> CMyStatic::WindowProc(). I use some if-statement in it to check what
> messages it receives. It do receive WM_PAINT, but it don't receive
> WM_LBUTTIODOWN when I click on the static control. That's what
> really surprised me.

> I know "static" means "DOES NOT RESPOND TO USER INPUT". I think it
> behaves like that because its WndProc simply ignores messages related
> to user input. But in fact I found that the WndProc doesn't receive
> WM_LBUTTONDOWN at all. That's strange.

> Any inspirations?

See the "Static Control Default Message Processing" subheading at the
following URL...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shel...

...Under the WM_NCHITTEST message entry we find that the control,
"...Returns HTCLIENT if the control style is SS_NOTIFY; otherwise,
returns HTTRANSPARENT".

--
Jeff Partch [VC++ MVP]



Wed, 01 Jun 2005 12:42:48 GMT  
 Strange behavior when subclassing a static control in modal dialog
Thank you very much.  I got it.


--

Quote:


>> I have defined a virtual function CMyStatic::WindowProc() which
>> overrides CWnd::WindowProc(). In MFC, this means all the messages
>> sent to the static control I subclassed will be received by
>> CMyStatic::WindowProc(). I use some if-statement in it to check what
>> messages it receives. It do receive WM_PAINT, but it don't receive
>> WM_LBUTTIODOWN when I click on the static control. That's what
>> really surprised me.

>> I know "static" means "DOES NOT RESPOND TO USER INPUT". I think it
>> behaves like that because its WndProc simply ignores messages related
>> to user input. But in fact I found that the WndProc doesn't receive
>> WM_LBUTTONDOWN at all. That's strange.

>> Any inspirations?

>See the "Static Control Default Message Processing" subheading at the
>following URL...

>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shel...

>...Under the WM_NCHITTEST message entry we find that the control,
>"...Returns HTCLIENT if the control style is SS_NOTIFY; otherwise,
>returns HTTRANSPARENT".



Wed, 01 Jun 2005 13:34:44 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Modal Dialog Box behavior

2. modal property sheet looses modal behavior after error message

3. Strange Modeless Dialog Behavior

4. Strange behavior of my dialog, or ocx??

5. Strange ATL Button Control Behavior

6. Strange behavior of Access as control host

7. Q: Change bkcolor fo control : strange behavior???

8. Strange - tab stop navigation disabled on modal dialog

9. Strange modal dialog problem

10. Strange - tab stop navigation disabled on modal dialog

11. Subclassing run-time created static control

12. modal dialogs on top of modal dialogs...

 

 
Powered by phpBB® Forum Software