"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
See below..
On Sat, 24 Mar 2007 15:26:38 -0500, "Peter Olcott" <NoSpam@SeeScreen.com>
wrote:
void CScrollBitmapDlg::OnSize(UINT nType, int cx, int cy) {
****
OnSize is called a lot of times and many times before the edit box is defined.
First, forget you ever heard of GetDlgItem; it is used in rare and exotic
situations of
which this is not one. Use ClassWizard to create control variables.
I have never used the class wizard. Are there any good tutorials on this? I used
examples. What should clean code look like?
Rename those variables by changing the ID from useless names like IDC_EDIT1 to
something
that makes sense to your problem domain, such as IDC_FILENAME, IDC_INPUT,
IDC_KEYWORD, or
whatever it represents. Then use classWizard to create the variable.
What you need to add here is
if(c_EditBox.GetSafeHwnd() != NULL)
{ /* control exists */
*****
CEdit *editbox = (CEdit *) GetDlgItem(IDC_EDIT1);
****
Create a control variable and get rid of the above line
****
RECT rect;
this->GetClientRect(&rect);
*****
You don't need to GetClientRect because you have cx and cy
****
int Width = rect.right - rect.left;
int Height = rect.bottom - rect.top;
*****
Guess what? Width == cx and Height == cy, so you don't need to compute them.
But if you
DID want to compute them, you would be better off writing
CRect rect;
GetClientRect(&rect);
int Width = rect.Width();
int Height = rect.Height();
Note that you do not need to write this-> in front of GetClientRect. It just
clutters
things up.
****
//editbox->MoveWindow(&rect);
editbox->SetWindowPos(NULL, 0, 0, Width, Height, SWP_NOMOVE |
SWP_NOZORDER);
*****
This would work if it were inside the conditional
} /* control exists */
It should resize the control. I do this all the time, it is quite standard
practice.
joe
*****
CDialog::OnSize(nType, cx, cy);
}
Why isn't this code correctly changing the size of the editbox to match the
size
of the DialogBox?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm