CDialogBase MFC dialog base class

Based on the dialog base class abstracted from message mapping, business development only needs to inherit this class. This parent class can already meet a large number of business scenarios. For example, creating a modal dialog box or a non-modal dialog box, etc., is only encapsulated.

#pragma once
#include "common.h"

/****************************************************** ************************/
/*
\t
Based on the base class of all MFC dialog boxes provided by the business, developers no longer inherit the MFC dialog class when defining a new window class, but only inherit CDialogBase.

::LoadString() replaces the displayed string
When writing international applications, it is often necessary to use strings in different languages. For example, it is called "File" in the Chinese menu, but it is called "File" in English. The function of developing this kind of software is the same, but the text displayed on the interface is different.
In order to facilitate the development of this kind of software, a commonly used method in Windows is to replace the displayed string. For example, if you specify "File" in Chinese, it will display "File" in English.
This is achieved by loading different string displays from different resources through the function LoadString. In fact, all variable strings can be displayed using the function LoadString to load strings from resources.

::LoadIcon() Function to change the icon
Image information is very convenient for people to remember. Just like traffic signals, various icons are used. Everyone will understand what they are after seeing them. Therefore, icons are used in programs to identify programs.
As long as you see this icon, you will know what this software is used for. For example, the icon displayed in the upper left corner of the program needs to call the function LoadIcon to load it from the resource into the memory and then display it.
\t
::LoadCursor() function to replace the cursor
The cursor is the most commonly used icon and can be seen all the time. When you are editing a file, the cursor appears as an "I" icon.
When you operate a file on the desktop, it appears as an arrow. The cursor changes like this because different icons are set. The use of the cursor is to give different instructions according to different areas.



*/
/****************************************************** ************************/




class CDialogBase;

typedef LRESULT(CDialogBase::* pMapFn)(WPARAM wParam, LPARAM lParam);

//Window message table entry
struct WND_DLG_MSGMAP_ENTRY
{<!-- -->

pMapFn m_pfn;
UINT m_nMessage;
UINT m_nID;
WND_DLG_MSGMAP_ENTRY(UINT uMsg,pMapFn pfn) : m_nMessage(uMsg), m_pfn(pfn), m_nID(0) {<!-- -->}
WND_DLG_MSGMAP_ENTRY(UINT uMsg, UINT nID, pMapFn pfn) : m_nMessage(uMsg), m_nID(nID), m_pfn(pfn) {<!-- -->}
};


//Window message table
struct WND_DLG_MSGMAP
{<!-- -->
const WND_DLG_MSGMAP* (*pfnGetBaseMap)();
const WND_DLG_MSGMAP_ENTRY* lpEntries;
};

#ifndef dlg_msg
#define dlg_msg
#endif


//Define message mapping macro
#define DECLARE_DLG_MESSAGE_MAP() \
protected: \
static const WND_DLG_MSGMAP* GetThisMessageMap(); \
virtual const WND_DLG_MSGMAP* GetMessageMap() const; \

#define BEGIN_DLG_MESSAGE_MAP(theClass, baseClass) \
const WND_DLG_MSGMAP* theClass::GetMessageMap() const \
{<!-- --> \
    return GetThisMessageMap(); \
} \
const WND_DLG_MSGMAP* theClass::GetThisMessageMap() \
{<!-- --> \
    typedef baseClass TheBaseClass; \
static const WND_DLG_MSGMAP_ENTRY _messageEntries[] = \
{<!-- --> \

#define ON_DLG_MESSAGE(message, memberFxn) \
WND_DLG_MSGMAP_ENTRY(message, static_cast< LRESULT (CDialogBase::*)(WPARAM, LPARAM) >(memberFxn)),

#define ON_DLG_COMMAND(_id, memberFxn) \
WND_DLG_MSGMAP_ENTRY(WM_COMMAND, _id, static_cast< LRESULT (CDialogBase::*)(WPARAM, LPARAM) >(memberFxn)),

#define END_DLG_MESSAGE_MAP() WND_DLG_MSGMAP_ENTRY(0, NULL) }; \
static const WND_DLG_MSGMAP messageMap = \
{<!-- --> & amp;TheBaseClass::GetThisMessageMap , & amp;_messageEntries[0] }; \
return &messageMap; \
} \

#define DECLARE_DLG_BASE_MESSAGE_MAP() \
protected: \
static const WND_DLG_MSGMAP* GetThisMessageMap(); \
virtual const WND_DLG_MSGMAP* GetMessageMap() const; \
static const WND_DLG_MSGMAP* GetBaseMessageMap(); \

#define BEGIN_DLG_BASE_MESSAGE_MAP(theClass) \
typedef theClass TheThisClass; \
const WND_DLG_MSGMAP* TheThisClass::GetMessageMap() const \
{<!-- --> \
    return GetThisMessageMap(); \
} \
const WND_DLG_MSGMAP* TheThisClass::GetBaseMessageMap() \
{<!-- --> \
    return NULL; \
} \
const WND_DLG_MSGMAP* TheThisClass::GetThisMessageMap() \
{<!-- --> \
static const WND_DLG_MSGMAP_ENTRY _messageEntries[] = \
{<!-- --> \

#define END_DLG_BASE_MESSAGE_MAP() WND_DLG_MSGMAP_ENTRY(0, NULL) }; \
static const WND_DLG_MSGMAP messageMap = \
{<!-- --> & amp;TheThisClass::GetBaseMessageMap, & amp;_messageEntries[0] }; \
return &messageMap; \
} \



//Dialog base class
class CDialogBase
{<!-- -->
public:

//Construction and destruction
CDialogBase();

~CDialogBase();

//Create a modal window
dlg_msg INT_PTR DoModal
(
\t\t/*Input parameters*/
HWND hWndParent, /*Handle of the parent window*/
bool bCenter = true /*Whether it is centered*/
);
dlg_msg INT_PTR DoModal
(
\t\t/*Input parameters*/
UINT resourceID, /*Window UI resource ID*/
HWND hWndParent, /*Parent window handle*/
bool bCenter = true /*Whether the window is displayed in the center*/
);
dlg_msg INT_PTR DoModalEx
(
\t\t/*Input parameters*/
UINT resourceID, /*Window UI resource ID*/
HWND hWndParent, /*Parent window handle*/
BOOL isShow = TRUE, /*Whether to display the window, the default display*/
bool bCenter = true /*The window position is centered. The default is centered*/
);

//Create a non-modal window
dlg_msg HWND DoDialog
(
\t\t/*Input parameters*/
UINT resourceID, /*Window UI resource ID*/
HWND hWndParent,/*Parent window handle*/
BOOL isShow = TRUE, /*Whether to display the window, the default display*/
bool bCenter = true /*The window position is centered. The default is centered*/
);

\t//close the window
dlg_msg LRESULT OnClose(WPARAM wParam, LPARAM lParam);

//Modify window dialect
dlg_msg LRESULT OnLanguageChange(WPARAM wParam, LPARAM lParam);




//Set UI resource ID
VOID SetResourceID
(
\t\t/*Input parameters*/
UINT resourceID /*To set the resource ID*/
);

//Set language ID
VOID SetLanguageID
(
\t\t/*Input parameters*/
LANGID langID /*Language ID to be set*/
);


//display window
VOID ShowWindow(
\t\t/*Input parameters*/
int cmdShow = SW_SHOW /* Determines how to display the window. The default is to activate the window and display the window at the current size and position. */
);

//Check whether the window is visible
BOOL IsVisible() const;


//To move the dialog box to the middle, you need to tell its parent window which dialog box it is based on.
VOID MoveToCenter
\t(\t/*Input parameters*/
HWND hParent = NULL /*Change the dialog box and the handle of the parent window*/
);


//Load string text based on resource ID
_tstring _LoadString
(
\t\t/*Input parameters*/
UINT uID /*resource ID*/
);

//Check the title or text associated with the control in the dialog box
_tstring GetItemString
(
\t\t/*Input parameters*/
DWORD dwID /*Control ID*/
);

//Set the title or text associated with the controls in the dialog box
void SetItemString
(
\t\t/*Input parameters*/
DWORD dwID, /*Control ID*/
const _tstring strText /*To set the text or title of the control*/
);

//Modify the title of the window menu item
VOID ModifyMenuText
(
HMENU hMnu,/*menu handle (menu contains menu items)*/
UINT uPosition, /*You want to modify the position or identifier of the menu item. The meaning of this parameter depends on the value of fByPosition*/
LPCTSTR lpNewItem,/*What text title should be modified*/
BOOL fByPos = TRUE
);

VOID ModifyMenuText
(
\t\t/*Input parameters*/
HMENU hMnu,/*menu handle (menu contains menu items)*/
UINT uPosition,/*You want to modify the position or identifier of the menu item. The meaning of this parameter depends on the value of fByPosition*/
UINT resourceID, /*can be a resource ID to handle international scenarios*/
BOOL fByPos = TRUE
);

//Check the handle of the window
HWND GetWndHandle() const;

//End kill window
bool EndDialog(INT_PTR nResult);

//To the window, directly deliver the message
BOOL _PostMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);

//Send message to window
LRESULT _SendMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);

//When forced transfer occurs, return the underlying window handle of this window class.
operator HWND() const
{<!-- -->
return m_hWnd;
}

protected:

//window processing function
static INT_PTR WINAPI DialogProc
(
/*Callback parameters*/
HWND hWnd, /*The window handle currently entering the callback*/
UINT uMsg, /*Message that triggers the window processing function*/
WPARAM wParam, /*wParam data carried in the message*/
LPARAM lParam /*lParam data carried in the message*/
);

INT_PTR DialogProc
(
/*Callback parameters*/
UINT uMsg, /*Message that triggers the window processing function*/
WPARAM wParam, /*wParam data carried in the message*/
LPARAM lParam /*lParam data carried in the message*/
);

//Fake modal dialog box
dlg_msg LRESULT DoFakeModal
\t(\t/*Input parameters*/
UINT resourceID, /*window resource ID*/
HWND hWndParent, /*Parent window handle*/
BOOL isShow = TRUE /*Whether to display the window, displayed by default*/
);



//Virtual function, extended by subclasses
virtual BOOL PreTranslateMessage(LPMSG pMsg);


protected:
HWND m_hWnd;//window handle
UINT m_resID; //Window UI resource ID
LANGID m_LangId;//Window language ID
BOOL m_isModel;//Is this window a modal box? TRUE-yes FALSE-no
BOOL m_isFakeModel; //Is this window a fake modal window? TRUE-Yes FALSE-No
BOOL m_isCenter; //Is this window centered?

//Declare message mapping macro
DECLARE_DLG_BASE_MESSAGE_MAP()
};

</code><img class="look-more-preCode contentImg-no-view" src="//i2.wp.com/csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack. png" alt="" title="">
#include "StdAfx.h"
#include "CDialogBase.hpp"

#pragma comment(linker,""/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*\ ' publicKeyToken='6595b64144ccf1df' language='*'"")

BEGIN_DLG_BASE_MESSAGE_MAP(CDialogBase)
    ON_DLG_MESSAGE(WM_CLOSE, & amp;CDialogBase::OnClose) //If the user sends a WM_CLOSE message, it will be processed by the callback OnClose method.
END_DLG_BASE_MESSAGE_MAP()

CDialogBase::CDialogBase()
{<!-- -->
    m_hWnd = NULL;
    m_resID = 0;
    m_LangId = 0;
    m_isModel = FALSE;
    m_isFakeModel = FALSE;
    m_isCenter = FALSE;
}

CDialogBase::~CDialogBase()
{<!-- -->
    if (NULL != m_hWnd)
    {<!-- -->
        ::DestroyWindow(m_hWnd); m_hWnd = NULL;
    }
}

INT_PTR CDialogBase::DoModal(HWND hWndParent, bool bCenter/* = true*/)
{<!-- -->
    m_isCenter = bCenter;
    m_isModel = TRUE;

    //Create a modal dialog box from the dialog box template resource.
    return ::DialogBoxParam
    (
        GetModuleHandle(NULL), //Handle of the module containing the dialog box template
        MAKEINTRESOURCE(m_resID),//Dialog template.
        hWndParent, //Handle of the window that owns the dialog box
        DialogProc, //Pointer to the dialog box procedure
        (LPARAM)this //The value to be passed to the dialog box in the lParam parameter of the WM_INITDIALOG message
    );
}

 INT_PTR CDialogBase::DoModal(UINT resourceID, HWND hWndParent, bool bCenter/* = true*/)
{<!-- -->
     m_isCenter = bCenter;
     m_resID = resourceID;
     m_isModel = TRUE;

     return ::DialogBoxParam
     (
         GetModuleHandle(NULL),
         MAKEINTRESOURCE(m_resID),
         hWndParent,
         DialogProc,
         (LPARAM)this
     );
}

 dlg_msg INT_PTR CDialogBase::DoModalEx(UINT resourceID, HWND hWndParent, BOOL isShow, bool bCenter)
 {<!-- -->
     m_isCenter = bCenter;
     m_isModel = FALSE;
     return DoFakeModal(resourceID, hWndParent, isShow);
 }

 dlg_msg HWND CDialogBase::DoDialog(UINT resourceID, HWND hWndParent, BOOL isShow, bool bCenter)
 {<!-- -->
     m_isCenter = bCenter;
     m_isModel = FALSE;
     m_resID = resourceID;
     HWND hWnd = ::CreateDialogParam(GetModuleHandle(NULL),MAKEINTRESOURCE(resourceID), hWndParent, DialogProc,(LPARAM)this );
     m_hWnd = hWnd;
     
     if(isShow)
     {<!-- -->
         ::ShowWindow(m_hWnd,SW_SHOW);
     }

     return m_hWnd;
 }

 dlg_msg LRESULT CDialogBase::OnClose(WPARAM wParam, LPARAM lParam)
 {<!-- -->
     return EndDialog(wParam);
 }

 dlg_msg LRESULT CDialogBase::OnLanguageChange(WPARAM wParam, LPARAM lParam)
 {<!-- -->
     return TRUE;
 }

 dlg_msg LRESULT CDialogBase::DoFakeModal(UINT resourceID, HWND hWndParent, BOOL isShow)
 {<!-- -->
     m_isModel = FALSE;
     m_resID = resourceID;
     m_isFakeModel = TRUE;

     MSG msg = {<!-- --> 0 };
     BOOL bRet = NULL;
     TCHAR szBuf[MAX_PATH] = {<!-- --> 0}; //Message mechanism!

     //Create a modeless dialog box from the dialog template resource.
     m_hWnd = ::CreateDialogParam (GetModuleHandle(NULL),MAKEINTRESOURCE(resourceID),hWndParent,DialogProc,(LPARAM)this);

     //Failed to create window, terminate the process!
     if (NULL == m_hWnd)
     {<!-- -->
         return -1;
     }
   
     if(isShow)
     {<!-- -->
         ::ShowWindow(m_hWnd, SW_SHOW);
     }

     //Disable parent window
     HWND hParent = GetParent(m_hWnd);
     if(hParent)
     {<!-- -->
         ::EnableWindow(hParent, FALSE);
     }



     //If hWnd is NULL, GetMessage will retrieve messages for any windows belonging to the current thread, and any messages on the current thread's message queue for which hwnd has a NULL value.
     //So if hWnd is NULL, both window messages and thread messages are processed.
     //If hWnd is - 1, GetMessage only retrieves messages whose hwnd value is NULL in the message queue of the current thread.
     //That is, when the hWnd parameter is NULL or PostThreadMessage, the thread message published by PostMessage.
     while (0 != (bRet = ::GetMessage( & amp;msg, NULL, 0, 0)))
     {<!-- -->
         if (-1 == bRet)
         {<!-- -->
             break;
         }

         //Preprocess the message and leave a hook for subclasses to intervene in this message processing process.
         if (PreTranslateMessage( & amp;msg))
         {<!-- -->
             continue;
         }

         //Class capture message processing and dialog box TAB key processing
         if (::IsDialogMessage(m_hWnd, & amp;msg))
         {<!-- -->
             continue;
         }

         ::TranslateMessage( & amp;msg);
         ::DispatchMessage( & amp;msg);
     }

     return msg.wParam;
 }

 VOID CDialogBase::SetResourceID(UINT resourceID)
 {<!-- -->
     m_resID = resourceID;
 }

 VOID CDialogBase::SetLanguageID(LANGID langID)
 {<!-- -->
     m_LangId = langID;
 }

 VOID CDialogBase::ShowWindow(int cmdShow)
 {<!-- -->
     ::ShowWindow(m_hWnd, cmdShow);
 }

 BOOL CDialogBase::IsVisible() const
 {<!-- -->
     return ::IsWindowVisible(m_hWnd);//Determine the visibility status of the specified window
 }

 VOID CDialogBase::MoveToCenter(HWND hParent /*= NULL*/)
 {<!-- -->
     RECT rectParent = {<!-- --> 0 }; //Parent window size
     RECT rectChild = {<!-- --> 0 }; // child window size
     RECT rectWork = {<!-- --> 0 }; //Display size

     LONG dwParentW = 0; //Width of parent window
     LONG dwParentH = 0; //Height of parent window

     LONG dwChildW = 0; //Width of child window
     LONG dwChildH = 0; //Height of child window

     LONG dwChildX = 0; //X component of the coordinates of the upper left corner of the subwindow
     LONG dwChildY = 0; //Y component of the coordinates of the upper left corner of the subwindow

     //Check the size of this window
     ::GetWindowRect(m_hWnd, & amp;rectChild);

     //Check the size of the monitor
     ::SystemParametersInfo(SPI_GETWORKAREA,0, & amp;rectWork, 0);

     //If the parent window is not specified, use the handle of the desktop window
     if (NULL == hParent)
     {<!-- -->
         hParent = ::GetDesktopWindow(); //Check the handle of the desktop window. The desktop window covers the entire screen.
     }

     //Check the size of the parent window
     ::GetWindowRect(hParent, & amp;rectParent);

     dwParentW = rectParent.right - rectParent.left;
     dwParentH = rectParent.bottom - rectParent.top;

     dwChildW = rectChild.right - rectChild.left;
     dwChildH = rectChild.bottom - rectChild.top;

    
     //The left corner point of the operator window
     dwChildX = rectParent.left + (dwParentW - dwChildW) / 2;
     dwChildY = rectParent.right + (dwParentH - dwChildH) / 2;


     //Handling of several illegal situations
     if (dwChildX < 0)
     {<!-- -->
         dwChildX = 0;
     }

     if (dwChildY < 0)
     {<!-- -->
         dwChildY = 0;
     }

     if ((dwChildX + dwChildW) > rectWork.right)
     {<!-- -->
         dwChildX = rectWork.right - dwChildW;
     }

     if ((dwChildY + dwChildH) > rectWork.bottom)
     {<!-- -->
         dwChildY = rectWork.bottom - dwChildH;
     }

     ::MoveWindow(
         m_hWnd,
         dwChildX,
         dwChildY,
         dwChildW,
         dwChildH,
         TRUE
     );

    
 }

 _tstring CDialogBase::_LoadString(UINT uID)
 {<!-- -->
     static TCHAR szBuf[1024] = {<!-- --> 0 };

     ::LoadString
     (
         ::GetModuleHandle(NULL),//Handle of EXE or DLL
         uID, //resource ID
         szBuf, //buffer
         _countof(szBuf) //Buffer size
     );
     return szBuf;
 }

 _tstring CDialogBase::GetItemString(DWORD dwID)
 {<!-- -->
     static TCHAR szBuf[1024] = {<!-- --> 0 };
     ::GetDlgItemText(m_hWnd, dwID, szBuf, _countof(szBuf));
     return szBuf;
 }

 void CDialogBase::SetItemString(DWORD dwID, const _tstring strText)
 {<!-- -->
     ::SetDlgItemText(m_hWnd, dwID, strText.c_str());
 }

 VOID CDialogBase::ModifyMenuText(HMENU hMnu, UINT uPosition, LPCTSTR lpNewItem, BOOL fByPos)
 {<!-- -->
     MENUITEMINFO mii = {<!-- --> 0 };
     TCHAR szBuf[MAX_PATH] = {<!-- --> 0 };
     mii.cbSize = sizeof(mii);
     mii.fMask = MIIM_TYPE | MIIM_STATE | MIIM_DATA;
     mii.fType = MFT_STRING;
     mii.dwTypeData = szBuf;
     mii.cch = _countof(szBuf);

     //Check menu item information
     ::GetMenuItemInfo(hMnu,uPosition,fByPos, & amp;mii);
     ::StringCchCopy(szBuf, _countof(szBuf), lpNewItem);
     
     //Set menu item information
     ::SetMenuItemInfo(hMnu, uPosition, fByPos, & amp;mii);

 }

 VOID CDialogBase::ModifyMenuText(HMENU hMnu, UINT uPosition, UINT resourceID, BOOL fByPos)
 {<!-- -->
     ModifyMenuText(hMnu, uPosition, _LoadString(resourceID).c_str(), fByPos);
 }

 HWND CDialogBase::GetWndHandle() const
 {<!-- -->
     if (::IsWindow(m_hWnd))
     {<!-- -->
         return m_hWnd;
     }
     return NULL;
 }

 bool CDialogBase::EndDialog(INT_PTR nResult)
 {<!-- -->
     //The window has not been created yet, so there is no need to kill the window. Process terminated!
     if (NULL == m_hWnd)
     {<!-- -->
         return FALSE;
     }

     //Check if it is a fake modal box
     if (m_isFakeModel)
     {<!-- -->
         //Enable parent window
         HWND hParent = ::GetParent(m_hWnd);
         if(hParent)
         {<!-- -->
             ::EnableWindow(hParent, TRUE);
         }
         // Post the WM_QUIT message to exit the message loop (when the window handle is specified as NULL,
         // This function behaves like a call to PostThreadMessage,
         //The dwThreadId parameter is set to the identifier of the current thread.
         ::PostMessage(NULL, WM_QUIT, nResult, 0);
     }

     //Check if it is a modal box
     if (m_isModel)
     {<!-- -->
         ::EndDialog(m_hWnd, nResult);
         m_hWnd = NULL;
     }
     else
     {<!-- -->
         ::DestroyWindow(m_hWnd);
         m_hWnd = NULL;
     }
     return TRUE;



 }

 BOOL CDialogBase::_PostMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
 {<!-- -->
     return ::PostMessage(m_hWnd, uMsg, wParam, lParam);
 }

 LRESULT CDialogBase::_SendMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
 {<!-- -->
     return ::SendMessage(m_hWnd, uMsg, wParam, lParam);
 }

INT_PTR WINAPI CDialogBase::DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{<!-- -->
    //Check the data from the window's property list and get the pointer to the current dialog class
    CDialogBase* pThis = (CDialogBase*)::GetProp(hWnd, _T("this"));


    //For messages, they are processed after the window has been created.
    if (pThis) //The message is processed by its class method
    {<!-- -->
        return pThis->DialogProc(uMsg, wParam, lParam); //Call the member method defined by CDialogBase encapsulation
    }


    //For messages that are an initialization dialog box, do the following initialization processing.
    if (WM_INITDIALOG == uMsg)
    {<!-- -->
        pThis = (CDialogBase*)(lParam);
        pThis->m_hWnd = hWnd;

        ::SetProp(hWnd, _T("this"), pThis); //Save the pointer of this object into the attribute table, and the attribute name is this
        if (pThis->m_isCenter)
        {<!-- -->
            pThis->MoveToCenter(::GetParent(hWnd));
        }
        return (INT_PTR)TRUE;
    }
    return (INT_PTR)FALSE;
}


INT_PTR CDialogBase::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{<!-- -->
    //Get message mapping table
    const WND_DLG_MSGMAP* pEntry = GetMessageMap();
    LRESULT lpResult = NULL;

    while(pEntry)
    {<!-- -->
        //Find the message map entry
        const WND_DLG_MSGMAP_ENTRY* lpEntries = pEntry->lpEntries;

        while(pEntry)
        {<!-- -->
            const WND_DLG_MSGMAP_ENTRY* lpEntries = pEntry->lpEntries;
            while (lpEntries->m_pfn)
            {<!-- -->
                if (uMsg == lpEntries->m_nMessage)
                {<!-- -->
                    if (WM_COMMAND == uMsg)
                    {<!-- -->
                        WORD wID = LOWORD(wParam);
                        WORD wNotify = HIWORD(wParam);

                        if (wID == lpEntries->m_nID)
                        {<!-- -->
                            lpResult = (this->*lpEntries->m_pfn)(wParam, lParam);
                            break;
                        }
                    }
                    else
                    {<!-- -->
                        lpResult = (this->*lpEntries->m_pfn)(wParam, lParam);
                        break;
                    }
                }

                lpEntries + + ;
            }

            //If the subclass handles it, return it
            if(lpResult)
            {<!-- -->
                ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, lpResult);
                return lpResult;
            }


            //Get the message mapping of the base class
            pEntry = pEntry->pfnGetBaseMap();

        }

        return FALSE;
    }
    return FALSE;
}



BOOL CDialogBase::PreTranslateMessage(LPMSG pMsg)
{<!-- -->
    return FALSE;
}


</code><img class="look-more-preCode contentImg-no-view" src="//i2.wp.com/csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack. png" alt="" title="">