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
Solved

Control scale

Posted on 2004-04-12
2
324 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 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