Non-static member functions are used for window (non- ing table implementation), and member functions are used for message ing.

Source: Internet
Author: User

Previously, the principle of mfc was to map the class pointer to the window handle;

After several versions are implemented, I always think that it is a waste of elegance to search for ing tables, especially when there are many windows, for example, a large number of subclass win32 controls are often used;

 

Therefore, the window USERDATA has the following implementation versions:

Class XWindow
{
Protected:
Static lresult callback WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
XWindow * pWindow;

If (WM_NCCREATE = uMsg)
{
MDICREATESTRUCT * pMDIC = (MDICREATESTRUCT *) (LPCREATESTRUCT) lParam)-> lpCreateParams;

PWindow = (XWindow *) (pMDIC-> lParam );
: SetWindowLong (hWnd, GWL_USERDATA, (LONG) pWindow );
}
Else
{
PWindow = (XWindow *): GetWindowLong (hWnd, GWL_USERDATA );
}

If (NULL! = PWindow)
{
Return pWindow-> WndProc (hWnd, uMsg, wParam, lParam );
}
Else
{
Return: DefWindowProc (hWnd, uMsg, wParam, lParam );
}
}

Virtual LRESULT WndProcSelf (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// This is self wndproc
}

Virtual HWND CreateEx (DWORD dwExStyle,
LPCTSTR lpszClass,
LPCTSTR lpszName,
DWORD dwStyle,
Int x, int y,
Int nWidth, int nHeight,
HWND hParent,
HMENU hMenu,
HINSTANCE hInst)
{
MDICREATESTRUCT mdic;
Memset (& mdic, 0, sizeof (mdic ));
Mdic. lParam = (LPARAM) this;

Return createmediawex (dwExStyle,
LpszClass,
LpszName,
DwStyle,
X, y,
NWidth, nHeight,
HParent,
HMenu,
HInst,
& Mdic );
}

Private:
HWND m_hWnd;
};

 

In this way, message ing is so easy. You can add ing in the static window or ing in the member window;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.