Hi Oleg,
I'm not exactly sure what you mean by "metrics", but the following code seems to work fine. And if you change the size of the tab control, this code adapts to the change the next time you run it.
I made this method part of the main dialog and call it from OnInitDialog():
void CMyDlg::InitTabControl()
{
TC_ITEM TabCtrlItem;
WINDOWPLACEMENT lpwndpl;
RECT r;
DWORD tHeight;
// Create the tab control
TabCtrlItem.mask = TCIF_TEXT;
TabCtrlItem.pszText = "Tab 1";
m_tab.InsertItem( 0, & TabCtrlItem );
TabCtrlItem.pszText = "Tab 2";
m_tab.InsertItem( 1, & TabCtrlItem );
// Create the two child dialogs that will appears to be
// the contents of the two "tabs"
m_tab_1.Create(IDD_DIALOG_TAB_1, NULL);
m_tab_2.Create(IDD_DIALOG_TAB_2, NULL);
// Adjust position of child dialogs so that they fit
// within the tab area
// Get the height of the "tab" in the tab control
m_tab.GetItemRect(0, & r );
tHeight= r.bottom - r.top;
// Get the full display rectangle of the tab control
// which includes the tab height
::GetWindowPlacement(m_tab.m_hWnd, & lpwndpl);
r= lpwndpl.rcNormalPosition;
// Adjust the vertical origin by the height of the "tab"
r.top += tHeight;
// Adjust the rectangle so that they fit just inside the
// actual tab control
r.left += 4;
r.top += 4;
r.right -= 4;
r.bottom -= 4;
// Convert right and bottom to width and height
r.right -= r.left;
r.bottom -= r.top;
// Set the new size and position of our child dialogs
::SetWindowPos(m_tab_1.m_hWnd, NULL
, r.left, r.top, r.right, r.bottom, SWP_NOZORDER);
::SetWindowPos(m_tab_2.m_hWnd, NULL
, r.left, r.top, r.right, r.bottom, SWP_NOZORDER);
return;
}
Thanks again,
Chris
Oleg Pilipenko wrote:
> If you have success playing around with Windows metrics, please let me know.
> I'm too busy this week, though I might need it by the end of the month.
> Take care!
> Oleg.
> Chris Severtson <ch...@microware.com> wrote in message
> news:377BCE4E.A7E92344@microware.com...
> > Thanks you very much for all your help :^)
> > I really apreciate it!
> > Chris
> > Oleg Pilipenko wrote:
> > > ResizeCurrentPage is a wrapper around SetWindowPos:
> > > void CRepBrowseCtrl::ResizeCurrentPage(int cx, int cy)
> > > {
> > > int cxPage = cx - 8;
> > > int cyPage = cy - 32;
> > > ::SetWindowPos(m_pPage[m_nCurTab]->m_hWnd,
> > > NULL,
> > > 4,
> > > 4,
> > > cxPage,
> > > cyPage,
> > > SWP_NOZORDER | SWP_NOACTIVATE);
> > > }
> > > It works OK for me, though to be absolutely precise, instead of using 8
> and
> > > 32 you have to calculate those deltas using Windows metrics.
> > > Oleg
> > > Chris Severtson <ch...@microware.com> wrote in message
> > > news:377B986B.A80B6156@microware.com...
> > > > Hi again Oleg,
> > > > I have the child dialogs set up and displaying. My last problem has to
> do
> > > with sizing and positioning these child dialogs such that they fall
> within
> > > the tab control (I cannot find ResizeCurrentPage() in any of the
> > > documentation I have). When I show the child dialogs, the appears in the
> > > upper left hand corner of the dialog.
> > > > I think I only have two questions left to get this finished:
> > > > 1) I get the rectangle of the tab control so that I know where to
> place
> > > the child dialogs, but this rectangle includes the tabs. Is there a
> constant
> > > or something that indicates how tall the tabs are so that I can take
> that
> > > into account?
> > > > Or, are you placing a dialog item over the tab control defining the
> area
> > > of the tab control in which you wanted the child dialogs to appear?
> > > > 2) Since I do not have a ResizeCurrentPage(), I was trying to do it
> with
> > > SetWindowPos() which, I discovered, sets that main dialog position (I
> was
> > > using the syntax "myChildDlg.FromHandle(myChildDlg.m_hWnd)" in
> > > SetWindowPos()).
> > > > I cannot find a method to adjust the size/position of the child
> dialogs,
> > > can you please point me in the right direction?
> > > > Thank you so much,
> > > > Chris
> > > > Oleg Pilipenko wrote:
> > > > > They are child, without border. Positioning of a child dialog inside
> tab
> > > > > control is done in the ResizeCurrentPage(). It is also called from
> the
> > > > > OnCreate/OnInitDialog of the parent for the page that is selected by
> > > > > default.
> > > > > Oleg
> > > > > Chris Severtson <ch...@microware.com> wrote in message
> > > > > news:377A1C48.96F5F41A@microware.com...
> > > > > > Thanks for the response Oleg!
> > > > > > I still have a question about your response though:
> > > > > > What kind of dialogs are these (Overlapped, Popup, Child)?
> > > > > > Did you have to position the upper left hand corner of these
> dialogs,
> > > or
> > > > > were they tied to something in the main dialog?
> > > > > > Thanks,
> > > > > > Chris
> > > > > > Oleg Pilipenko wrote:
> > > > > > > Here is a snippet from my code:
> > > > > > > void CRepBrowseCtrl::DoSelectTab(int nTab)
> > > > > > > {
> > > > > > > m_pPage[m_nCurTab]->ShowWindow(FALSE);
> > > > > > > m_nCurTab = nTab;
> > > > > > > m_pPage[m_nCurTab]->ShowWindow(TRUE);
> > > > > > > // Adjust current page size
> > > > > > > RECT rc;
> > > > > > > GetWindowRect(&rc);
> > > > > > > ResizeCurrentPage(rc.right - rc.left, rc.bottom - rc.top);
> > > > > > > }
> > > > > > > where m_pPage is an array of dialogs. This is a snippet from an
> > > > > ATL-based
> > > > > > > project, though I believe it contains enough info to do it in
> MFC.
> > > > > > > Good luck!
> > > > > > > Oleg
> > > > > > > Chris Severtson <ch...@microware.com> wrote in message
> > > > > > > news:3777D1CA.406E6306@microware.com...
> > > > > > > > I've looked at the resources I have online as well as msdn
> without
> > > > > luck.
> > > > > > > It is possible that I have not looked in the right place, or,
> this
> > > > > question
> > > > > > > is too simple to actually be written down.
> > > > > > > > I have a dialog application. To the dialog, I have added a
> > > CTabCtrl
> > > > > class
> > > > > > > variable named m_tab.
> > > > > > > > Then, in OnInitDialog() I added the following:
> > > > > > > > BOOL CULServerDlg::OnInitDialog()
> > > > > > > > {
> > > > > > > > ...
> > > > > > > > // TODO: Add extra initialization here
> > > > > > > > TC_ITEM TabCtrlItem;
> > > > > > > > TabCtrlItem.mask = TCIF_TEXT;
> > > > > > > > TabCtrlItem.pszText = "TAB 1";
> > > > > > > > m_tab.InsertItem( 0, &TabCtrlItem );
> > > > > > > > TabCtrlItem.pszText = "TAB 2";
> > > > > > > > m_tab.InsertItem( 1, &TabCtrlItem );
> > > > > > > > ...
> > > > > > > > }
> > > > > > > > My difficulty is that I am not finding out how to show
> controls on
> > > the
> > > > > two
> > > > > > > tabs when they are in front.
> > > > > > > > I already looked at the FIRE demo, and it's just showing an
> image.
> > > And
> > > > > the
> > > > > > > image is kept in all of the tabs so I do not see really how to
> > > > > > > display/change different controls for different tabs.
> > > > > > > > Also, can someone tell be a definition for "owner-drawn" and
> > > > > > > non-owner-drawn? And, which applies to CTabCtrl?
> > > > > > > > Thanks for any advice,
> > > > > > > > Chris