Thread: tab control

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    132

    tab control

    I create a tab control:

    Code:
    // create the tab control
    GetClientRect(hwnd, &rect);
    hTC_Wnd = CreateWindowEx(0, WC_TABCONTROL, NULL, 
    WS_VISIBLE | WS_TABSTOP | WS_BORDER | TCS_HOTTRACK, 
    rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 
    hwnd, NULL, g_hInst, NULL);
    if( hTC_Wnd == NULL )
    	return(2);
    This code is called in a CreateTabControl function I created for this purpose. Then what I wanted it to do since my main window is being created with the WM_MAXIMIZE style (so the main window starts out smaller then what it becomes) is handle the WM_SIZE message in my main windows procedure in order to resize the tab control so it fills the entire client area of my main window:

    Code:
    case WM_SIZE:
    	GetClientRect(hwnd, &rect);
    	MoveWindow(hTC_Wnd, 0, 0, rect.right - rect.left, rect.bottom - rect.top, FALSE);
    	break;
    Now I have tried setting the (HMENU) for when I create the tab control to a valid value except that my program fails in creating the control if I actually try setting that parameter to any value. I'm not sure why this is, but I was forced to leave it as NULL. I did define IDC_TAB as 36000 and that was what I intended to use for this value by using (HMENU)IDC_TAB as that parameter except that it failed everytime whenever I tried to create the tab control.

    If you can assist, thanks.
    Tyouk

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Seems like tab controls with the TCS_HOTTRACK style don't like to be created with (HMENU)identifiers (return value from GetLastError called immediately after CreateWindowEx is 1401: Invalid menu handle).

    So, you might want to create the control without an identifier and then use SetWindowLongPtr with an nIndex value of GWL_ID(or GWLP_ID, if defined) once it's been created. I noticed it also seems to have a problem with its parentage, too, and wasn't created within the parent client area - a call to SetParent, again after the control is created fixed this. This problem, too, seems to be as a direct result of the presence of the TCS_HOTTRACK style.

    You may also be interested in testing for the presence of hot-tracking with SystemParametersInfo (SPI_GETHOTTRACKING) if you're not already doing so.
    Last edited by Ken Fitlike; 01-24-2005 at 02:47 AM. Reason: correction: GWL_ID not GWL_STYLE
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    Wow, thats a lot of things not explained in the MSDN! Now what value am I setting the call of SetWindowLongPtr(hTC_Wnd, GWL_STYLE, ???). Do I set this as TCS_HOTTRACK? cause if so I don't get why I would have to do this afterwards, when I should be able to just set that style during the CreateWindowEx call couldn't I? In which case wouldn't I call CreateWindowEx with an identifier to start with? Sorry, just need some clarification there.

    Now without calling the SetWindowLongPtr as stated in your last post, I am getting the following error messages. When I call SetParent(hTC_Wnd, hWnd); I get the error value from GetLastError and it's 1400: Invalid window handle. Now hTC_Wnd is the global HWND to the tab control (value returned when CreateWindowEx was called). hWnd is a global HWND set when CreateWindowEx was called to create the main window.

    The next error message I get is when I call SystemParametersInfo(SPI_GETHOTTRACKING, 0, &bpvParam, 0); bpvParam being a BOOL that I am passing to get the TRUE (Enabled) or FALSE (Disabled) status of the TCS_HOTTRACKING style being set. I also took the code out of my WM_CREATE message and placed it in the body of WInMain and this caused my tab control to at least resize to the full size of the window, sort of. It looks like the tab doesn't fill the entire window and so there is a chunk of the window that seems to "sink down" lower. Like there is limits to the page sizes.

    I know thats a lot for one post. But any clarification you can give would be of great help.

    Thanks,
    cyreon

    PS - totally switching names so it's the same person just different users.

    Edit: I even did the following to heavily check for errors during the SystemParametersInfo call:

    Code:
    // check to make sure that the TCS_HOTTRACKING style was properly set
    if( !SystemParametersInfo(SPI_GETHOTTRACKING, 0, &bpvParam, 0) )
    {
        sprintf(error, "ERROR: SystemParametersInfo failed! (%u)", GetLastError());
        MessageBox(NULL, error, "Error", MB_ICONEXCLAMATION);
    }
    else {
        if( bpvParam == TRUE )
            MessageBox(NULL, "HotTracking is not active!", "Error", MB_OK);
    }
    Edit::Edit: Hot Tracking is actually working when the program runs. But the tab control doesn't seem to quite want to share the look of focus, should I use the tab control style that disables the tab control from getting focus? The titlebar of my window is lighter in colour as if the program doesn't have focus. Maybe this will be fixed once I get SetParent to work?
    Last edited by cyreon; 01-24-2005 at 01:10 AM.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Actually, ignore that earlier nonsense I posted on account of the fact that it's largely utter balderdash.

    The missing style (thankyou tmouse!) is WS_CHILD and this is the beginning and end of your current code problem, ie.:
    Code:
    hTC_Wnd = CreateWindowEx(0, WC_TABCONTROL, NULL, 
    WS_VISIBLE | WS_TABSTOP | WS_BORDER | TCS_HOTTRACK | WS_CHILD, 
    rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 
    hwnd, NULL, g_hInst, NULL);
    I can only apologise for any confusion my vain attempt to bash the round peg into the square hole has caused you.
    Last edited by Ken Fitlike; 01-24-2005 at 12:44 PM. Reason: that's no way to skin this cat + typo
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    Haha, that doesn't surprise me! I've forgotten to include the WS_CHILD style so many times and it has caused me so many headaches that I really should put a big post it or something on my monitor that says "Did you forget to include the WS_CHILD style again?" just as a reminder. Okay now so I placed the WS_CHILD style into the creation of the tab control and that fixed a lot of the "look" of the interface errors. Now I have the following code in my main windows procedure:

    Code:
    case WM_NOTIFY:
    	lpnmhdr = (LPNMHDR)lParam;
    	if( lpnmhdr->code == TCN_SELCHANGE )
    	{
    		MessageBox(NULL, "Tab selection change..", "Tab Change", MB_OK);
    		tab = TabCtrl_GetCurSel(hTC_Wnd);
    	                if( tab != -1 )
    			SwitchTabs(tab);
    	}
    	break;
    Now the SwitchTabs(tab) call should infact be passed the new tab control that has been selected, correct? For some reason it is passing 0 everytime (meaning the first tab). I get messages such as "Hiding first tab..." then right afterwards "Showing first tab...".

    Basically SwitchTabs right now is two switch statements... the first is switch(curTab) which determines which tab was selected prior to the new selection. Then a switch(newTab) which determines the new tab being selected based on the value of tab passed to the function from the WM_NOTIFY message. I can't figure out why this is returning 0 everytime. Quite annoying, and most likely a very simple problem.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You could try replacing hTC_Wnd with lpnmhdr->hwndFrom as the parameter of TabCtrl_GetCurSel. If that doesn't change things then look to your 'SwitchTabs' function and see if the problem is, in fact, there.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    Okay I tried your suggestion, it did not work. I have already tested my values for the SwitchTabs function. It would seem that the problem lies in the TabCtrl_GetCurSel call. It seems to always return 0. If you have any other suggestions then please let me know.

    Btw, sorry for the late reply. I recently moved and just got my internet hooked up again.

    cyreon

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need a little help here about MFC and Tab Control stuff...
    By guitarist809 in forum Windows Programming
    Replies: 4
    Last Post: 09-19-2008, 10:36 AM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Tab order in Tab Control
    By Halloko in forum Windows Programming
    Replies: 2
    Last Post: 05-08-2005, 11:08 PM
  4. Disable a tab in control tab?
    By Iron Mike in forum Windows Programming
    Replies: 1
    Last Post: 07-23-2003, 10:50 AM
  5. Using Tab control to change between dialogs
    By Eado in forum Windows Programming
    Replies: 2
    Last Post: 05-15-2002, 03:43 AM