Creating and using Tab controls in the windows api
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
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]
#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]
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
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
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,SW_HIDE); // hide all pages<br>}<br><br>int CurTab = SendMessage(pNotify->hwndFrom,TCM_GETCURSEL,0,0);<br>ShowWindow(hTabPages[CurTab],SW_SHOWNORMAL); // show the right page<br><br>}<br><br><A href = "http://www.Quasar3D.nl">My Site</A><br><br><br><SPAN CLASS=editedby>[edited by - Quasar3D on April 5, 2003 3:42:14 AM]</SPAN>
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,SW_HIDE); // hide all pages<br>}<br><br>int CurTab = SendMessage(pNotify->hwndFrom,TCM_GETCURSEL,0,0);<br>ShowWindow(hTabPages[CurTab],SW_SHOWNORMAL); // show the right page<br><br>}<br><br><A href = "http://www.Quasar3D.nl">My Site</A><br><br><br><SPAN CLASS=editedby>[edited by - Quasar3D on April 5, 2003 3:42:14 AM]</SPAN>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement