Tutorials
|
|
Menu of tutorialsTutorial 1: The Simplest Window
Tutorial 6: Customising Window CreationUp until now we have used the default parameters supplied by Win32++ to create the view window. Here we use the PreRegisterClass to specify the Window Class (not to be confused with a C++ class) parameters prior to window creation. This will allow us to create a window with a colored background and set it's cursor. void CView::PreRegisterClass(WNDCLASS &wc) { // Set the background brush and cursor. wc.hbrBackground = m_brush; wc.lpszClassName = "Scribble Window"; wc.hCursor = GetApp()->LoadCursor(IDC_CURSOR1); } We also use PreCreate to give the window a 3D look by giving it's border a sunken edge. void CView::PreCreate(CREATESTRUCT &cs) { // Set the extra style to provide a sunken edge. cs.dwExStyle = WS_EX_CLIENTEDGE; } The cursor IDC_CURSOR1 used in PreRegisterClass is specified in resource.rc. The resource.rc file is our resource script and contains the specifications for various window resources such as bitmaps, dialogs, cursors, icons, menus etc. The resources specified in resource.rc are compiled and linked into our application. This is the specification for the cursor in the resource.rc file. ///////////////////////////////////////////////////////////////////////////// // // Cursor // IDC_CURSOR1 CURSOR "res/Cursor.cur" We create the background brush in CView's constructor. The brush is a CBrush object that automatically deletes its brush when its destructor is called. This is how the brush is created. // Constructor. CView::CView() : m_penColor(RGB(0,0,0)) { m_brush.CreateSolidBrush(RGB(255,255,230)); } The source code for this tutorial is located within the Tutorial folder of the software available from SourceForge at http://sourceforge.net/projects/win32-framework. |