Click to See Complete Forum and Search --> : SDI question???


axr0284
February 2nd, 2005, 12:47 PM
Hi,
anybody knows if there is a way to set a dialog box as the topmost window (Above the CView object) in an SDI project. Thanks
Amish

Mutilated1
February 2nd, 2005, 01:10 PM
If you mean can you attach a Dialog Bar to a CView, then yes thats pretty easy. But if you mean can a CView have a CDialog parent, then no you cannot to do that.

axr0284
February 2nd, 2005, 01:33 PM
If you mean can you attach a Dialog Bar to a CView, then yes thats pretty easy. But if you mean can a CView have a CDialog parent, then no you cannot to do that.

Thanks for the reply. I have been trying to set up tabs in an SDI program and I can't find any SIMPLE explanation of how to do it. Anybody would know where I could go for that. Thanks
Amish

Mutilated1
February 2nd, 2005, 02:38 PM
Oh so you want a tabbed view right ?

That should not be really hard, you just use a CFormView for your view class and use a CTabCtrl on the view with some creative resizing should work nicely.

You might also try the VIEWEX (http://download.microsoft.com/download/VisualStudioNET/Sample/7.0/NT5XP/EN-US/mfc_general_viewex.exe) sample to get an idea of some ways you can use views effectively.

axr0284
February 3rd, 2005, 08:58 AM
Oh so you want a tabbed view right ?

That should not be really hard, you just use a CFormView for your view class and use a CTabCtrl on the view with some creative resizing should work nicely.

You might also try the VIEWEX (http://download.microsoft.com/download/VisualStudioNET/Sample/7.0/NT5XP/EN-US/mfc_general_viewex.exe) sample to get an idea of some ways you can use views effectively.

Thanks for pointing that program to me. It will definitly be helpful.
Amish

axr0284
February 3rd, 2005, 09:17 AM
I was wondering if I should make an SDI application or an MDI application to use with tabControl. Thanks
Amish

Mutilated1
February 3rd, 2005, 12:36 PM
Well that depends if you want multiple documents or not. The Tab Control will interact with the View in the same way regardless of which one you pick.

axr0284
February 3rd, 2005, 01:31 PM
hi,
I tried implementing the tab control but I am getting an assertion error:
This is the code I am using:

// RemoteView.cpp : implementation of the CRemoteView class
//

#include "stdafx.h"
#include "Remote.h"

#include "RemoteDoc.h"
#include "RemoteView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CRemoteView

IMPLEMENT_DYNCREATE(CRemoteView, CFormView)

BEGIN_MESSAGE_MAP(CRemoteView, CFormView)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnTabChange)
END_MESSAGE_MAP()

// CRemoteView construction/destruction

CRemoteView::CRemoteView()
: CFormView(CRemoteView::IDD)
{
// TODO: add construction code here

CRect r;
TCITEM tci;
// get dimensions of client area
GetClientRect(&r);
// create tab control
theTabControl.Create(WS_VISIBLE | WS_CHILD,r, this, IDC_TAB1);
tci.mask = TCIF_TEXT;
tci.iImage = -1;
tci.pszText = "One";
theTabControl.InsertItem(0, &tci);
tci.pszText = "Two";
theTabControl.InsertItem(1, &tci);
tci.pszText = "Three";
theTabControl.InsertItem(2, &tci);
}

CRemoteView::~CRemoteView()
{
}

void CRemoteView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
}

BOOL CRemoteView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CFormView::PreCreateWindow(cs);
}

void CRemoteView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit(false);
//initializeTabs();
}

// CRemoteView message handlers
afx_msg void CRemoteView::OnTabChange(NMHDR *hdr,LRESULT *NotUsed)
{
CClientDC DC(this);
char str[255];
wsprintf(str, "Changed to Tab %d ",
theTabControl.GetCurSel()+1);
DC.SetBkColor(RGB(200, 200, 200));
DC.TextOut(40, 100, str, strlen(str));
}


The assertion is occuring in the constructor when GetClientRect(&r) is run.
The assertion error is occuring here:

_AFXWIN_INLINE void CWnd::GetClientRect(LPRECT lpRect) const
{ ASSERT(::IsWindow(m_hWnd)); ::GetClientRect(m_hWnd, lpRect); }

It seems it can't find m_hWnd. I was wondering if anybody knew a way around that or could explain why it is so. Thanks
Amish

Mutilated1
February 3rd, 2005, 03:10 PM
You see this line of code:

theTabControl.Create(WS_VISIBLE | WS_CHILD,r, this, IDC_TAB1);

there is your problem. All the code that is related to creating a window will need to happen someplace other than the constructor, because in your constructor, your window has not been created yet.

typically you put code like that in OnInitialUpdate, not in the constructor

axr0284
February 4th, 2005, 08:13 AM
Thanks for the answer. That works.
Amish