Shaikh Sonny Aman’s Blog

Lets learn and share!

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

Leave a Reply