Click here to Skip to main content
15,890,825 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Overflow in LPtoDP function Pin
Richard MacCutchan19-Oct-10 4:30
mveRichard MacCutchan19-Oct-10 4:30 
GeneralRe: Overflow in LPtoDP function Pin
ashtwin21-Oct-10 23:09
ashtwin21-Oct-10 23:09 
GeneralRe: Overflow in LPtoDP function Pin
Richard MacCutchan22-Oct-10 2:44
mveRichard MacCutchan22-Oct-10 2:44 
Questionstatic text box new line problem Pin
raju_shiva18-Oct-10 18:04
raju_shiva18-Oct-10 18:04 
AnswerRe: static text box new line problem Pin
vasu_sri18-Oct-10 19:01
vasu_sri18-Oct-10 19:01 
QuestionHow to use " CMFCPropertyGridProperty "to have a button Pin
stevenyes18-Oct-10 5:42
stevenyes18-Oct-10 5:42 
AnswerRe: How to use " CMFCPropertyGridProperty "to have a button Pin
Andrew Truckle28-Feb-24 7:58
professionalAndrew Truckle28-Feb-24 7:58 
QuestionOn the Origin of CTabCtrlEx used in Tabbed Dialogs Pin
federico.strati18-Oct-10 4:00
federico.strati18-Oct-10 4:00 
Hello,

this is a bit of a strange question: I have a CTabCtrlEx class
that was passed to me for doing tabbed dialog forms: in substance
it is a class that allows dialogs to be inscribed inside a
tabbed control. It is probably a well known class but I cannot find
the origin of it (maybe Jeff Prosise's, but I don't know for certain).
Hence the question is, do you know any reference to this class in
the literature ?

I attach here the class itself

---- header ----
#if !defined(AFX_TABCTRLEX_H__INCLUDED_)
#define AFX_TABCTRLEX_H__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TabCtrlEx.h : header file

#define TBC_NO_IMAGE			-1

class CTabCtrlEx : public CTabCtrl
{
private:
	BOOL m_bDeleteItemDlg;
	BOOL m_itemRectIsValid;
	CRect m_itemDlgRect;
	CDialog* m_pLastSelDlg;

public:
	CTabCtrlEx(BOOL bDeleteItemDlg = FALSE);
	~CTabCtrlEx();

	BOOL InitItem(UINT nIDTemplate, CDialog* pDlg, CDialog* pParent);

	int AddItem(LPTSTR lpczText, CDialog* pDlg, int nImage = TBC_NO_IMAGE);
	
	int GetItem(CDialog* pDlg);
	int GetItem(LPCTSTR lpczText);

	CDialog* GetNextItem(int nItem);
	
	BOOL RemoveItem(CDialog* pDlg);
	BOOL RemoveItem(LPCTSTR lpczText);
	
	void RemoveAllItems(BOOL bDeleteDlg);
	
	CDialog* GetSelectedItemDlg();
	BOOL SetSelectedItemDlg(CDialog* pDlg);
	
	void SetItemDlgRect(LPRECT lprect);
	BOOL GetItemDlgRect(LPRECT lprect);

	BOOL ShowSelectedItemDlg();

	virtual BOOL DestroyWindow();

protected:
	afx_msg void OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult);
	DECLARE_MESSAGE_MAP()	
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TABCTRLEX_H__INCLUDED_)

---- header ----

---- body ----
// TabCtrlEx.cpp : implementation file
//

#include "stdafx.h"
#include "TabCtrlEx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

/////////////////////////////////////////////////////////////////////////////
// CTabCtrlEx dialog
CTabCtrlEx::CTabCtrlEx(BOOL bDeleteItemDlg /*FALSE*/)
{
	m_bDeleteItemDlg = 	bDeleteItemDlg;
	m_itemRectIsValid = FALSE;
	m_pLastSelDlg = NULL;
}

CTabCtrlEx::~CTabCtrlEx()
{
}


BEGIN_MESSAGE_MAP(CTabCtrlEx, CTabCtrl)
	ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnTcnSelchange)
END_MESSAGE_MAP()

BOOL CTabCtrlEx::DestroyWindow()
{
	if(m_bDeleteItemDlg)
		RemoveAllItems(m_bDeleteItemDlg);
	return CTabCtrl::DestroyWindow();
}

int CTabCtrlEx::AddItem(LPTSTR lpczText, CDialog* pDlg, int nImage /*TBC_NO_IMAGE*/)
{
	int nItem = GetItemCount(); 	
	TCITEM item;
	item.mask = TCIF_TEXT|TCIF_PARAM;
	item.pszText = lpczText;
	item.lParam = (DWORD) pDlg; 	
	if(nImage != TBC_NO_IMAGE)
	{
		item.mask |= TCIF_IMAGE;
		item.iImage = nImage;
	}

	return InsertItem(nItem, &item); 	
}

BOOL CTabCtrlEx::InitItem(UINT nIDTemplate, CDialog* pDlg, CDialog* pParent)
{
	if(!pDlg->m_hWnd && !pDlg->Create(nIDTemplate, pParent))
		return FALSE;
	if(m_itemRectIsValid)
		pDlg->SetWindowPos(NULL, m_itemDlgRect.left, m_itemDlgRect.top, m_itemDlgRect.Width(), m_itemDlgRect.Height(), 
						SWP_NOZORDER|SWP_HIDEWINDOW);
	
	return TRUE;
}

int CTabCtrlEx::GetItem(CDialog* pDlg)
{
	TCITEM item;
	item.mask = TCIF_PARAM;
	
	int nCount = GetItemCount();
	for(int i = 0; i < nCount; i++)
		if(CTabCtrl::GetItem(i, &item) && item.lParam == (DWORD) pDlg)
			return i;
	return -1;
}

int CTabCtrlEx::GetItem(LPCTSTR lpczText)
{
	TCHAR czText[MAX_PATH];
	TCITEM item;
	item.mask = TCIF_TEXT;
	item.pszText = czText;
	item.cchTextMax = MAX_PATH - 1;
	
	int nCount = GetItemCount();
	for(int i = 0; i < nCount; i++)
		if(CTabCtrl::GetItem(i, &item) && _tcscmp(item.pszText, lpczText) == 0)
			return i;
	return -1;
}

CDialog* CTabCtrlEx::GetNextItem(int nItem)
{
	int nCount = GetItemCount();
	if(nItem >= nCount)
		return NULL;

	TCITEM item;
	item.mask = TCIF_PARAM;
	if(!CTabCtrl::GetItem(nItem, &item))
		return NULL;

	return (CDialog*) item.lParam;
}

BOOL CTabCtrlEx::RemoveItem(CDialog* pDlg)
{
	int nItem = GetItem(pDlg);
	return nItem >=0 ? CTabCtrl::DeleteItem(nItem) : FALSE; 
}

BOOL CTabCtrlEx::RemoveItem(LPCTSTR lpczText)
{
	int nItem = GetItem(lpczText);
	return nItem >=0 ? CTabCtrl::DeleteItem(nItem) : FALSE; 
}

void CTabCtrlEx::RemoveAllItems(BOOL bDeleteDlg)
{
	int nItem = 0;
	CDialog* pDlg = GetNextItem(nItem);
	while(pDlg)
	{
		CTabCtrl::DeleteItem(nItem);
		if(bDeleteDlg)
		{
			if(m_pLastSelDlg == pDlg)
				m_pLastSelDlg = NULL;
			pDlg->DestroyWindow();
			delete pDlg;
		}
		
		//Do not increment nItem: delete always first
		pDlg = GetNextItem(nItem);
	}
}

CDialog* CTabCtrlEx::GetSelectedItemDlg()
{
	int nSel = GetCurSel(); 
	if(nSel == -1)
		return NULL;
	TCITEM item;
	item.mask = TCIF_PARAM;
	if(!CTabCtrl::GetItem(nSel, &item))
		return NULL;

	return (CDialog*) item.lParam;
}

BOOL CTabCtrlEx::SetSelectedItemDlg(CDialog* pDlg)
{
	int nItem = GetItem(pDlg);
	nItem = SetCurSel(nItem);
	return nItem >= 0 ? TRUE : FALSE;
}

BOOL CTabCtrlEx::ShowSelectedItemDlg()
{
	CDialog* pCurSelDlg = GetSelectedItemDlg();
	if(m_pLastSelDlg == pCurSelDlg)
		return TRUE;
	if(m_pLastSelDlg)
		m_pLastSelDlg->ShowWindow(FALSE);
	m_pLastSelDlg = pCurSelDlg;
	if(m_pLastSelDlg)
		m_pLastSelDlg->ShowWindow(TRUE);

	return m_pLastSelDlg != NULL;
}

void CTabCtrlEx::SetItemDlgRect(LPRECT lprect) 
{ 
	m_itemDlgRect = lprect; 
	m_itemRectIsValid = TRUE; 
}

BOOL CTabCtrlEx::GetItemDlgRect(LPRECT lprect) 
{ 
	if(!lprect || !m_itemRectIsValid)
		return FALSE;
	
	lprect->top = m_itemDlgRect.top;
	lprect->left = m_itemDlgRect.left;
	lprect->bottom = m_itemDlgRect.bottom;
	lprect->right = m_itemDlgRect.right;

	return TRUE;
};

void CTabCtrlEx::OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult)
{
	ShowSelectedItemDlg();
	*pResult = 0;
}

---- body ----
AnswerRe: On the Origin of CTabCtrlEx used in Tabbed Dialogs Pin
Electron Shepherd18-Oct-10 6:16
Electron Shepherd18-Oct-10 6:16 
QuestionHow can get Domain name in given URL? Pin
Le@rner18-Oct-10 2:44
Le@rner18-Oct-10 2:44 
AnswerRe: How can get Domain name in given URL? Pin
Chris Losinger18-Oct-10 3:00
professionalChris Losinger18-Oct-10 3:00 
AnswerRe: How can get Domain name in given URL? Pin
Code-o-mat18-Oct-10 8:58
Code-o-mat18-Oct-10 8:58 
Questionfitnesse about C++ Pin
lxlenovostar18-Oct-10 2:12
lxlenovostar18-Oct-10 2:12 
AnswerRe: fitnesse about C++ Pin
Maximilien18-Oct-10 3:42
Maximilien18-Oct-10 3:42 
GeneralRe: fitnesse about C++ Pin
lxlenovostar18-Oct-10 3:59
lxlenovostar18-Oct-10 3:59 
GeneralRe: fitnesse about C++ Pin
Richard MacCutchan18-Oct-10 9:31
mveRichard MacCutchan18-Oct-10 9:31 
GeneralRe: fitnesse about C++ Pin
lxlenovostar18-Oct-10 15:57
lxlenovostar18-Oct-10 15:57 
GeneralRe: fitnesse about C++ Pin
Aescleal18-Oct-10 21:39
Aescleal18-Oct-10 21:39 
GeneralRe: fitnesse about C++ Pin
lxlenovostar18-Oct-10 23:12
lxlenovostar18-Oct-10 23:12 
GeneralRe: fitnesse about C++ Pin
lxlenovostar19-Oct-10 20:43
lxlenovostar19-Oct-10 20:43 
GeneralRe: fitnesse about C++ Pin
Aescleal20-Oct-10 7:36
Aescleal20-Oct-10 7:36 
QuestionProblem with SelectObject() Pin
ashtwin17-Oct-10 23:52
ashtwin17-Oct-10 23:52 
AnswerRe: Problem with SelectObject() Pin
Cedric Moonen18-Oct-10 0:05
Cedric Moonen18-Oct-10 0:05 
GeneralRe: Problem with SelectObject() Pin
ashtwin18-Oct-10 0:34
ashtwin18-Oct-10 0:34 
GeneralRe: Problem with SelectObject() Pin
Sauro Viti18-Oct-10 0:42
professionalSauro Viti18-Oct-10 0:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.