Stack Window


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


Sample Image

Overview on stack window

The stack window gives alternative way to manage multiple dialog boxes inside single window (see picture). Unlike standard property sheet control layout of stack window is vertical. Pages are separated with captions. Page captions displays user-defined name and can be clicked to expand/contract the page. If size of stack window exceeds size of parent's client area user can pan window contents by clicking and dragging on the whitespace area or static/disabled control of child dialog box.

How to use stack window in your application

1. Add member variable in your CMainFrame class:

CStackWnd m_wndStack;

2. Create stack window during main frame creation

   int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_wndStack.Create(NULL, NULL, WS_CHILD | WS_VISIBLE,
		CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
		TRACE0("Failed to create view window\n");
		return -1;


3. Create dialog box template and dialog box class. Dialog box should be invisible child.

4. Insert a page into stack window

CDialog* pDlg;
pDlg = new CMyDialog;
m_wndStack.InsertPage(pDialog, IDD_MY_DIALOG, _T("My dialog"),

5. Return to step 3 to add more pages.

Page flags

The combination of following values can be passed to dwFlags parameter of CStackWnd::InsertPage:

Page is visible

Page is contracted (i.e. only caption is visible)


You should ensure the size of parent window is less or equal to size of the child stack window.


Download demo project - 64 Kb
Download source - 9 Kb


  • Stack Window

    Posted by Legacy on 12/28/1999 08:00am

    Originally posted by: Masoud

    Hi every body,

    Cool thing!, But i've been trying to add it to a CFormView
    inside the LefPane of a splitted (2,1) child view app.

    It don't give what i want, instead it loads only the empty form without the stack window or the controls dialog pages on it, just plane sheet!

    I wonder any one can help?

    Thank you and Merry Xmas with wishes for a very happy 2000.


  • used sample to create a dialogbar

    Posted by Legacy on 10/11/1999 07:00am

    Originally posted by: wolfram

    wow, very good.
    I used the StackWnd class as a sample to create a cool dialogbar. I devired the StackWnd class from CControlBar instead of CWnd and added some changes for control bar behavier. If someone would like to get the code, send a mail and i will publish it here.

  • not really a bug, but it's better to be fixed ..

    Posted by Legacy on 09/09/1999 07:00am

    Originally posted by: alexander

    First of all, this is really cool stuff.

    As to the problem : you are missing DT_SINGLELINE flag in CDC::DrawText() call, thus making DT_VCENTER flag meaningless (refer to the mfc docs). See code below for the fix.

    Another comment is that I believe it would be more appropriate to define member variable of type CFont and initialize it once (say, in [PrecreateWindow]) and then just use it in [DrawPageCaption]. Plus you would be able more accurately compute the value of [m_cyCaption] as it depends on the font chars.

    void CStackWnd::DrawPageCaption(...)

    if (lpszText)

    pDC->DrawText(lpszText, lpRect,


  • Memory leaks :(

    Posted by Legacy on 09/01/1999 07:00am

    Originally posted by: Jack

    Nice job, but on closing of stack window
    dialogs stays in the memory.

    The solution is:

    void CStackWnd::ClearPageInfo()
    CPageInfo* ptr = m_pPageInfo, *ptrNext;
    while (ptr)
    ptrNext = ptr->m_pNext;

    // !! This line solve the problem:
    delete ptr->m_pDlg;

    delete ptr;
    ptr = ptrNext;

    m_pPageInfo = NULL;

  • Suggestion: indicators

    Posted by Legacy on 08/19/1999 07:00am

    Originally posted by: Tomaz Stih

    It`s a cool class. How about a little improvement? Since there is no scroll bar user has no way of knowing that there is more info above the window limit. Maybe adding cool looking up and down indicators would be an improvement.


  • Font Problems under Win98 1st Edition

    Posted by Legacy on 08/15/1999 07:00am

    Originally posted by: Wraith Zero

    All in all, a nice little feature!  Thanks for the contribution!

    However, in testing I encountered some problems with fonts on the page captions ...

    In the DrawPageCaption() method, simply replace the existing

    if (lpszText)

    clause with the one below:

    // draw text
    if (lpszText)
    CFont font;
    LOGFONT lf;
    WU_GetDefaultGUIFont(8, &lf);

    //$ WRAITH: Preserve previous font
    CFont *pfontOld = (CFont*)pDC->SelectObject(&font);

    pDC->DrawText(lpszText, lpRect, DT_CENTER | DT_VCENTER);

    //$ WRAITH: Restore original font

    Also, I've found some painting anomalies which occur when dragging the client area around and resizing the dialog to its full normal size ... though I haven't had the time to look into it yet.

    Thanks for the great work and keep 'em coming!

    - Wraith Z

  • Круто

    Posted by Legacy on 08/05/1999 07:00am

    Originally posted by: Alex II

    Просто круто

  • Way Cool!

    Posted by Legacy on 07/29/1999 07:00am

    Originally posted by: Alex

    Nice job, Tim! It's got that 3D Studio MAX look and feel.

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date