Tutorials

 

Home
About
How it Works
Documentation
Tutorials

Examples

Links
Contact

 

 

Menu of tutorials

Tutorial 1:   The Simplest Window
Tutorial 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: Print Previewing
Tutorial 11: 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 "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.