CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    Aug 2009
    Posts
    84

    MFC TabControl Pages

    Hello everyone!!

    I've created a MFC Dialog Application, and I put a tabcontrol on it, then I've read somewhere to manage with pages I have to create modeless dialog template and class turning off titlebar and border, so I did.
    BUT, to put that modeless dialog template into the page of tabcontrol I've read also to use MoveWindow to position all of the dialogs on the control...what would that mean?...Since MoveWindow would change simply position and dimensions, how it would be used to put templates in tabcontrol's page?...

    Thanks
    Ciao,
    Luigi

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: MFC TabControl Pages

    Of course you have to have all your dialogs already created (by templates you mentioned), and have them all invisible except the one you currently show up.
    Best regards,
    Igor

  3. #3
    Join Date
    Aug 2009
    Posts
    84

    Re: MFC TabControl Pages

    Quote Originally Posted by Igor Vartanov View Post
    Of course you have to have all your dialogs already created (by templates you mentioned), and have them all invisible except the one you currently show up.
    Yes in fact I did that...I removed titlebar and border plus I settled visible = false... but how I can put that template in tabcontrol's page?...

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: MFC TabControl Pages

    See this sample. And forget about template. Template is a resource. Since a dialog is created (by a template), it's already window but not template.
    Last edited by Igor Vartanov; September 14th, 2009 at 02:00 PM.
    Best regards,
    Igor

  5. #5
    Join Date
    Aug 2009
    Posts
    84

    Re: MFC TabControl Pages

    Quote Originally Posted by Igor Vartanov View Post
    See this sample. And forget about template. Template is a resource. Since a dialog is created (by a template), it's already window but not template.
    Ehm, the link doesn't work....returns a 404 page....

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: MFC TabControl Pages

    Yep, sorry. Try this one.
    Best regards,
    Igor

  7. #7
    Join Date
    Aug 2009
    Posts
    84

    Re: MFC TabControl Pages

    Hiya Igor,

    I saw the template but that example refers to a non-resource modeless CDialog, when I need to have a template resource because I put controls on each like EditBox, RichEdit..etc etc...
    Actually I started with a main CDialog interface where I put from component's toolbox a tabcontrol and creating 4 tabpages...
    Then I created four CDialog class templates with resource where I removed border (Border = none), titlebar and settled Style as Child.
    In one of them I put another tabcontrol with 2 tabpages.
    The issue I have actually is I made a ShowTabDlg function as following your example:

    ShowTabDlg(int TabSel)
    {
    for(int idx=0; idx < ARRAYSIZE(m_dlg); idx++)
    m_dlg[idx]->ShowWindow(SW_HIDE);

    CRect rc;
    pTabDlg->GetClientRect(rc);
    pTabDlg->AdjustRect(FALSE, rc);
    pTabDlg->ClientToScreen(rc);
    m_dlg[tabSel]->SetWindowPos(NULL, rc.left, rc.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
    }

    and a OnSize (related to WM_SIZE message and ON_WM_SIZE() on begin_message_map) always for each tabpage:

    OnSize(UINT nType, int cx, int cy)
    {
    CDialog::OnSize(nType, cx, cy);

    CWnd* pWnd = GetDlgItem(IDC_TABPAGE1);
    if (pWnd)
    {
    CRect rect;
    pWnd->GetWindowRect(rect);
    ScreenToClient(rect);
    rect.right = cx - rect.left;
    rect.bottom = cy - 10;
    pWnd->MoveWindow(rect);
    }
    }

    BUT I couldn't get those CDialog templates fit in each TabPage....it goes like in the bottom-right of the main window if main CDialog isn't maximized and when maximized it goes indeed at almost the top-left of the tabcontrol... what could I have missed?...

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: MFC TabControl Pages

    that example refers to a non-resource modeless CDialog
    My sample deals with resource dialogs, you can easily see that in .rc file.

    what could I have missed?
    You've missed to upload a sample project (you could take mine) along with comprehensible description of your problems (maybe including screenshots).
    Best regards,
    Igor

  9. #9
    Join Date
    Aug 2009
    Posts
    84

    Re: MFC TabControl Pages

    Hello Igor and everyone...

    I figured out using easier's CPropertyPage and CPropertySheet which are similar to tabcontrol....
    BUT Just a little doubt: since I want to have a container component to put some controls like edit box, buttons, labels and stuff so I can reposition the container at the center when I resize the form and there is no Panel... I was thinking about creating something like a Frame...but how I could create a frame by resource then putting it in the PropertyPage since I don't see something like IDD_FRAME or whatever in the Dialog Resources.... (IDD_DIALOGBAR, IDD_FORMVIEW, IDD_OLE_PROPPAGE_LARGE...)

    Thanks
    Ciao,
    Luigi

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC TabControl Pages

    In MFC, for each property page, you create a dialog resource with the frame style set to 'child'.

    Then you create a class for the dialog derived from CPropertyPage.

    In the later versions of visual studio, to create a class, just right click on the dialog when opened in the resource studio, and choose "Add Class...".

    From there, choose CPropertyPage as the derived class.

    This will create the necessary CPropertyPage class that can be used with a CPropertySheet.

    In VC6, create the CPropertyPage derived class using the Class Wizard.

  11. #11
    Join Date
    Aug 2009
    Posts
    84

    Re: MFC TabControl Pages

    Hello Arjay,

    I did that! Just I'd like to have a container to keep some controls inside so I can "center" the container when I resize the dialog application window which resizes also the propertysheets....
    But I don't need to resize also the controls, indeed I need to center the controls in the propertysheet and I thought I'd do with a "container" like an IDD_FORMVIEW or so like it's a Frame container.... any idea?...

    Thanks
    Luigi

  12. #12
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC TabControl Pages

    Not sure of your approach. What I would do is replace the main application dialog with the propertysheet dialog in CMyWinApp::InitInstance( ).

  13. #13
    Join Date
    Aug 2009
    Posts
    84

    Re: MFC TabControl Pages

    I'm finding a way to have a container where to put some controls inside like edit box, labels, checkboxs because I tried to use a Group Box, then putting those controls inside and in OnSize of the CPropertyPage I put this:

    CWnd* pWnd = GetDlgItem(IDC_GRP_BOX);
    if (pWnd)
    {
    CRect rctDlg;

    pWnd->GetWindowRect(&rectDlg);
    ScreenToClient(&rectDlg);
    pWnd->MoveWindow(rectDlg.left, rectDlg.top, cx - 2 * rectDlg.left, cy - rectDlg.top - rectDlg.left, TRUE);
    }

    but the GroupBox doesn't keep inside the controls and move them where the GroupBox goes... so that's why I'm looking for a way to have a controls container which I can center in the CPropertyPage. In this way I was thinking about something like a Frame with a fixed dimensions where to fill with those controls; then load the Frame inside the CPropertyPage so in the OnSize I can MoveWindow the frame in the center of the CPropertyPage.
    So the question is how I can create a Frame-like with resources?...

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC TabControl Pages

    Groupbox isn't a control container like it is in a different environment like VB or .Net. In Win32 (i.e. MFC), GroupBox is just another control so you need to resize it like any other control.

    When you need to resize several controls within the OnSize handler, use DeferWindowPos to help reduce flickering.

    Code:
    void CMyDialog::OnSize(UINT state, int cx, int cy)
    {
      HDWP hdwp = BeginDeferWindowPos(3);
    
      if (hdwp) hdwp = DeferWindowPos(hdwp,
    m_GroupBoxCtrl.GetSafeHwnd( ),
        NULL, 0, 0, cx, cy,
        SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
    
      if (hdwp) hdwp = DeferWindowPos(hdwp,
    m_NameFirstCtrl.GetSafeHwnd( ),
        NULL, 10, 10, cx-20, 30,
        SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
      if (hdwp) hdwp = DeferWindowPos(hdwp,m_NameLastCtrl.GetSafeHwnd( ),
        NULL, 10, 50, cx-20, 30,
        SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
      if (hdwp) EndDeferWindowPos(hdwp);}
    Note: the actual size params aren't correct - I just threw in some values for the example.

  15. #15
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: MFC TabControl Pages

    Quote Originally Posted by npuleio View Post
    I'm finding a way to have a container where to put some controls inside like edit box, labels, checkboxs because I tried to use a Group Box...
    The container name is... a dialog. I have no idea why did you do that (finding a way to have a container other than the main dialog), but you always can have a child dialog window belonging to your main dialog. The evident demerit is: you need to have separate dialog procedure for a child dialog, and therefore, some way of communiction between the dialogs.
    Best regards,
    Igor

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured