Solved

Control scale

Posted on 2004-04-12
2
322 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
  • 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 80 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 92
Execute multiple curl cmds with sleep and send output to file 10 97
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 93
Work with App store 7 51
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

805 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