tags:

views:

2036

answers:

6

Hi all,

I am writing a program which has two panes (via CSplitter), however I am having problems figuring out out to resize the controls in each frame. For simplicity, can someone tell me how I would do it for a basic frame with a single CEdit control?

Fairly sure it is to do with the CEdit::OnSize() funcion... but not really getting anywhere...

Thanks! :)

A: 

When your frame receives an OnSize message it will give you the new width and height - you can simply call the CEdit SetWindowPos method passing it these values.

Assume CMyPane is your splitter pane and it contains a CEdit you created in OnCreate called m_wndEdit:

void CMyPane::OnSize(UINT nType, int cx, int cy)
{
    m_wndEdit.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
}
Rob
+1  A: 

SetWindowPos is a little heavy duty for this purpose. MoveWindow has just what is needed.

ravenspoint
+1  A: 

GetDlgItem(IDC_your_slidebar)->SetWindowPos(...) // actually you can move ,resize...etc

Eddie
+4  A: 

A window receives WM_SIZE message (which is processed by OnSize handler in MFC) immediately after it was resized, so CEdit::OnSize is not what you are looking for.

You should add OnSize handler in your frame class and inside this handler as Rob pointed out you'll get width and height of the client area of you frame, then you should add the code which adjust size and position of your control.

Something like this

void MyFrame::OnSize(UINT nType, int w, int h)
{
    // w and h parameters are new width and height of your frame
    // suppose you have member veriable CEdit myEdit which you need to resize/more
    myEdit.MoveWindow(w/5, h/5, w/2, h/2);
}
Serge
A: 

Others have pointed out that WM_SIZE is the message you should handle and resize the child controls at that point. WM_SIZE is sent after the resize has finished.

You might also want to handle the WM_SIZING message which gets sent while the resize is in progress. This will let you actively resize the child windows while the user is still dragging the mouse. Its not strictly necessary to handle WM_SIZING but it can provide a better user experience.

Brian Ensink
A: 

I use CResize class from CodeGuru to resize all controls automatically. You tell how you want each control to be resized and it does the job for you.

The resize paradigm is to specify how much each side of a control will move when the dialog is resized.

SetResize(IDC_EDIT1, 0,   0,   0.5, 1);
SetResize(IDC_EDIT2, 0.5, 0,   1,   1);

Very handy when you have a large number of dialog controls.

Source code

Sergey Kornilov