Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a tab control

Status
Not open for further replies.

timmay3141

Programmer
Dec 3, 2002
468
US
I need help using a tab control C++ with win32. I didn't see a single good online tutorial for how to use one. I'm sure there is quite a bit to know about how to use them, but can someone give me the basic messages that a tab control will send, and how to use them to show the correct controls for each page? Do I have to manually say which controls to show/hide, or is their an easier way to do it?
 
Basic messages you send for manipulating tab controls:

TCM_INSERTITEM [inserts an item into the tab control]
TCM_SETCURSEL [sets which tab is active, by index]
TCM_GETCURSEL [gets index of currently selected tab]

Most important notification the parent window will receive:

TCN_SELCHANGE [whenever the user selects a different tab]

>> Do I have to manually say which controls to show/hide

You could do that, but here is an easier way: use Child dialogs. For each tab, create a Child dialog in the resource editor (with no border and with the Child style). In the dialog properties, be sure to set X and Y to the offset (in DLU's) of the corner of the tab control. And also turn the Visible style off.

For the parent dialog's WM_INITDIALOG handler, create all the child dialogs. Call ShowWindow(SW_SHOW) on the first child dialog.

Then, when you receive a TCN_SELCHANGE notification, you simply call ShowWindow(SW_HIDE) on the current dialog, and ShowWindow(SW_SHOW) on the newly selected dialog.

I REALLY hope that helps.
Will
 
That was helpful, but I still have a couple of questions. First of all, I'm somehow missing the TCN_SELCHANGE notification. Then I change a tab, I do get a WM_NOTIFY message, but wParam doesn't equal TCN_SELCHANGE as it should. It is sending the ID of the tab control instead. I've never really dealt with the WM_NOTIFY message, as I'm new to win32, but I looked at an example that said this is how you would handle it within the DialogProc:

switch(msg)
{
case WM_NOTIFY:
switch(wParam)
{
case TCN_SELCHANGE:
// do stuff
break;
// other notifications
}
break;
// other messages
}

But, like I said, wParam was the ID of the tab control rather than TCN_SELCHANGE. Am I doing something wrong, or does the ID imply that it's a TCN_SELCHANGE?

I'm having a problem with the child dialogs as well, but I've still got some ideas of how I can get them to work. I'll let you know if I can't figure anything out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top