Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C win32 tab control

Tags:

c

tabs

winapi

api

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.

like image 360
Josh Avatar asked May 18 '11 17:05

Josh


People also ask

What is tab control?

A tab control is analogous to the dividers in a notebook or the labels in a file cabinet. By using a tab control, an application can define multiple pages for the same area of a window or dialog box.

How do I create a tab in C++?

If you just want to add a newline, you're supposed to just insert a '\n' . And if you just want to add a tab, you just insert a '\t' .

How do you use tab control in Access?

First, open your Form in Design View. Then select the Design tab in the toolbar at the top of the screen. Then click on the Table Control button in the Controls group. Then left-click on the Form where you'd like the Tab Control to appear.


1 Answers

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.

like image 132
BrendanMcK Avatar answered Sep 20 '22 06:09

BrendanMcK