ExpandingDialog.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:4k
源码类别:
P2P编程
开发平台:
Visual C++
- // ExpandingDialog.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "ExpandingDialog.h"
- #include <windowsx.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CExpandingDialog dialog
- CExpandingDialog::CExpandingDialog(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
- : CDialog(nIDTemplate, pParent)
- {
- //{{AFX_DATA_INIT(CExpandingDialog)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_bExpanded = true;
- m_nIDButton = IDC_BUTTON_MORE;
- m_strExpand = "More";
- m_SizeBox = m_Size = CSize(0, 0);
- }
- 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 the dialog is already in the requested state, return
- // immediately.
- if (fExpand == m_bExpanded) return;
- CRect rcDefaultBox, rcChild, rcIntersection;
- CWnd * wndChild=NULL;
- CWnd * wndDefaultBox=NULL;
- // get the window of the button
- CWnd * pCtrl = GetDlgItem(m_nIDButton);
- if (pCtrl==NULL) return;
- /*
- wndDefaultBox = GetDlgItem(m_nIDFrame);
- if (wndDefaultBox==NULL) return;
- wndDefaultBox->GetWindowRect(&rcDefaultBox);
- //*/
- rcDefaultBox = CRect(CPoint(0, 0), m_SizeBox);
- ClientToScreen(rcDefaultBox);
- // enable/disable all of the child window outside of the default box.
- wndChild = GetTopWindow();
- for ( ; wndChild != NULL; wndChild = wndChild->GetWindow(GW_HWNDNEXT))
- {
- // get rectangle occupied by child window in screen coordinates.
- wndChild->GetWindowRect(&rcChild);
- if (!rcIntersection.IntersectRect(&rcChild,&rcDefaultBox))
- {
- wndChild->EnableWindow(fExpand);
- }
- }
- if (!fExpand) // we are contracting
- {
- _ASSERT(m_bExpanded);
- // shrink the dialog box so that it encompasses everything from the top,
- // left up to and including the default box.
- SetWindowPos(NULL,0,0,
- m_SizeBox.cx,
- m_SizeBox.cy,
- SWP_NOZORDER|SWP_NOMOVE);
- CString strText = m_strExpand + ">>";
- strText = "扩展>>";
- pCtrl->SetWindowText(strText);
- m_bExpanded = FALSE;
- }
- else // we are expanding
- {
- _ASSERT(!m_bExpanded);
- SetWindowPos(NULL, 0, 0, m_Size.cx, m_Size.cy, SWP_NOZORDER|SWP_NOMOVE);
- // make sure that the entire dialog box is visible on the user's
- // screen.
- // SendMessage(DM_REPOSITION,0,0);
- CString strText = "<<" + m_strExpand;
- strText = "简化<<";
- pCtrl->SetWindowText(strText);
- m_bExpanded = TRUE;
- }
- }
- void CExpandingDialog::OnClickAdvanced()
- {
- Expand(!m_bExpanded);
- }
- BOOL CExpandingDialog::Expand(BOOL bExpand)
- {
- if (bExpand == m_bExpanded) return TRUE;
- ExpandBox(bExpand);
- CWnd * pCtrl = GetDlgItem(m_nIDButton);
- if (pCtrl != NULL)
- {
- GetNextDlgTabItem(pCtrl,0)->SetFocus();
- }
- return(m_bExpanded == bExpand);
- }
- BOOL CExpandingDialog::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CRect rc;
- GetWindowRect(&rc);
- m_Size = CSize(rc.Width(), rc.Height());
- m_SizeBox = m_Size;
- m_SizeBox.cy = 230;
- 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;
- // crack the WM_COMMAND message
- id = GET_WM_COMMAND_ID(wParam,lParam);
- hwndCtl = GET_WM_COMMAND_HWND(wParam,lParam);
- codeNotify = GET_WM_COMMAND_CMD(wParam,lParam);
- // if the "Advanced" button was clicked, then call the
- // message handler.
- if ((id == m_nIDButton)&&(codeNotify==BN_CLICKED))
- {
- OnClickAdvanced();
- }
- return CDialog::OnCommand(wParam, lParam);
- }