SetWindowPos(...) 的一些注意事项。

来源:互联网 发布:淘宝介入后同意退款 编辑:程序博客网 时间:2024/04/25 03:51

        前些天在调整控件位置,总是出现非预想的错误。我完全没有注意到msdn关于参数的注释:

hWnd
[in] Handle to the window.
hWndInsertAfter
[in] Handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values.
X
[in] Specifies the new position of the left side of the window, in client coordinates.
Y
[in] Specifies the new position of the top of the window, in client coordinates.
cx
[in] Specifies the new width of the window, in pixels.
cy
[in] Specifies the new height of the window, in pixels.

其中X,Y 都是对应于 hWndInsertAfter 的 客户区 坐标。也就是说,关于定位的计算,都应该通过GetClientRect。特别是有着边框(Frame)的控件,直接导致GetWindowRect 与 GetClientRect 所得到的长宽不同。

看MSDN要仔细啊,那么细小的问题。
      

原创粉丝点击