C win32选项卡控件

发布于 2024-11-08 02:34:46 字数 581 浏览 0 评论 0原文

好吧,我首先使用 win32 api 在 C 中编码,没有 mfc,没有 .net,没有 wxwidgets。 我已经使用 WC_TABCONTROL 类创建了一个窗口,并向其中添加了选项卡,一切正常,除了...我需要在每个选项卡中包含内容,我从 msdn 得到的印象是我需要为每个页面创建一个对话框,然后在用户选择选项卡时加载对话框。唯一的问题是我的主窗口不是对话框,因此使选项卡的对话框完全适合效果不太好。

所以我想知道是否有更好的方法来做到这一点?我想过只是隐藏和显示每个选项卡的不同控件,但这似乎不是一个好主意。

我想要的是,当我的应用程序启动时,它会将窗口和选项卡控件的大小调整为适合所有选项卡(3-4 个选项卡)所需的最小尺寸,并且窗口不会调整大小,我想这会简化事情一点点。我按照 msdn 上的示例(将每个对话框加载到内存中,循环遍历每个对话框并将 RECT 设置为所需的最小大小,然后调整所有内容的大小)来做到这一点,问题是大小以对话框单位为单位,我不能将其转换为像素,因为我还没有对话框的 HWND。

基本上我的问题是使用选项卡控件管理窗口上的控件的最佳方法是什么。因此,如果我有一个选项卡控件并且用户从 tab1 更改为 tab2,我希望向用户显示不同的控件。

Alright so first im coding in C using the win32 api, no mfc, no .net, no wxwidgets.
I've created a window with the WC_TABCONTROL class, and have added tabs to it, everything works fine except... I need to have content in each tab, I got the impression from msdn that I needed to create a dialog for each page, and then load the dialog when the user selects a tab. Only problem with this is my main window isnt a dialog, so making the dialog box for the tab fit perfectly is not working too good.

So I'm wondering if there's a better way to do this? I thought about just hiding and showing different controls per tab but that doesn't seem like a good idea.

What I'd like is when my application starts it will resize the window and the tab control to the minimal size needed to fit all the tabs (3-4 tabs), and the window isn't going to be resizable which I guess simplifies things a little bit. I did this by following the example on msdn (Loading each dialog box into memory, looping thru each one and setting a RECT to the minimal size needed then resizing everything), problem is that the size is in dialog box units and I can't convert it to pixels because I don't have a HWND to the dialog box yet.

Basically my question is what is the best way to manage controls on a window with a tab control. So if I have a tab control and the user changes from tab1 to tab2, I want different controls to be displayed to the user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染柒℉ 2024-11-15 02:34:46

MSDN 的基本思想是让每个选项卡的控件都位于其自己的 HWND 中。这样做的好处是,您可以通过隐藏/显示父 HWND 来隐藏/显示 HWND 中的所有控件。这意味着从一个选项卡转到另一个选项卡只是隐藏一个容器 HWND 并显示另一个容器的情况,这比隐藏/显示一组控件更简单、更优雅。 (它还使每个窗格的对话框处理程序代码保持独立,这通常是您想要的。)但这两种方法都是允许的:创建对话框通常更方便,但您不需要这样做。

这些容器 HWND 不必是对话框,但使用对话框意味着 Windows 将为您填充 .rc 文件中的内容并自动处理键盘选项卡。如果您创建自己的 HWND,则必须自己执行此操作。您可以采用混合方法:从对话框开始,但如果需要,可以在 WM_INITDIALOG 处理程序中添加您自己的控件,甚至可以处理 WM_SIZE 来执行自定义布局,以便控件更适合。

如果您选择创建您自己的 HWND 路线,请查找 IsDialogMessage() 以获取向您自己的 HWND 添加键盘选项卡支持的简单方法;并且还检查 WS_EX_CONTROLPARENT 样式,以便选项卡本身与容器 HWND 中的控件之间的选项卡切换有效。

回复:“问题是尺寸以对话框单位为单位,我无法将其转换为像素,因为我还没有对话框的 HWND。” - 您可以使用 CreateDialog 将对话框创建为不可见 - 从 .rc 文件中省略 WS_VISIBLE - 然后您可以在显示之前适当测量/调整大小。

The basic idea that MSDN is getting at is to have the controls for each tab within their own HWND. The benefit of this is that you can hide/show all the controls within a HWND by hiding/showing that parent HWND. This means that going from one tab to another is just a case of hiding one container HWND, and showing another, which is simpler and more elegant than having to hide/show groups of controls. (It also keeps the dialog handler code for each pane separate, which is usually what you want.) Both approaches are allowed, though: it's often more convenient to create a dialog, but you are not required to.

These container HWNDs don't have to be dialogs, but using a dialog means that windows will populate the contents from a .rc file for you and handle keyboard tabbing automatically. If you create your own HWND, you'll have to do this yourself. You could take a hybrid approach: start off with a dialog, but add your own controls in the WM_INITDIALOG handler if you need to, and even handle WM_SIZE to do custom layout so that the controls fit better.

If you go the create-your-own-HWND route, look up IsDialogMessage() for a simple way to add keyboard tabbing support to your own HWND; and also check out the WS_EX_CONTROLPARENT style so that tabbing between the tabs themselves and the controls in the container HWND work.

Re: "problem is that the size is in dialog box units and i cant convert it to pixels because i dont have a HWND to the dialog box yet." - you may be able to use CreateDialog to create the dialog as invisible - omit WS_VISIBLE from the .rc file - then you can measure/resize as appropriate before you show it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文