在 MFC 中调整控件大小

2022-01-12 00:00:00 c++ mfc

我正在编写一个程序,它有两个窗格(通过 CSplitter),但是我在弄清楚如何调整每个帧中的控件大小时遇到??了问题.为简单起见,有人可以告诉我如何为带有单个 CEdit 控件的基本框架执行此操作吗?

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?

我很确定这与 CEdit::OnSize() 函数有关...但我并没有真正到达任何地方...

I'm fairly sure it is to do with the C:OnSize() function... But I'm not really getting anywhere...

谢谢!:)

推荐答案

当你的框架收到 OnSize 消息时,它会给你新的宽度和高度 - 你可以简单地调用 CEdit SetWindowPos 方法传递这些值.

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.

假设 CMyPane 是您的拆分器窗格,它包含您在 OnCreate 中创建的名为 m_wndEdit 的 CEdit:

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

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

相关文章