Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

quant

Creating and using Tab controls in the windows api

This topic is 5652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Ive been trying to create a working tab control using the winapi all day, and ive got pretty much nowhere. The only website i can find on them is the msdn one. But ive had alot of trouble trying to get the example they give to work correctly. I think the problem lies with creating resource templates, in that im not 100% sure how to do it. So if any1 has experience with the example on the msdn website ( in particular the one relating to tab controls on a dialog box), then id be greatful of some advice on how to create dialog templates. Or if anyone has some sample code which they have written, which uses tab controls on a dialog box (however messy) using the windows api (not mfc please) then id also be greatful if the can post a link to it or email it to me Also if anyone has a good tutorial about tab controls in the winapi it would be good if you could post some links Thx

Share this post


Link to post
Share on other sites
Advertisement
I don't know the msdn sample, however, to create a tab control:

#include <commctrl.h>

link with comctl32.lib

call InitCommonControls() somewhere before creating the dialog

in the WM_INITDIALOG message case:

TCITEM Item;

// execute this code to add a tab page
Item.mask = TCIF_TEXT;
Item.pszText = "Tab";
SendDlgItemMessage(hDlg,IDC_TAB,TCM_INSERTITEM,0,(LPARAM)&Item);

you receive a WM_NOTIFY message with notify code TCN_SELCHANGE, when another page is selected, and than you should redraw the content of the tab page, or just show and hide other child windows, with the right controls in it.

hope this helps

My Site

[edited by - Quasar3D on April 4, 2003 5:20:21 AM]

Share this post


Link to post
Share on other sites
Thx for the reply .

The drawing and redrawing of the child dialog box is the main bit ive been having trouble with

Could you please explain how to do that in a bit more detail

thx

Share this post


Link to post
Share on other sites
You have the dialog with the tab control in it, and for every page, you create another dialog, without a border (select none in the border list, and in the style list you should select child. Now you create such a dialog for every page.

now in the message proc for the dialog:

HWND hTabPages[5]; // this should be a global, or static

case WM_INITDIALOG:
hTabPages[0] = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_PAGE1),hWnd,(DLGPROC)Tab1Proc);
SetWindowPos(hTabPages[0],0,10,10,0,0,SWP_NOSIZE|SWP_NOZORDER);
hTabPages[1] = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_PAGE2),hWnd,(DLGPROC)Tab2Proc);
SetWindowPos(hTabPages[1],0,10,10,0,0,SWP_NOSIZE|SWP_NOZORDER);

...

ShowWindow(hTabPages[0],SW_SHOWNORMAL);
break;

and when another page is selected, you hide and show other pages:

// in the message proc of the dialog
case WM_NOTIFY:
pNotify = (NMHDR*)lParam;
if(wParam == IDC_OBJTAB && pNotify->code == TCN_SELCHANGE)
{
for(int i = 0;i<5;i++)
{
ShowWindow(hTabPages[ i ],SW_HIDE); // hide all pages
}

int CurTab = SendMessage(pNotify->hwndFrom,TCM_GETCURSEL,0,0);
ShowWindow(hTabPages[CurTab],SW_SHOWNORMAL); // show the right page

}

My Site


[edited by - Quasar3D on April 5, 2003 3:42:14 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!