|
Home
»
MFC
»
Resizing the Window (Dialog Box)
|
|
|
|
Page Views :
|
2468
|
|
Downloads :
|
17
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
|
|
|
Download
Files:
|
|
|
|
|
|
|
|
|
|
|
|
Sometime we need to resize the dialog at run time, here is one example to
resize the dialog window using VC++ and MFC.
First you have to compute the new coordinates for the controls.
class CGenUtils { public:
void GetNewCoor(
INT nRefWBndLeft, INT nRefWBndRight, INT nRefWBndTop, INT nRefWBndBottom,INT
nRefCBndLeft, INT nRefCBndRight, INT nRefCBndTop, INT nRefCBndBottom, INT
nRefNewWBndLeft, INT nRefNewWBndRight, INT nRefNewWBndTop, INT
nRefNewWBndBottom,INT& nNCBndLeft, INT& nNCBndRight, INT&
nNCBndTop, INT& nNCBndBottom );
void CalcCoor( INT
nRefWBndLower, INT nRefWBndUpper, INT nRefCBndLower, INT nRefCBndUpper,INT
nRefNewWBndLower, INT nRefNewWBndUpper, INT& nCBndLower, INT& nCBndUpper );
};
This
method computes the new coordinate for a given control with respect to the
size of the containing window.
void CGenUtils::GetNewCoor(
INT nRefWBndLeft, INT nRefWBndRight,
INT
nRefWBndTop, INT nRefWBndBottom, INT nRefCBndLeft, INT nRefCBndRight, INT
nRefCBndTop, INT nRefCBndBottom,INT nRefNewWBndLeft, INT nRefNewWBndRight,INT
nRefNewWBndTop, INT nRefNewWBndBottom, INT& nNCBndLeft, INT& nNCBndRight,INT&
nNCBndTop, INT& nNCBndBottom )
{
CalcCoor( nRefWBndLeft, nRefWBndRight, nRefCBndLeft, nRefCBndRight,
nRefNewWBndLeft, nRefNewWBndRight, nNCBndLeft, nNCBndRight );
// Calculates the new horizontal coordinates of
the control
CalcCoor(
nRefWBndTop, nRefWBndBottom, nRefCBndTop, nRefCBndBottom, nRefNewWBndTop,
nRefNewWBndBottom, nNCBndTop, nNCBndBottom );
// Calculates the new vertical coordinates of the control
} Following function computes the vertical and horizontal coordinate
for a given control with respect to the size of the containing window for a
vertical or horizontal size.
void CGenUtils::CalcCoor(
INT nRefWBndLower, INT nRefWBndUpper, INT nRefCBndLower, INT
nRefCBndUpper,INT nRefNewWBndLower, INT nRefNewWBndUpper,INT& nCBndLower,
INT& nCBndUpper )
{
nCBndLower = INT( double( double(
nRefNewWBndUpper ) / double(
nRefWBndUpper ) ) * double(
nRefCBndLower ) );
nCBndUpper = INT( double( double(
nRefNewWBndUpper ) / double(
nRefWBndUpper ) ) * double(
nRefCBndUpper ) );
}
Following
part code should be modified depending on the controls used in you dialog
which has to be resized at runtime.
void
CConfigInteractionLayerDiag::OnSize(UINT nType, int
cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
CGenUtils CGenU;
CRect CRect_Cust;
int nL, nR, nT, nB;
m_bNxtPressed = FALSE;
CMainFrame* pFrmWnd = ((CMainFrame*)(AfxGetMainWnd()));
CView* pCVw = pFrmWnd->GetActiveView();
CWnd* pWndMsgSigSt = ( CWnd* )GetDlgItem( IDC_ST_MsgSig );
if( pWndMsgSigSt != NULL )
{
CGenU.GetNewCoor( 0, 380, 0, 407, 9, 359, 8, 25, 0, cx, 0, cy, nL, nR, nT,
nB );
CRect_Cust.left = nL;
CRect_Cust.right = nR;
CRect_Cust.top = nT;
CRect_Cust.bottom = nB;
pWndMsgSigSt->MoveWindow( CRect_Cust, TRUE );
}
CWnd* pWndRxMsgSigSt = ( CWnd* )GetDlgItem( IDC_ST_RXMSGSIG );
if( pWndRxMsgSigSt != NULL )
{
CGenU.GetNewCoor( 0, 380, 0, 407, 14, 174, 27, 37, 0, cx, 0, cy, nL, nR, nT,
nB );
CRect_Cust.left = nL;
CRect_Cust.right = nR;
CRect_Cust.top = nT;
CRect_Cust.bottom = nB;
pWndRxMsgSigSt->MoveWindow( CRect_Cust, TRUE );
}
CWnd* pWndTxMsgSigSt = ( CWnd* )GetDlgItem( IDC_ST_TXMSGSIG );
if( pWndTxMsgSigSt != NULL )
{
CGenU.GetNewCoor( 0, 380, 0, 407, 199, 358, 27, 37, 0, cx, 0, cy, nL, nR, nT,
nB );
CRect_Cust.left = nL;
CRect_Cust.right = nR;
CRect_Cust.top = nT;
CRect_Cust.bottom = nB;
pWndTxMsgSigSt->MoveWindow( CRect_Cust, TRUE );
}
CWnd* pWndRxMsgSigTv = ( CWnd* )GetDlgItem( IDC_TV_RXMSGSIG );
if( pWndRxMsgSigTv != NULL )
{
CGenU.GetNewCoor( 0, 380, 0, 407, 14, 174, 39, 270, 0, cx, 0, cy, nL, nR, nT,
nB );
CRect_Cust.left = nL;
CRect_Cust.right = nR;
CRect_Cust.top = nT;
CRect_Cust.bottom = nB;
pWndRxMsgSigTv->MoveWindow( CRect_Cust, TRUE );
}
CWnd* pWndTxMsgSigTv = ( CWnd* )GetDlgItem( IDC_TV_TXMSGSIG );
if( pWndTxMsgSigTv != NULL )
{
CGenU.GetNewCoor( 0, 380, 0, 407, 199, 359, 39, 270, 0, cx, 0, cy, nL, nR,
nT, nB );
CRect_Cust.left = nL;
CRect_Cust.right = nR;
CRect_Cust.top = nT;
CRect_Cust.bottom = nB;
pWndTxMsgSigTv->MoveWindow( CRect_Cust, TRUE );
}
CWnd* pWndMsgSigOk = ( CWnd* )GetDlgItem( IDC_PB_OK );
if( pWndMsgSigOk != NULL )
{
CGenU.GetNewCoor( 0, 380, 0, 407, 156, 206, 387, 401, 0, cx, 0, cy, nL, nR,
nT, nB );
CRect_Cust.left = nL;
CRect_Cust.right = nR;
CRect_Cust.top = nT;
CRect_Cust.bottom = nB;
pWndMsgSigOk->MoveWindow( CRect_Cust, TRUE );
}
CWnd* pWndMsgSigCancel = ( CWnd* )GetDlgItem( IDC_PB_CANCEL );
if( pWndMsgSigCancel != NULL )
{
CGenU.GetNewCoor( 0, 380, 0, 407, 209, 259, 387, 401, 0, cx, 0, cy, nL, nR,
nT, nB );
CRect_Cust.left = nL;
CRect_Cust.right = nR;
CRect_Cust.top = nT;
CRect_Cust.bottom = nB;
pWndMsgSigCancel->MoveWindow( CRect_Cust, TRUE );
}
CWnd* pWndVSFMsgVal = (
CWnd* )GetDlgItem( IDC_VSFLEXGRIDILMSGVALUES );
if( pWndVSFMsgVal != NULL )
{
pWndVSFMsgVal->ShowWindow( SW_SHOW );
CGenU.GetNewCoor( 0, 380, 0, 407, 14, 362, 274, 379, 0, cx, 0, cy, nL, nR,
nT, nB );
CRect_Cust.left = nL;
CRect_Cust.right = nR;
CRect_Cust.top = nT;
CRect_Cust.bottom = nB;
m_unFColwidth = (cx * 6 );
m_unSColwidth = ( cx * 4);
m_unTColwidth = ( cx * 3);
long cols =
m_MsgSigValuesGrid.get_Cols();
m_MsgSigValuesGrid.put_ColWidth( 0, m_unFColwidth );
m_MsgSigValuesGrid.put_ColWidth( 1, m_unSColwidth );
m_MsgSigValuesGrid.put_ColWidth( 2, m_unTColwidth );
pWndVSFMsgVal->MoveWindow( CRect_Cust, TRUE
);
}
pFrmWnd->SetActiveView( pCVw );
}
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|