如何在相对位置将子窗口绑定到父窗口? [英] How to bind child windows to parent window in relative positions?

查看:36
本文介绍了如何在相对位置将子窗口绑定到父窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对话框或主窗口中布置子窗口(公共控件)的最佳做法是什么?我的意思是有一种绑定机制可以像在 WPF 中那样将控件的相对位置固定到父窗口的边框.在窗口调整大小期间,子控件将与主窗口一起调整大小.目前我有这个:

What is the best practices for laying out child windows (common controls) in a dialog box or main window? I mean is there a binding mechanism which would fix a relative positions of the control to parent window's border like in WPF. And during window resize the child control would resize together with the main window. Currently I have this:

正如您从红线中看到的那样,当我调整列表视图控件的父窗口大小时,它看起来并不漂亮.我想将例如 ListView 的右侧绑定到 DialogBox 的右边框和类似的其他控件.

As you can see from the red lines it does not look pretty when I am resizing parent window of a list view control. I would like to bind for example ListView's right side to DialogBox's right border and similarly other controls.

我知道我可以使用 GetWindowRect、GetClientRect 和 MoveWindow 函数.但这是正确的方法吗?

I know that I can play around with GetWindowRect, GetClientRect and MoveWindow functions. But is this the correct way?

目前我正在使用没有 MFC 的纯 Win32 Api.

Currently I am working with pure Win32 Api without MFC.

推荐答案

如果你只是使用 Win32 API,你通常通过处理 WM_SIZE 消息来处理这个问题,并通过在父窗口上调用 GetClientRect 和在父窗口上调用 MoveWindow 来响应children 移动/调整子级以适当地填充父级.

If you're just using the Win32 API, you normally handle this by handling the WM_SIZE message, and respond by calling GetClientRect on the parent window and MoveWindow on the children to move/resize the children to fill the parent appropriately.

如果你够狠,你可以(当然)实现一个布局管理器,所以程序的其余部分不需要直接处理这样的事情.至少 IME,做好这件事已经够难的了,除非你能大量使用该布局代码,否则几乎不值得这样做.

If you want to badly enough, you can (of course) implement a layout manager, so the rest of the program doesn't need to handle things like this directly. At least IME, doing this well is sufficiently difficult that it's rarely worth the trouble unless you can make quite a lot of use of that layout code.

这篇关于如何在相对位置将子窗口绑定到父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆