【发布时间】:2017-01-04 23:43:27
【问题描述】:
我们可以使用EM_SETMARGINS 消息来设置RichEdit 控件的左右边距。但我不知道如何设置顶部/底部边距。有人知道吗?谢谢。
【问题讨论】:
标签: c++ windows winapi controls
我们可以使用EM_SETMARGINS 消息来设置RichEdit 控件的左右边距。但我不知道如何设置顶部/底部边距。有人知道吗?谢谢。
【问题讨论】:
标签: c++ windows winapi controls
使用EM_GETRECT/EM_SETRECT消息组合修改所有边距:
RECT rc;
// Get the current control rectangle
SendMessage(hWndRichEdit, EM_GETRECT, 0, (LPARAM)&rc);
rc.left += 20; // increase the left margin
rc.top += 20; // increase the top margin
rc.right -= 20; // decrease the right margin
rc.bottom -= 20; // decrease the bottom margin (rectangle)
// Set the rectangle
SendMessage(hWndRichEdit, EM_SETRECT, 0, (LPARAM)&rc);
生成的控件具有所有四个边距:
更新:根据下面的Barmak Shemirani 和IInspectable cmets,您可以使用GetClientRect 函数来获取当前矩形和InflateRect 函数来操作矩形/边距尺寸。
【讨论】:
GetClientRect 而不是EM_GETRECT。因为EM_GETRECT 返回当前边距。例如,左/上边距可以返回为 1 和 1。而 GetClientRect 始终返回 0 和 0。
InflateRect(rc, -20, -20);。