Thread: Tab Controls

  1. #1
    Registered User
    Join Date
    Sep 2009
    Location
    Lagos, Nigeria
    Posts
    3

    Thumbs up Tab Controls

    Hello,
    I have problem in having a tab control created with Win32 programming working properly. Though the contrl is created, but on clicking any of the tabs none of the others controls created did not show on the tab control.

    Here is the code for the tab control:

    Code:
     BOOL SetUpMDIChild1WindowClass(HINSTANCE hInstance)
            {
                    WNDCLASSEX wc;
    
                    wc.cbSize = sizeof(WNDCLASSEX);
                    wc.style = CS_HREDRAW | CS_VREDRAW;
                    wc.lpfnWndProc = MDIChild1WndProc;
                    wc.cbClsExtra = 0;
                    wc.cbWndExtra = 0;
                    wc.hInstance = hInstance;
                    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
                    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
                    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
                    wc.lpszMenuName = NULL;
                    wc.lpszClassName = g_szChild1ClassName;
                    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
    				
    
                    if(!RegisterClassEx(&wc))
                    {
                    MessageBox(0, "Could Not Register Child Window", "Oh Oh...",
                    MB_ICONEXCLAMATION | MB_OK);
                    return FALSE;
                    }
                    else
                    return TRUE;
            }
    
    LRESULT CALLBACK MDIChild1WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
            {
    	int i;
    	HFONT hfDefault;
    	NMHDR lpnmhdr;
    	lpnmhdr.hwndFrom = g_hwndTab;
    	lpnmhdr.idFrom = IDC_TABCTRL;
    	switch(msg)
    	{
    		case WM_CREATE:
    		{
    			
                             //Create Tab Controls
                                  g_hwndTab = DoCreateTabControl(hwnd);
    
    		//Create Static Control that will occupy the tabcontrol's display area.
    		     g_hwndDisplay = DoCreateDisplayWindow(hwnd);
    			
    	        //Create Edit control that will occupy the tabcontrol's display area. 
    				hEditTab = DoEditCreation(hwnd);
    			
    		}
    		break;
    		case WM_MDIACTIVATE:
    		{
    			HMENU hMenu, hFileMenu;
    			UINT EnableFlag;
    
    			hMenu = GetMenu(g_hMainWindow);
    			if(hwnd == (HWND)lParam)
    			{	   //being activated, enable the menus
    				EnableFlag = MF_ENABLED;
    CheckMenuItem(hSubMenu6,IDM_COYFORMATION,MF_CHECKED |MF_BYCOMMAND);
    			}
    			else
    			{	//being de-activated, gray the menus
    				//EnableFlag = MF_GRAYED;
    CheckMenuItem(hSubMenu6,IDM_COYFORMATION,MF_UNCHECKED |MF_BYCOMMAND);
    			}
    
    			EnableMenuItem(hMenu, 1, MF_BYPOSITION | EnableFlag);
    			EnableMenuItem(hMenu, 2, MF_BYPOSITION | EnableFlag);
    
    			hFileMenu = GetSubMenu(hMenu, 0);
    			EnableMenuItem(hFileMenu, ID_SAVEAS, MF_BYCOMMAND | EnableFlag);
    
    			EnableMenuItem(hFileMenu, ID_CLOSE, MF_BYCOMMAND | EnableFlag);
    			EnableMenuItem(hFileMenu, ID_CLOSEALL, MF_BYCOMMAND | EnableFlag);
    
    			DrawMenuBar(g_hMainWindow);
    		}
    		break;
    		
    		
    		
    		case WM_SIZE: { 
                                   HDWP hdwp; 
    
                                     RECT rc; 
     
                    // Calculate the display rectangle, assuming the 
                    // tab control is the size of the client area. 
                    SetRect(&rc, 0, 0, LOWORD(lParam), HIWORD(lParam)); 
                    TabCtrl_AdjustRect(g_hwndTab, FALSE, &rc); 
     
                    // Size the tab control to fit the client area. 
                    hdwp = BeginDeferWindowPos(2); 
                   DeferWindowPos(hdwp, g_hwndTab, NULL, 0, 0, LOWORD(lParam),        HIWORD(lParam), SWP_NOMOVE | SWP_NOZORDER); 
     
                    // Position and size the static control to fit the 
                    // tab control's display area, and make sure the 
                    // static control is in front of the tab control. 
                    DeferWindowPos(hdwp, g_hwndDisplay, HWND_TOP, 10, 50, 200, 20,0); 
                    DeferWindowPos(hdwp, hEditTab, HWND_TOP, 100, 100, 100, 100, 0);
    				EndDeferWindowPos(hdwp); 
                } 
                break; 
     
            case WM_NOTIFY: 
    	{
    	if(LOWORD(wParam) == IDC_TABCTRL)
    	{
    	if(HIWORD(wParam) == TCN_SELCHANGE)
    	{
    		if(SendMessage(g_hwndTab,TCM_GETCURSEL,0,0) == 0)
    		{ 
    							
    		ShowWindow(g_hwndDisplay,SW_SHOW);
    		ShowWindow(hEditTab,SW_HIDE);
    		}
    		if(SendMessage(g_hwndTab,TCM_GETCURSEL,0,0) == 1)
    		{
    							
    		   ShowWindow(g_hwndDisplay,SW_HIDE);
    	SetWindowLong(hEditTab,GWL_STYLE,WS_VISIBLE | WS_CHILD  | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL);
    							
    SendMessage(hEditTab,WM_SHOWWINDOW,TRUE,0);
    FORWARD_WM_NOTIFY(hwnd,IDC_TABCTRL,&lpnmhdr,SendMessage);
    		}
    	}
               }
                
                }
    	break; 
    	case WM_COMMAND:
    	switch(LOWORD(wParam))
    	{
    		case ID_NEWCOMPANY1:
    		break;
    	}
    	break;
    
    	return DefMDIChildProc(hwnd, msg, wParam, lParam);
    	default:
    	return DefMDIChildProc(hwnd, msg, wParam, lParam);
    	
    	}
    	return 0;
    }
    
    HWND CreateNewMDIChild1(HWND g_hMDIClient)
            {
                    MDICREATESTRUCT mcs;
                    
    
                    mcs.szTitle = "Company Information";
                    mcs.szClass = g_szChild1ClassName;
                    mcs.hOwner = GetModuleHandle(NULL);
                    mcs.x = 0;
    	    mcs.cx = 810;
                    mcs.y =  0;
    	    mcs.cy = 550;
                    mcs.style = MDIS_ALLCHILDSTYLES;
    
                    hChild1 = (HWND)SendMessage(g_hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
    
                    if(!hChild1)
                            {
                            MessageBox(g_hMDIClient, "MDI Child creation failed.", "Oh Oh...", MB_ICONEXCLAMATION | MB_OK);
                            }
                    return hChild1;
            }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    After a brief read...

    if(HIWORD(wParam) == TCN_SELCHANGE)

    Is this line working?
    I don't think the wParam is the event type (for TAB controls). I think it is a pointer to a NMHDR struc where the 'code' contains TCN_SELCHANGE.

    Otherwise....

    I dont use DeferWindowPos() but I think you have not got the offset right, as the coords are relative to the MDI (which is the Display and edits parent) not the TAB controls client area.

    Can you post the DoCreateDisplayWindow and DoEditCreation functions?

    Are they HWND_TOPMOST? Have you got the right HWND passed in?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tab Orders (Child Controls)
    By (TNT) in forum Windows Programming
    Replies: 6
    Last Post: 07-14-2006, 07:11 AM
  2. Tab Ordering of GUI Controls
    By cloudy in forum Windows Programming
    Replies: 2
    Last Post: 04-22-2006, 09:13 AM
  3. Using the VS.NET form designer with tab controls
    By bennyandthejets in forum Windows Programming
    Replies: 1
    Last Post: 07-06-2004, 12:49 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Tab controls - MFC (revived)
    By Robert602 in forum Windows Programming
    Replies: 1
    Last Post: 01-22-2002, 12:32 PM