dockwnddlg.cpp
来自「c++系统开发实例精粹内附的80例源代码 环境:windows2000,c++」· C++ 代码 · 共 166 行
CPP
166 行
// DockWndDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DockWnd.h"
#include "DockWndDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDockWndDlg dialog
CDockWndDlg::CDockWndDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDockWndDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDockWndDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bDisplayed = TRUE;
}
void CDockWndDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDockWndDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDockWndDlg, CDialog)
//{{AFX_MSG_MAP(CDockWndDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
ON_WM_HELPINFO()
ON_WM_DESTROY()
ON_WM_MOVING()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDockWndDlg message handlers
BOOL CDockWndDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// 将主窗体居中显示
this->CenterWindow();
// 创建子窗体
m_dlgDisplay.Init(this->GetSafeHwnd());
InverseState();
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDockWndDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDockWndDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDockWndDlg::OnDisplay()
{
// TODO: Add your control notification handler code here
InverseState();
}
BOOL CDockWndDlg::OnHelpInfo(HELPINFO* pHelpInfo)
{
// TODO: Add your message handler code here and/or call default
OnDisplay();
return TRUE;
}
void CDockWndDlg::InverseState()
{
// 显示状态取反
m_bDisplayed = !m_bDisplayed;
// 获得显示子窗体状态的按钮指针
CWnd *pWnd = this->GetDlgItem(IDC_DISPLAY);
pWnd->SetWindowText(m_bDisplayed ? _T("隐藏") : _T("显示"));
// 将子窗体显示或隐藏
m_dlgDisplay.ShowWindow(m_bDisplayed ? SW_SHOW : SW_HIDE);
}
void CDockWndDlg::OnDestroy()
{
m_dlgDisplay.DestroyWindow();
CDialog::OnDestroy();
}
void CDockWndDlg::OnMoving(UINT fwSide, LPRECT pRect)
{
CDialog::OnMoving(fwSide, pRect);
// TODO: Add your message handler code here
RECT rect,rectMain;
// 获得子窗体矩形
rect = (RECT)m_dlgDisplay.GetRect();
// 获得主窗体矩形
this->GetWindowRect(&rectMain);
// 判断是否在停靠状态
if (m_dlgDisplay.IsDocking((CRect)rectMain,(CRect)rect,NO_DIRECTION))
{
// 是则调整子窗体位置
m_dlgDisplay.Dock(m_dlgDisplay.GetDirection(),this);
// 记录子窗体停靠矩形的位置
rect = (RECT)m_dlgDisplay.GetRect();
// 移动子窗体,停靠到主窗体的边上
m_dlgDisplay.MoveWindow(&rect);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?