C win32 tab control

Ok, first first coding in C using win32 api, no mfc, no.net, no wxwidgets. I created a window with the WC_TABCONTROL class and added tabs to it, everything works fine, except that ... I need to have content on 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 the tab. The only problem with this is my main window, this is not a dialog, so making a dialog for a tab is perfect, it doesn't work too well.

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

I would like it to resize the window and tab control to the minimum size required for all tabs (3-4 tabs) when launching my application, and the window will not change, which I think makes it a little easier. I did this following the example in msdn (loading each dialog box into memory, switching over each of them and setting RECT to the minimum size needed to resize everything), the problem is that the size is in the units of the dialog box, and I don’t I can convert it to pixels because I do not have HWND in the dialog yet.

Basically, my question is the best way to manage controls in a window using a tab control. Therefore, if I have a tab control and the user moves from tab1 to tab2, I want various controls to be displayed to the user.

+7
source share
1 answer

The basic idea that MSDN receives is to have controls for each tab in its own HWND. The advantage of this is that you can hide / show all controls in the HWND by hiding / showing this parent HWND. This means that switching from one tab to another is just a case of hiding one HWND container and showing another, which is simpler and more elegant than hiding / showing groups of controls. (It also saves the dialog handler code for each individual panel, which is usually what you want.) Both approaches are allowed: although it is often convenient to create a dialog, you do not need to.

These HWND containers do not have to have dialogs, but using a dialog means that the windows will fill the contents of the .rc file for you and automatically manipulate the keyboard. If you create your own HWND, you will have to do it yourself. You can use a hybrid approach: start with a dialog, but add your own controls to the WM_INITDIALOG handler if you need, and even process WM_SIZE to execute a custom layout to make the controls fit better.

If you are on the path to creating your own HWND, find IsDialogMessage () for an easy way to add keyboard support to your own HWND; and also check the WS_EX_CONTROLPARENT style so that work between tabs and controls in the HWND container.

Re: "The problem is that the size is in units of the dialog box, and I can’t convert it to pixels because I don’t have HWND in the dialog box yet." - you can use CreateDialog to create a dialog as invisible - omit WS_VISIBLE from the .rc file - then you can measure / resize, if necessary, before showing it.

+3
source

All Articles