📄 basedialog.cpp
字号:
// BaseDialog.cpp: implementation of the CBaseDialog class.
//
//////////////////////////////////////////////////////////////////////
//#include "stdafx.h"
#include "BaseDialog.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBaseDialog::CBaseDialog(int nResId, HWND hParent)
{
m_nResId = nResId;
m_hParent = hParent;
}
CBaseDialog::~CBaseDialog()
{
m_hWnd = NULL;
}
extern HINSTANCE hInst;
int CBaseDialog::DoModal(void)
{
// m_hWnd=CreateDialogParam(hInst, MAKEINTRESOURCE(m_nResId), m_hParent,
// (DLGPROC)DialogProcStatic, (long)this );
// if(m_hWnd==NULL)return -1;
return DialogBoxParam(hInst, MAKEINTRESOURCE(m_nResId), m_hParent,
(DLGPROC)DialogProcStatic, (long)this );
}
void CBaseDialog::AddMessageHandler(UINT MessageId, void(CBaseDialog::*MsgHandler)(HWND hDlg,WPARAM wParam,LPARAM lParam))
{
t_MessageEntry MessageEntry;
MessageEntry.MsgHandler = MsgHandler;
m_MessageMap.insert(std::map<UINT,t_MessageEntry>::value_type(MessageId, MessageEntry)); /// insert key & data to map
}
BOOL CALLBACK CBaseDialog::DialogProcStatic(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
if ( message == WM_CREATE )
{
CBaseDialog *pObj = reinterpret_cast<CBaseDialog *>
((long)((LPCREATESTRUCT)lParam)->lpCreateParams);
if(pObj)
{
::SetWindowLong( hDlg, GWL_USERDATA,
(LONG)((LPCREATESTRUCT)lParam)->lpCreateParams );
pObj->m_hWnd = hDlg;
pObj->DlgFlag = FALSE;
}
}
if ( message == WM_INITDIALOG )
{
CBaseDialog *pObj = reinterpret_cast<CBaseDialog *>(lParam);
if(pObj)
{
::SetWindowLong( hDlg, GWL_USERDATA, lParam );
pObj->m_hWnd = hDlg;
pObj->DlgFlag = TRUE;
}
}
LRESULT lResult;
// Retrieve the pointer
CBaseDialog *pObj = (CBaseDialog *)::GetWindowLong( hDlg, GWL_USERDATA );
// call the virtual window procedure for the object stored in the
// windows user data
if ( pObj )
lResult = pObj->DialogProc( hDlg, message, wParam, lParam );
else
return false;
//lResult = DefDlgProc( hDlg, message, wParam, lParam );
return lResult;
}
BOOL CALLBACK CBaseDialog::DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
m_MessageMapIterator = m_MessageMap.find(message); /// find message entry by key
if(m_MessageMapIterator == m_MessageMap.end()) /// check if message entry available
{
return FALSE;
}
else
{
t_MessageEntry MessageEntry = (*m_MessageMapIterator).second; /// dereference iterator and get message entry
void (CBaseDialog::*MessageHandler)(HWND hDlg,WPARAM wParam,LPARAM lParam);
MessageHandler = MessageEntry.MsgHandler;
(this->*MessageHandler)(hDlg, wParam, lParam); /// execute function
return TRUE;
}
}
void CBaseDialog::OnOK(void)
{
EndDialog(m_hWnd, IDOK);
}
void CBaseDialog::OnCancel(void)
{
EndDialog(m_hWnd, IDCANCEL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -