The PreCreateWindow Member Function

PreCreateWindow, declared at the CWnd level, is another virtual function that you can override to change the characteristics of your window before it is displayed. The framework calls this function before it calls ActivateFrame. AppWizard always generates an overridden PreCreateWindow function in your project's view and frame window classes.

This function has a CREATESTRUCT structure as a parameter, and two of the data members in this structure are style and dwExStyle. You can change these data members before passing the structure on to the base class PreCreateWindow function. The style flag determines whether the window has a border, scroll bars, a minimize box, and so on. The dwExStyle flag controls other characteristics, such as always-on-top status. See the online documentation for Window Styles and Extended Window Styles for details.

The CREATESTRUCT member lpszClass is also useful to change the window's background brush, cursor, or icon. It makes no sense to change the brush or cursor in a frame window because the view window covers the client area. If you want an ugly red view window with a special cursor, for example, you can override your view's PreCreateWindow function like this:

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs) {     if (!CView::PreCreateWindow(cs)) {         return FALSE;     }     cs.lpszClass =         AfxRegisterWndClass(CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW,                             AfxGetApp()->LoadCursor(IDC_MYCURSOR),                             ::CreateSolidBrush(RGB(255, 0, 0)));     if (cs.lpszClass != NULL) {         return TRUE;     }     else {         return FALSE;     } }

If you override the PreCreateWindow function in your persistent frame class, windows of all derived classes will share the characteristics you programmed in the base class. Of course, derived classes can have their own overridden PreCreateWindow functions, but then you'll have to be careful about the interaction between the base class and derived class functions.



Programming Visual C++
Advanced 3ds max 5 Modeling & Animating
ISBN: 1572318570
EAN: 2147483647
Year: 1997
Pages: 331
Authors: Boris Kulagin

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net