|
Tutorials |
Menu of tutorials
Tutorial 1: The Simplest
WindowTutorial 2: Using Classes and
Inheritance
Tutorial 3: Using Messages to Create a
Scribble Window
Tutorial 4: Repainting the
Window
Tutorial 5: Wrapping a Frame around
our Scribble Window
Tutorial 6: Customising Window
Creation
Tutorial 7: Customising the
ToolBar
Tutorial 8: Loading and Saving
Files
Tutorial 9: Printing
Tutorial 10: Finishing Touches
Tutorial 1: The Simplest Window
The following code uses Win32++ to create a window. This is all the code you need (in combination with Win32++) to create and display a simple window. Note that in order to add the Win32++ code to our program, we use an #include statement as shown below.
#include "wincore.h"
// Note:
// * Add the Win32++\include directory to project's additional include directories
// A class that inherits from CWnd. It is used to create the window.
class CMyWindow : public CWnd
{
public:
CMyWindow() {}
virtual void OnDestroy() { PostQuitMessage(0); } // Ends the program
virtual ~CMyWindow() {}
};
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
// Start Win32++
CWinApp MyApp;
// Create a CMyWindow object
CMyWindow MyWindow;
// Create (and display) the window
MyWindow.Create();
// Run the application's message loop
return MyApp.Run();
}
This program has four key steps:
- Start Win32++. We do this here by creating a
CWinAppobject called MyApp. - Create a
CMyWindowobject called MyWindow. - Create a default window by calling the Create function.
- Start the message loop, by calling the Run function.
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.
The
CMyWindow class inherits from CWnd. CWnd is the base class for all
objects used to create windows. We override the OnDestroy function of CWnd
to end the program when the window is closed.