📄 dialog.cpp
字号:
#include "stdafx.h"
#include "dialog.h"
CDialog::CDialog() : m_hWnd(NULL), m_uIDTemplate(0)
{
}
CDialog::~CDialog()
{
}
//void CDialog::SetTemplateID()
//{
// m_uIDTemplate = IDD;
//}
int CDialog::DoModal(HWND hParent)
{
SetTemplateID();
return DialogBox
(
g_hInstance,
MAKEINTRESOURCE(m_uIDTemplate),
hParent,
(DLGPROC)m_pfnWndProc
);
}
bool CDialog::CenterDlg()
{
HWND hParent;
RECT rcParent;
RECT rcDlg;
int x, y, cx1, cy1, cx2, cy2;
if(!IsWindow(m_hWnd))
return false;
if(hParent = GetParent(m_hWnd))
GetWindowRect(hParent, &rcParent);
else
SystemParametersInfo(SPI_GETWORKAREA, 0, &rcParent, 0);
cx1 = rcParent.right - rcParent.left;
cy1 = rcParent.bottom - rcParent.top;
GetWindowRect(m_hWnd, &rcDlg);
cx2 = rcDlg.right - rcDlg.left;
cy2 = rcDlg.bottom - rcDlg.top;
x = rcParent.left + (cx1 - cx2) / 2;
if(x < 0)
x = 0;
y = rcParent.top + (cy1 - cy2) / 2;
if(y < 0)
y = 0;
MoveWindow(m_hWnd, x, y, cx2, cy2, true);
return true;
}
HICON CDialog::SetIcon(HICON hIcon, bool bBigIcon)
{
return (HICON)SendMessage(m_hWnd, WM_SETICON, (WPARAM)bBigIcon, (LPARAM)hIcon);
}
void CDialog::SetTitle(LPCTSTR lpszTitle)
{
SendMessage(m_hWnd, WM_SETTEXT, 0, (LPARAM)lpszTitle);
}
LRESULT CALLBACK CDialog::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_DLGMSG(hwnd, WM_INITDIALOG, OnInitDialog);
HANDLE_DLGMSG(hwnd, WM_COMMAND, OnCommand);
}
return false;
}
//HANDLE_WM_INITDIALOG
bool CDialog::OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
m_hWnd = hwnd;
CenterDlg();
return true;
}
//HANDLE_WM_SETFONT
void CDialog::OnSetFont(HWND hwndCtl, HFONT hfont, BOOL fRedraw)
{
}
//HANDLE_WM_COMMAND
void CDialog::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
HANDLE_CMD(hwnd, IDCANCEL, OnCancel);
HANDLE_CMD(hwnd, IDOK, OnOK);
}
}
void CDialog::OnCancel(HWND hwnd, HWND, UINT)
{
EndDialog(hwnd, IDCANCEL);
}
void CDialog::OnOK(HWND hwnd, HWND, UINT)
{
EndDialog(hwnd, IDOK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -