Windows objects are not the "class objects" in the "face objects" programming we usually call, but a Windows resource entity, such as a paint brush or font,
We use handles to identify these windows objects.
C ++ objects are the "class objects" in the true "Object-Oriented" thinking ".
In Windows programming, apart from common "class objects, the most commonly used "C ++ Class Object" should be an MFC object (if you are programming with MFC ), an MFC object is a C ++ object that encapsulates windows objects ".
Taking the cwnd class as an example, after we define the object mywnd of a cwnd class, we cannot directly perform operations such as display and movement (equivalent to not using it) on it. Why? Because we haven't encapsulated a corresponding Windows Object for it (Note: The cwnd class has a member variable hwnd m_hwnd), so we need to call the member function create (). The create () function is to create a Windows window class instance (it is also a windows object, we also use a handle to identify it, here we use the hwnd type handle) link the handle of the window instance to the member variable m_hwnd of the cwnd class object ).
Of course, it is troublesome to use the CREATE () function to implement the function, but it gives us a clearer understanding of this process:
Cwnd mywnd; // defines the object of a window class (cwnd)
Hwnd; // defines the window handle hwnd
Hwnd = createwindows (......); // Call the API function createwindows (......) Create a Windows window instance, return a handle, and assign the handle to the hwnd handle.
Mywnd. Attach (hwnd); // link the handle of the window instance to the cwnd object mywnd.
......
Destrory window (hwnd );
As many people do not know the details, when learning MFC windows programming, they always cannot figure out why so many initialization and other functions need to be called to create an MFC class object, to call other functions. However, after creating a C ++ object, we can always directly call its member functions.
Windows Object is a Windows operating system object represented by a handle in Win32, and MFC object is a C ++ object, is a C ++ class instance.
An MFC window object is an instance of a C ++ cwnd class (or a derived class) and is directly created by a program. During program execution, it is generated with the call of window class constructor, and disappears with the call of the destructor. Windows is an instance of an internal data structure in windows. It is identified by a "window handle". Windows creates it and allocates system resources to it. After an MFC window object is created in Windows, it is created by the create member function of the cwnd class. The "window handle" is saved in the m_hwnd member variable of the window object. A Windows window can be destroyed by a program or a user action.
The creation of the MFC window is different from that of the windwos window. The MFC object is directly created by the program through the constructor; the windows object is created by the corresponding SDK function.
The following two steps are generally taken to use these MFC objects in MFC:
1. Create an MFC object, create it in the stack, or create it in heap. In this case, the variable of the MFC object handle instance is empty, or is not a valid handle.
2. Call the MFC object member function to create a corresponding windows object. The MFC handle variable stores a valid handle.
Of course, you can create the corresponding windows object in the MFC object constructor. the GDI class of MFC is implemented in this way, but in essence, the creation of an MFC object is different from that of a Windows Object.
Whether the properties of Windows windows are not in its status, there is basically no difference between the two. setwindowtext (...), seticon (...), setmenu (...), the window object only has a handle parameter.
What else do you ask is the difference between the C ++ object and the windows object. I think the C ++ object here should refer to the MFC object.