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 "wxx_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 WINAPI 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
CWinApp
object called myApp.
- Create a
CMyWindow
object called myWindow.
- Create a default window by calling the Create function.
- Start the message loop, by calling the Run function.
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.
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.