Shaikh Sonny Aman’s Blog

previously www.mailtoaman.com

Why calling SetWindowText in PreSubclassWindow does not work for a Dialog

Posted on | August 5, 2007 |

The OnInitDialog() follows the PreSubClassWindow(). So any initialization done in PreSubClassWindow() will be overwritten by the initializations that take place in OnInitDialog().

For this, say we called SetWindowText(L” My Dialog”) in PreSubClassWindow(). After a while when OnInitDialog() is being processed, a call to SetWindowText is called with the Caption which can be set using the VS dialog editor.

Another point I would like to mention in this regard.

In normal window handling, we will have an OnCreate handler that is invoked just as the window is created. In normal MFC window handling, we have the PreCreateWindow virtual method which lets us change the CREATESTRUCT values, such as style parameters.

These are not accessible in dialogs. The reason is that the members of the subclass can be invoked only when the window is mapped into MFC, that is, its handler has been changed to be the AfxWnd handler. But dialog controls are created long before the subclassing, which takes place on the first DoDataExchange handler, which happens during the OnInitDialog processing. This is far too late.

PreSubclassWindow is an ideal place to make certain modifications, such as changing styles. This applies only to those styles which have an effect after the window has been created (many styles cannot be changed once the window is created. We can change the style bits( as like as calling SetWindowText as discussed above ), but the window itself is oblivious to these changes).

This is useful when the styles you want to change are not part of the styles presented by the dialog editor.

Comments

2 Responses to “Why calling SetWindowText in PreSubclassWindow does not work for a Dialog”

  1. noob
    April 6th, 2008 @ 9:36 am

    No freaking way. I’m absolutely disagreeing. Next time when you post something think about reaction of readers.

  2. hdw
    April 9th, 2008 @ 2:45 am

    Your blog make me chuckle from beginning to end^_^!! It sounds absolutely great to me. Your blog is my favorite!

Leave a Reply