Archived

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

Tab Controls in Windows (No MFC)

This topic is 5886 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

Have 2 windows registered via RegisterClassEx, on window1, i have a tab control(child of window1), with 3 tabs, below those tabs, i have created 3 of window2(all children of window1), using WM_NOTIFY and TCN_SELCHANGE i show a window, and hide the others, on each of these windows, i have common controls of windows (static, buttons, editboxes, etc)(children of their respective window2) with the WS_TABSTOP property. Problem is when my cursor is in an editbox, i can''t tab to another control in the window2, all it does is beep at me, very annoying. Any suggestions?

Share this post


Link to post
Share on other sites
I just wanna know how the heck you got a tab control to work. I have never been able to get tab controls, or tree controls, or any other non-basic control to work.

Share this post


Link to post
Share on other sites
Russell, you need to initalize common controls to get tab controls to work. Otherwise, nothing will show.

In your main window, include the following source

  
INITCOMMONCONTROLSEX iccex;
/* INITIALIZE COMMON CONTROLS */
iccex.dwICC = ICC_WIN95_CLASSES;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCommonControlsEx(&iccex);


If you are just using Win95, just use InitCommonControls, rather than InitCommonControlsEx.

Skibum, remember to check whether it''s a dialog message, and just pass the messages of the parent to their children.

Share this post


Link to post
Share on other sites
Here you have Russel:

  

bool CWnd::CreateTabControl(HWND hwndParent, CWnd *pTabWnds, int NumTabs)
{
InitCommonControlsEx(&icex);

const MAX_TABS = 2;

RECT rcClient;
HWND hwndTab;

// Get the dimensions of the parent window''s client area, and

// create a tab control child window of that size.

GetClientRect(hwndParent, &rcClient);

DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_EX_STATICEDGE;

hwndTab = CreateWindowEx( WS_EX_DLGMODALFRAME,
WC_TABCONTROL, "", dwStyle,
0, 0, rcClient.right, rcClient.bottom,
hwndParent, NULL, (HINSTANCE) GetModuleHandle(NULL), NULL );

if (hwndTab == NULL)
return false;

// Set Font to default menu font

LOGFONT logfont ;
GetObject (GetStockObject (DEFAULT_GUI_FONT), sizeof (LOGFONT), (PTSTR) &logfont) ;
HFONT hFont = CreateFontIndirect (&logfont) ;
SendMessage (hwndTab, WM_SETFONT, (WPARAM) hFont, 0) ;

TCITEM tie;
tie.mask = TCIF_IMAGE | TCIF_TEXT;
tie.iImage = -1;

char* flikNamn[] =
{
"
Tab1", "Tab2"
};

for(int i=0; i<MAX_TABS; i++)
{
tie.pszText = flikNamn[i];
TabCtrl_InsertItem(hwndTab, i, &tie);
}

hWnd = hwndTab;

RECT rc;
GetClientRect(hWnd, &rc);

RECT rcFlik;
TabCtrl_GetItemRect(hWnd, 0, &rcFlik); rcFlik.bottom+=5;
GetClientRect(hWnd, &rc);

char ClassName[100];
GetClassName(hwndParent, ClassName, 99);

rc.top += rcFlik.bottom;
pTabWnds[0].CreateWnd(ClassName, hwndParent, rc, WS_CHILD | WS_VISIBLE | WS_VSCROLL, NULL);
pTabWnds[1].CreateWnd(ClassName, hwndParent, rc, WS_CHILD | WS_VSCROLL, NULL);

return true;
}





Zeblar Nagrim, Lord of Chaos

Share this post


Link to post
Share on other sites
I have no dialogs, just 2 different windows that i've created
Parts of the program follow:
  
LRESULT CALLBACK ClientProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED) // it's a button, now check to see if it's one of the add/delete ones

{
SendMessage(g_hWnd, WM_COMMAND, wParam, lParam);// so i get button messages in my WndProc loop

break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow)) {
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_BASIC);

while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
initCtrl.dwSize = sizeof(INITCOMMONCONTROLSEX);
initCtrl.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&initCtrl);
GetClientRect(hWnd, &rect);
RegisterClientClass(hInst);
hTab = CreateWindow(WC_TABCONTROL, NULL, TCS_TABS | WS_VISIBLE | WS_CHILD,
0, 0, rect.right - rect.left, TAB_HEIGHT, hWnd, NULL, hInst, NULL);

memset(&ti, '\0', sizeof(TC_ITEM));
ti.mask = TCIF_TEXT;
ti.iImage = -1;
for(i=0;i < MAX_TABS;i++)
{
ti.pszText = TabNames[i];
TabCtrl_InsertItem(hTab, 0, &ti);
hTabWindows[i] = CreateWindow(CLIENT_WINDOW, NULL, WS_TABSTOP | WS_CHILD, 0, TAB_HEIGHT,
rect.right+1 - rect.left, rect.bottom+1 - rect.top - TAB_HEIGHT, hWnd, NULL, hInst, NULL);
}
TabCtrl_SetCurSel(hTab, 0);
ShowWindow(hTabWindows[DFHMSD], SW_SHOW);
iCurTab = 0;
for(i=0;i < 8;i++) // MSD Controls

{
CreateWindow("static", MSDLabel[i], WS_VISIBLE | WS_CHILD, 15, (i+1)*30, 70, 18, hTabWindows[FIRST_TAB], NULL, hInst, NULL);
hMSD[i] = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", NULL, WS_TABSTOP | WS_VISIBLE | WS_CHILD, 85, (i+1)*30, 100, 22, hTabWindows[FIRST_TAB], NULL, hInst, NULL);
}
case WM_NOTIFY:
lpnmhdr = (LPNMHDR)lParam;
if(lpnmhdr->code == TCN_SELCHANGE)
{
iCurTab = TabCtrl_GetCurSel(hTab);
ShowWindow(hTabWindows[iCurTab], SW_SHOW);
}
if(lpnmhdr->code == TCN_SELCHANGING)
{
ShowWindow(hTabWindows[iCurTab], SW_HIDE);
}


Edited by - Skibum on October 31, 2001 4:29:50 PM

Share this post


Link to post
Share on other sites