?
Solved

Control scale

Posted on 2004-04-12
2
Medium Priority
?
327 Views
Last Modified: 2013-11-20
There is one dialog box and only one edit control in my dialog-based MFC application. At design time, I set the edit control to be as big as half of the dialog box. At runtime, whenever I change the dialog's size, I want to the edit control always to scale up to half of the new size of the dialog box. How can I do that ?

Thanks.
0
Comment
Question by:kevinnguyen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 5

Expert Comment

by:Nass89
ID: 10810601
Hi,
Add the WM_SIZE message handler to your application and add the following code to change the size of EditBox in OnSize(..):

 CWnd *pWnd = GetDlgItem(IDC_EDIT1);
  CRect cr, dr;

  pWnd->GetWindowRect ( cr );
  GetClientRect(dr);
  ScreenToClient ( cr );
  pWnd->MoveWindow ( cr.left, cr.right, (dr.right-dr.left)/2, (dr.bottom-dr.top)/2, TRUE );

Good Luck!
0
 
LVL 5

Accepted Solution

by:
Nass89 earned 320 total points
ID: 10810704
Hi,
Correction to last comment!
As you see if you use the suggested codes under OnSize(), the App crashes at statrtup, make the following corrections:

void CMyDlg::OnSize(UINT nType, int cx, int cy)
{
      CDialog::OnSize(nType, cx, cy);
      // TODO: Add your message handler code here
CWnd *pWnd = GetDlgItem(IDC_EDIT1);
  CRect cr, dr;
  GetClientRect(dr);
//check the pointer
  if(pWnd){
  pWnd->GetWindowRect ( cr );
  ScreenToClient ( cr );
  pWnd->MoveWindow ( cr.left, cr.right, (dr.right-dr.left)/2, (dr.bottom-dr.top)/2, TRUE );      
  }
}

If You want the edit control  change it size at startup, add the the same codes in OnInitDialog() .

Good Luck!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question