Solved

Control scale

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 …
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…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

14 Experts available now in Live!

Get 1:1 Help Now