?? expandingdialog.cpp
字號(hào):
// ExpandingDialog.cpp : implementation file
////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <windowsx.h>
#include "ExpandingDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////
// CExpandingDialog dialog
CExpandingDialog::CExpandingDialog(UINT nIDTemplate,CWnd* pParent,
int nIDFrame,int nIDButton,LPCTSTR strExpand,
LPCTSTR strContract,int bAllowContract)
: CDialog(nIDTemplate, pParent)
{
//{{AFX_DATA_INIT(CExpandingDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_strExpand = strExpand;
m_strContract = strContract;
m_nIDFrame = nIDFrame;
m_nIDButton = nIDButton;
m_bExpanded = TRUE;
m_bAllowContract = bAllowContract;
m_pSize = NULL;
}
CExpandingDialog::~CExpandingDialog()
{
delete m_pSize;
}
void CExpandingDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExpandingDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExpandingDialog, CDialog)
//{{AFX_MSG_MAP(CExpandingDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////
// CExpandingDialog message handlers
void CExpandingDialog::ExpandBox(BOOL fExpand)
{
if (fExpand == m_bExpanded) return;
CRect rcWnd, rcDefaultBox, rcChild, rcIntersection;
CWnd * wndChild=NULL;
CWnd * wndDefaultBox=NULL;
CWnd * pCtrl = GetDlgItem(m_nIDButton);
if (pCtrl==NULL) return;
wndDefaultBox = GetDlgItem(m_nIDFrame);
if (wndDefaultBox==NULL) return;
wndDefaultBox->GetWindowRect(&rcDefaultBox);
// 是否使覆蓋框之外的對(duì)話框部分可見
wndChild = GetTopWindow();
for ( ; wndChild != NULL; wndChild = wndChild->GetWindow(GW_HWNDNEXT))
{
// 得到屏幕坐標(biāo)
wndChild->GetWindowRect(&rcChild);
if (!rcIntersection.IntersectRect(&rcChild,&rcDefaultBox))
wndChild->EnableWindow(fExpand);
}
if (!fExpand)//收縮
{
_ASSERT(m_bExpanded);
GetWindowRect(&rcWnd);
if (m_pSize == NULL)
{
m_pSize = new CSize;
m_pSize->cx = rcWnd.right - rcWnd.left;
m_pSize->cy = rcWnd.bottom - rcWnd.top;
wndDefaultBox->ShowWindow(SW_HIDE);
}
SetWindowPos(NULL,0,0,
rcDefaultBox.right - rcWnd.left,
rcDefaultBox.bottom - rcWnd.top,
SWP_NOZORDER|SWP_NOMOVE);
pCtrl->SetWindowText(m_strExpand);
//標(biāo)識(shí)此時(shí)對(duì)話框處于收縮狀態(tài)
m_bExpanded = FALSE;
}
else //展開
{
_ASSERT(!m_bExpanded);
_ASSERT(m_pSize != NULL);
SetWindowPos(NULL,0,0,m_pSize->cx,m_pSize->cy,SWP_NOZORDER|SWP_NOMOVE);
//確保整個(gè)對(duì)話框都可見
SendMessage(DM_REPOSITION,0,0);
if (m_bAllowContract)
pCtrl->SetWindowText(m_strContract);
else
pCtrl->EnableWindow(FALSE);
m_bExpanded = TRUE;
}
}
void CExpandingDialog::OnClickAdvanced()
{
Expand(!m_bExpanded);
}
//關(guān)鍵函數(shù):處理展開和收縮
BOOL CExpandingDialog::Expand(BOOL bExpand)
{
BOOL bShouldExpand;
if (bExpand == m_bExpanded) return TRUE;
//模擬展開過(guò)程
bShouldExpand = OnDialogExpanding(m_bExpanded);
//正式展開
if (bShouldExpand)
{
ExpandBox(bExpand);
//把焦點(diǎn)設(shè)置到欲展開的控件
CWnd * pCtrl;
pCtrl = GetDlgItem(m_nIDButton);
if (pCtrl != NULL)
{
GetNextDlgTabItem(pCtrl,0)->SetFocus();
}
//Expand!
OnDialogExpanded(m_bExpanded);
}
return(m_bExpanded == bExpand);
}
BOOL CExpandingDialog::OnDialogExpanding(BOOL /*bExpanded*/)
{
return (TRUE);
}
void CExpandingDialog::OnDialogExpanded(BOOL /*bExpanded*/)
{
return;
}
BOOL CExpandingDialog::OnInitDialog()
{
CDialog::OnInitDialog();
//初始化使對(duì)話框處于收縮狀態(tài)
ExpandBox(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CExpandingDialog::OnCommand(WPARAM wParam, LPARAM lParam)
{
HWND hwndCtl;
int id;
UINT codeNotify;
//得到WM_COMMAND消息各組成部分
id = GET_WM_COMMAND_ID(wParam,lParam);
hwndCtl = GET_WM_COMMAND_HWND(wParam,lParam);
codeNotify = GET_WM_COMMAND_CMD(wParam,lParam);
//處理消息
if ((id == m_nIDButton)&&(codeNotify==BN_CLICKED))
OnClickAdvanced();
return CDialog::OnCommand(wParam, lParam);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -