Hwnd is an identifier for all windows in windows, that is, the window handle. This is an SDK concept.
Cwnd is the base class of all window classes in the MFC class library. In MFC, Microsoft encapsulates all common window operations in this class, such as showwindow. At the same time, it also encapsulates the window handle, namely the m_hwnd member.
Obtain cwnd * From hwnd *:
Cwnd WND;
Hwnd;
WND. Attach (hwnd );
A window resource is usually associated with a cwnd Class Object. Since this class is generally created by itself, you naturally know how to get a pointer to this class. If not, create a cwnd object and associate it with the hwnd handle of the window resource. (For example, the preceding statement ). If you use
Static cwnd * cwnd: fromhandle (hwnd );
The returned value is a temporary cwnd object, and we ensure that the returned value is not null, that is, hwnd is valid.
Static cwnd * cwnd: fromhandlepermanent (hwnd );
A permanent object is returned. The returned value is not empty only when the returned cwnd already exists in the class table.
Obtaining hwnd from cwnd is much easier, because one of its members m_hwnd is the handle of the corresponding window.
WND-> m_hwnd.
----------------------------------------------------------
Cwnd * differs greatly from hwnd
Hwnd is a type defined by the SDK and a 32-bit value without definite meaning. It is used to refer to the form when calling an API.
Cwnd * is an exact pointer pointing to an MFC form-class cwnd instance. Because MFC encapsulates the SDK, most calls can use cwnd * as the parameter, so it is easy to confuse. The method for obtaining a handle from a cwnd * Is pwnd-> getsafehwnd (), which is safer than pwnd-> m_hwnd because the former returns NULL when pwnd = NULL, and the latter returns access violation.
Conversion from hwnd to cwnd * a usable method is cwnd: fromhandle.
Cwnd * ptempwnd = cwnd: fromhandle (hwnd); // If hwnd has a corresponding cwnd *, its pointer is returned. Otherwise, a temporary MFC form is created and its pointer is returned.
Note that this function will return a pointer to the temporary form. If you need to be safer, call cwnd: fromhandlepermanent and return NULL if the corresponding cwnd * does not exist.
----------------------------------------------------------
Cwnd is the basic window class of MFC. Hwnd is the Windows window handle. The former is a C ++ object, and the latter is a numeric object similar to a pointer address.
Cwnd can be regarded as an encapsulation of Windows window operations, and the core of the encapsulation is to use Windows window handles (that is, hwnd) to operate windows.
Cwnd can use cwnd: getsafehwnd () or the member variable m_hwnd to obtain the hwnd window handle of the window object.
Hwnd can instantiate a cwnd object through the static function: cwnd: fromhandle () of cwnd.
----------------------------------------------------------
1: SDK Functions
Definition
Hwnd getdlgitem (hwnd hdlg, int niddlgitem );
Parameters
Hdlg
Specify the window handle of the dialog box.
Niddlgitem
The identifier (ID) of the control ).
Return Value
If the function is successfully called, the return value is the window handle of the specified control. If the function call fails, the return value is null, indicating that the dialog box handle is invalid or the specified control does not exist. To obtain more error information, call the getlasterror function.
Description
When using this function, you can specify any window, not just a dialog box window, if hdlg specifies a parent window and the Child Window has an identifier (set by the hmenu parameter when the createwindow or createmediawex function is called to create a child window), getdlgitem returns a valid Child Window handle.
For example: (the call method is as follows, and the two parameters are called in the Platform SDK)
: Getdlgitem (this-> m_hwnd, idc_xxxx_size); // This-> m_hwnd refers to the handle of a window, and idc_xxx_size refers to the ID of a control to be operated.
2: class member functions
Definition
Cwnd: getdlgitem (int nid)
Example: (cwnd: getdlgitem (int nid) called in the window)
Getdlgitem (idc_v1)-> showwindow (sw_hide );
Getdlgitem (idc_v2)-> showwindow (sw_hide );
Getdlgitem (idc_v3)-> showwindow (sw_hide );