📄 ngdialogexpander.cpp
字号:
// Expanding and collapsing dialogs
//
// Michael Walz (walz@epsitec.ch)
// Dec. 99
//
#include "StdAfx.h"
#include "NGDialogExpander.h"
static void ShrinkDialog(CWnd *pDlg, int idmark)
{
ASSERT(pDlg != NULL) ;
CWnd *pWndMark = pDlg->GetDlgItem(idmark) ;
ASSERT(pWndMark != NULL) ;
CRect markrect ;
CRect dlgrect ;
CRect clientrect ;
//CWnd *pParentWnd = pDlg->GetParent() ;
int offset ;
pDlg->GetClientRect(&clientrect) ; // clientrect of the dialog
pDlg->GetWindowRect(&dlgrect) ; // rectangle of the dialog window
// get height of the title bar
offset = dlgrect.Height() - clientrect.bottom ;
pWndMark->GetWindowRect(&markrect) ;
pDlg->ScreenToClient(&markrect) ;
// calculate the new rectangle of the dialog window
dlgrect.bottom = dlgrect.top + markrect.bottom + offset;
pDlg->MoveWindow (dlgrect.left, dlgrect.top, dlgrect.Width(), dlgrect.Height()) ;
}
CNGDialogExpander::CNGDialogExpander()
{
m_bIsInitialized = FALSE ;
}
void CNGDialogExpander::Initialize( CWnd *pDialog,
BOOL bInitiallyExpanded,
int IdExpandButton,
int IdCollapsedMark,
int IdCollapsedText)
{
m_IdCollapsedText = IdCollapsedText;
CString sCollapsedText;
m_pDialog->GetDlgItemText(m_IdCollapsedText, sCollapsedText) ;
CWnd* pWndMark = m_pDialog->GetDlgItem(IdCollapsedText);
ASSERT(NULL != pWndMark);
pWndMark->ShowWindow(SW_HIDE); // hide the "delimiting" control
Initialize(pDialog,
bInitiallyExpanded,
IdExpandButton,
IdCollapsedMark,
sCollapsedText);
}
void CNGDialogExpander::Initialize( CWnd *pDialog,
BOOL bInitiallyExpanded,
int IdExpandButton,
int IdCollapsedMark,
const CString& sCollapsedText)
{
m_IdExpandButton = IdExpandButton;
m_IdCollapsedMark = IdCollapsedMark;
m_bIsInitialized = TRUE ;
m_pDialog = pDialog ;
m_bIsExpanded = TRUE ;
m_pDialog->GetWindowRect(&m_dialogrect) ; // rectangle of the dialog window
m_pDialog->GetDlgItemText(IdExpandButton, m_sTextMore) ;
m_sTextLess = sCollapsedText;
CWnd* pWndMark = m_pDialog->GetDlgItem(m_IdCollapsedMark);
ASSERT(NULL != pWndMark);
pWndMark->ShowWindow(SW_HIDE); // hide the "delimiting" control
if (bInitiallyExpanded)
{
CWnd *pButton = m_pDialog->GetDlgItem(m_IdExpandButton) ;
pButton->SetWindowText(m_sTextLess ) ;
}
else
{
OnExpandButton();
}
}
void CNGDialogExpander::OnExpandButton(void)
{
ASSERT(m_bIsInitialized) ;
m_bIsExpanded = !m_bIsExpanded;
if (m_bIsExpanded)
{
// ShrinkDialog(m_pDialog, m_IdExpandedMark) ;
CRect rect ;
m_pDialog->GetWindowRect(&rect) ;
rect.bottom = rect.top + m_dialogrect.Height();
rect.right = rect.left + m_dialogrect.Width();
m_pDialog->MoveWindow (&rect) ;
}
else
{
ShrinkDialog(m_pDialog, m_IdCollapsedMark );
}
CWnd* pButton = m_pDialog->GetDlgItem(m_IdExpandButton);
ASSERT(NULL != pButton);
if (NULL != pButton)
{
pButton->SetWindowText(!m_bIsExpanded ? m_sTextMore : m_sTextLess);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -