Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi everybody,

Sorry for not stating the problem clearly yesterday.

I want to use tabcontrol in my win32 cpp project. Please check the code:
-------------------------------------------------------------------------------

C++
BOOL OnInitTabControlDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
{
    // Load and register Tab control class
    INITCOMMONCONTROLSEX iccx;
    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    iccx.dwICC = ICC_TAB_CLASSES;
    if (!InitCommonControlsEx(&iccx))
        return FALSE;

    // Create the Tab control 
    RECT rect;
    GetClientRect(hWnd, &rect);
	
	//|TCS_BOTTOM
    hTab = CreateWindowEx(0, WC_TABCONTROL, 0, 
        TCS_FIXEDWIDTH | WS_CHILD | WS_VISIBLE, 
        rect.left + 2, (rect.bottom-rect.top)/3*2 , rect.right - 4, rect.bottom - 4, 
        hWnd, (HMENU)IDC_TAB, hInst, 0);
		
    // Set the font of the tabs to a more typical system GUI font
    SendMessage(hTab, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);

    // Add items to the tab common control.
    InsertTabItem(hTab, "First Page", 0);
    InsertTabItem(hTab, "Second Page", 1);

     MoveWindow(hTab, 2, (rect.bottom-rect.top)/3*2, rect.right-rect.left,(rect.bottom-rect.top)/3, TRUE);
		
     /*
     SetWindowPos(hTab, 
                 HWND_TOP, 
                 rect.left + 2, 
                 (rect.bottom-rect.top)/3*2, 
                 rect.right-rect.left,(rect.bottom-rect.top)/3, SWP_SHOWWINDOW); 
   */

	//using 
	//  RECT rect;
	//have the same effect.

	RECT TabRect;//get the Rect of the tab 	
    GetClientRect(hTab,&TabRect);
	
	//create and add tab dialog
	h_TabDlg1=CreateDialog(hInst,MAKEINTRESOURCE(IDD_TabDIALOG1),hTab, TabDlgProc1);
    h_TabDlg2=CreateDialog(hInst,MAKEINTRESOURCE(IDD_TabDIALOG2),hTab, TabDlgProc2);

	MoveWindow(h_TabDlg1,TabRect.left+4,TabRect.top+4,TabRect.right -10,TabRect.bottom-15,true);
	MoveWindow(h_TabDlg2,TabRect.left+4,TabRect.top+4,TabRect.right -10,TabRect.bottom-15,true);
	
        /*
	SetWindowPos(h_TabDlg1, 
                 HWND_TOP, 
                TabRect.left+4, 
                 TabRect.top+4, 
                 TabRect.right -10,
				 TabRect.bottom-15,           
                 SWP_SHOWWINDOW); 

        */

	ShowWindow(h_TabDlg1,SW_SHOW); 

    return TRUE;
}


-------------------------------------------------------------------------------

No matter how hard I try, h_TabDlg1 and h_TabDlg2 display on the top left conner of the screen.

Can somebody tell me what's wrong with my code ?

ps: win7, vs2010

Sincerely,

Zhishang.
Posted
Updated 2-Jul-14 21:07pm
v4
Comments
CHill60 2-Jul-14 10:39am    
Avoid posting your email address on open forums - it's just asking for spam.
Also we don't email code out from here ... if you want someone to write your code for you like that you should look at RentACoder or similar site.
Try it yourself, then post a more specific question here if you have problems
Member 10362802 3-Jul-14 2:59am    
Thank you very much.

I have been a java programer and new to cpp, many details make me frustrated.

The question was undated, can you please check it and give me some suggestion?

Thanks.
Sergey Alexandrovich Kryukov 2-Jul-14 11:02am    
Do you have an idea on what software development is? It is not done by finding some pieces of code. It's done by writing code. What, if you need to "combine" a tab page with a text edit control, will it be another question or another search of sample code? This is counterproductive. Instead, write the code (prototype), and, if you face some problem you can clearly explain/demonstrate, we will gladly help you.
—SA
Member 10362802 3-Jul-14 3:02am    
Thanks, I have undated the question, can you please check it?

Looking forward to your reply,

Sincerely,

Zhishang
Sergey Alexandrovich Kryukov 3-Jul-14 11:25am    
Thank you.
CreateDialog creates top-level POPUP window, which can be moved by MoveWindow...
—SA

1 solution

This sounds quiet amazing article: Win32 SDK C Tab Control Made Easy which should answer your questions.

Why arent you do that stuff with resources and the MFC TabCtrl. The MFC is somehow glitchy but it does its job. :-O
 
Share this answer
 
Comments
Member 10362802 4-Jul-14 2:45am    
Thank you very much,

'Win32 SDK C Tab Control Made Easy' is very useful, but hard to compile for beginner, also it provide less detail on 'Operation'.

Because it is a win32 project, I can't enjoy 'MFC TabCtrl'.

But thanks against for your kindly help!

Sincerely,

Zhishang

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900