Skip to main content

CObject, the Ancestor of All/Most MFC Classes

To implement its functionality, the MFC is organized as a hierarchical tree of classes, the ancestor of which is CObject:
CObject
Although you can create C++ classes for your applications, most of the classes you will use throughout our lessons descend directly or indirectly from CObject.
The CObject class lays a valuable foundation that other classes can build on. Using the rules of inheritance, the functionality of CObject can be transparently applied to other classes as we will learn little by little. Some of the features that CObject provides are:
  • Performing value streaming for saving or opening the contents of files
  • Controlling dynamic creation and destruction of its inherited classes
  • Checking the validity of variables of classes, etc
You will hardly use CObject directly in your program. Instead, you may create your own classes that are based on CObject. Here is an example:
class CCar : public CObject
{
public:
    CCar();
    char *Make;
    char *Model;
    int Year;
    long Mileage;
    int Doors;
    double Price;
};


  1. To make sure that this application uses MFC, on the main menu, click Project -> Properties...
  2. In the left list, click Configuration Properties
  3. In the right list, click User of MFC, click the arrow of its combo box and select Use MFC In A Shared DLL
    Property Pages
  4. Click OK

Comments

Popular posts from this blog

Creating a File

Although the most popular files used in Microsoft Visual C++ are header and source files, this IDE allows you to create various other types of files that are not natively C++ types. To create a file, if a project is currently opened: On the main menu, click Project -> Add New Item... This would open the New dialog box from where you can select the desired type of file and click Open. By default, the new file would open in the Source Code Editor. If you want to open the file otherwise, after selecting it in the New dialog box, click the arrow of the Open As combo box. In the Solution Explorer or the Class View, right- click the name of the project, position the mouse of Add, and click the option you want

Introduction to Win32

Win32 is a library made of data types, variables, constants, functions, and classes (mostly structures) that can be used to create applications for the Microsoft Windows family of operating systems. A typical application is made of at least two objects: a control and a host object on which the control is positioned. To create a Win32 application using Microsoft Visual C++: On the Start Page, you can click New Project On the main menu, you can click File -> New Project... On the Standard toolbar, you can click the New Project button You can press Ctrl + N Any of these actions would display the New Project dialog box. From there, select Win32 Project item. Just like a C++ program always has a main() function, a Win32 program uses a central function called WinMain . The syntax of that function is: INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ); To support international characters, Microsoft Windows provides anot...

Adding Existing Files to a Project

If a file had already been created and exists on a separate folder, drive, directory or project, you can import it and add it to your application. When you decide to add an existing file to a project, because Microsoft Visual Studio allows you a great level of flexibility on the types of files you can add, it is your responsibility to check that the file is valid. If you copy a file from somewhere and paste it in the folder that contains your project, the file is still not considered as part of the project. You must explicitly add it. Before adding an existing file to your project: On the main menu, you can click File -> Add Existing Itemテδ「テ「窶堋ャテつヲ On the main menu, you can also click Project -> Add Existing Itemテδ「テ「窶堋ャテつヲ In the Solution Explorer, you can right-click the name of the project, position your mouse on Add and click Add Existing Itemテδ「テ「窶堋ャテつヲ Any of these actions would open the Add Existing Item dialog box. This requires you to locate the item and select it. O...