Solved

Control scale

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 69
Rewrite URL With Encoded Characters 6 75
FizzBuzz challenge 9 76
building a service to accessed via telnet client, want colors ? 4 82
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now