Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A comprehensive CE class library to replace ATL and MFC

, 4 Oct 2000
A collection of classes for CE that do not use ATL or MFC, plus an FTP client, database viewer, and sample application that solves beam deflection equations.
kgwince-old.zip
WinCe
BeamEx
app.ico
BeamEx.dsp
BeamEx.dsw
BeamEx.ini
BeamEx.plg
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
calc.bmp
calc16.bmp
circ_cross.ico
cir_cross.ico
cross_4.ico
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico00005.ico
ico00008.ico
ico00009.ico
ico00010.ico
icon1.ico
icon2.ico
icon4.ico
id_downl.bmp
Install
BeamEx.inf
BeamEx.ini
BeamEx.MIPS_PPCBW.CAB
BeamEx.MIPS_PPCColor.CAB
BeamEx.SH3_PPCColor.CAB
Setup.exe
i_cross.ico
l_cross.ico
magenic.ico
mssccprj.scc
obl_corss.ico
obl_cross.ico
options.bmp
options1.bmp
ping16.bmp
rect_cross.ico
scene_5.ico
scene_6.ico
tri_cross.ico
vssver.scc
CeLib
CeLabel.inl
CeLib.aps
CeLib.dsp
CeLib.dsw
CeLib.old
CeLib.plg
CeLib.vcp
CeMisc.inl
CeProperty.inl
CeTab.inl
CeWnd.inl
mssccprj.scc
vssver.scc
WinLib.dsp
WinLib.dsw
dbView
bitmap1.bmp
bmp00001.bmp
db5.bmp
dbView.aps
DbView.dsp
dbView.dsw
dbView.old
dbView.plg
DbView.vcp
deldb.bp2
deldb5.bmp
delrec.bp2
delrecor.bmp
help16.bmp
help4.bmp
icon1.ico
icon2.ico
Install
dbView.inf
dbView.ini
Setup.exe
magenic.bmp
magenic.ico
mssccprj.scc
vssver.scc
ftpView
appicon.ico
bitmap1.bmp
bitmap2.bmp
bitmap3.bmp
bitmap4.bmp
bmp00001.bmp
bmp00002.bmp
db5.bmp
deldb.bp2
delrec.bp2
FtpView.dsp
ftpView.dsw
FtpView.old
ftpView.plg
FtpView.vcl
FtpView.vcp
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico171.ico
ico35.ico
icon1.ico
icon2.ico
imagelis.bmp
IMAGES.bmp
Install
ftpView.inf
ftpView.ini
Setup.exe
vssver.scc
magenic.bmp
magenic.ico
mssccprj.scc
options.bmp
options1.bmp
seperato.bmp
vssver.scc
Setup
ico101.ico
Setup.aps
Setup.dsp
setup.ico
Setup.plg
WinCe.dsw
WinLib.dsw
kgwince.zip
app.ico
BeamEx.dsp
BeamEx.dsw
BeamEx.ini
BeamEx.plg
BeamEx.vcl
BeamEx.vcp
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
calc.bmp
calc16.bmp
circ_cross.ico
cir_cross.ico
cross_4.ico
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico00005.ico
ico00008.ico
ico00009.ico
ico00010.ico
icon1.ico
icon2.ico
icon4.ico
id_downl.bmp
BeamEx.inf
BeamEx.ini
Setup.exe
i_cross.ico
l_cross.ico
magenic.ico
mssccprj.scc
obl_corss.ico
obl_cross.ico
options.bmp
options1.bmp
ping16.bmp
rect_cross.ico
scene_5.ico
scene_6.ico
tri_cross.ico
vssver.scc
CeFtp.vcp
CeFtp.vcw
CeLabel.inl
CeLib.aps
CeLib.dsp
CeLib.dsw
CeLib.plg
CeLib.vcl
CeLib.vcp
CeMisc.inl
CeProperty.inl
CeTab.inl
CeWnd.inl
mssccprj.scc
vssver.scc
WinLib.dsp
WinLib.dsw
bitmap1.bmp
bitmap2.bmp
bmp00001.bmp
db5.bmp
DbView.dsp
dbView.dsw
dbView.plg
DbView.vcl
DbView.vcp
deldb.bp2
deldb5.bmp
delrec.bp2
delrecor.bmp
help16.bmp
help4.bmp
icon1.ico
icon2.ico
dbView.inf
dbView.ini
Setup.exe
magenic.bmp
magenic.ico
menu1_5.bmp
mssccprj.scc
vssver.scc
appicon.ico
bitmap1.bmp
bitmap2.bmp
bitmap3.bmp
bitmap4.bmp
bmp00001.bmp
bmp00002.bmp
db5.bmp
deldb.bp2
delrec.bp2
FtpView.dsp
ftpView.dsw
ftpView.plg
FtpView.vcl
FtpView.vcp
FtpView.vcw
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico171.ico
ico35.ico
icon1.ico
icon2.ico
imagelis.bmp
IMAGES.bmp
ftpView.inf
ftpView.ini
Setup.exe
vssver.scc
magenic.bmp
magenic.ico
mssccprj.scc
newmenu.bmp
options.bmp
options1.bmp
rcdata1.bin
seperato.bmp
toolbar1.bmp
vssver.scc
WinCe.dsw
WinCe.vcw
#include "stdafx.h"
#include "CeTab.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CeTabCtrl

CeTabCtrl::~CeTabCtrl()
{
}

BOOL CeTabCtrl::Create(DWORD dwStyle, const RECT& rect, HWND hWndParent, UINT nID)
{
	return CeWnd::Create(NULL, WC_TABCONTROL, hWndParent, rect, NULL,
		dwStyle, 0, nID);
}

BOOL CeTabCtrl::InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem,
						   int nImage, LPARAM lParam, DWORD dwState,
						   DWORD dwStateMask)
{
	TCITEM item;

	item.mask = nMask;
	item.dwState = dwState;
	item.dwStateMask = dwStateMask;
	item.pszText = (LPTSTR) lpszItem;
    item.cchTextMax = lstrlen(lpszItem);
    item.iImage = nImage;
    item.lParam = lParam;

	return InsertItem(nItem, &item);
}


BOOL CeTabCtrl::InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem,
						   int nImage, LPARAM lParam)
{
	return InsertItem(nMask, nItem, lpszItem, nImage, lParam, 0, 0);
}



/////////////////////////////////////////////////////////////////////////////
// CeTabSheet

CeTabSheet::CeTabSheet()
{
    m_nActivePage = -1;
}


CeTabSheet::~CeTabSheet()
{
}


/////////////////////////////////////////////////////////////////////////////
// CeTabSheet message handlers

void CeTabSheet::AddPage(CeTabPage* pPage, int nBitmap /*=-1*/)
{
    ASSERT(pPage != NULL);
//    ASSERT(pPage->GetID() != 0);  // did you forget to overload this
    
    m_arPages.Add(&pPage);
    
    // add the item to the end of the tab
    int nItem;		// page's item number
    if ( ! (nItem = m_tabCtrl.InsertItem( m_tabCtrl.GetItemCount(), pPage->GetTabTitle(), nBitmap)) )
    {
        // first tab create
        pPage->Create(pPage->GetID(), m_hWnd);
        
        SetActivePage(nItem);
        
        CeRect rectWnd;
		GetPageRect(rectWnd);

        // convert to client coords
        ScreenToClient(rectWnd);
        
        // tab goes before ALL pages
        pPage->SetWindowPos(m_hWnd, rectWnd.left, rectWnd.top,
            rectWnd.Width(), rectWnd.Height(), SWP_NOACTIVATE);
        
//		if (GetStyle() & (KTCS_RIGHT|KTCS_BOTTOM))
//		{
//			// tab goes AFTER all pages, move it back
//			SetWindowPos(GetPage(nItem), 0, 0, 0, 0,
//				SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
//		}
    }
}

int CeTabSheet::FindPage(CeTabPage *pPage) const
{
    for (int ii = 0; ii < m_arPages.GetSize(); ii++)
        if (m_arPages[ii] == pPage)
	        return ii;
    
    return -1;
}

BOOL CeTabSheet::SetActivePage(CeTabPage* pPage)
{
    ASSERT(pPage != NULL);
    
    int nPage = FindPage(pPage);
    return (nPage < 0) ? FALSE: SetActivePage(nPage);
}

BOOL CeTabSheet::SetActivePage(int nPage)
{
    if (nPage == m_nActivePage)
        return TRUE;
    
    ASSERT(GetStyle() & WS_CHILD);
    HWND hParent = GetParent();
    
	CeTabPage* pPage = GetPage(nPage);
    CeRect rectWnd;

    // calc the area available for children
    GetPageRect(rectWnd);

    // convert to client coords
    ScreenToClient(rectWnd);
    
    if (! ::IsWindow(pPage->m_hWnd))
    {
        // first display do create
        pPage->Create(pPage->GetID(), m_hWnd);
        
		CeBaseWnd* pBefore = GetPage(0);
//        CeWnd* pWndBefore = (GetStyle() & (KTCS_RIGHT|KTCS_BOTTOM)) ?
//          (CWnd*)GetPage(0): (CWnd*)this;
        
        // set position before tab or after 'this'
        // tab goes before ALL pages
        pPage->SetWindowPos(pBefore->m_hWnd, rectWnd, SWP_NOACTIVATE);
    }
    
    // Hide the current window and then change the current window
    if (m_nActivePage >= 0)
    {
        // for sanity
        GetPage(m_nActivePage)->EnableWindow(FALSE);
        GetPage(m_nActivePage)->ShowWindow(FALSE);
    }
    
    pPage->MoveWindow(rectWnd);
    pPage->EnableWindow(TRUE);
    pPage->ShowWindow(TRUE);
    pPage->Invalidate();
    
    // transfer data
//    pPage->UpdateData(FALSE);
    
    m_nActivePage = nPage;
    
    // set focus to tab control
    SetFocus();
    return TRUE;
}

void CeTabSheet::RemovePage(CeTabPage *pPage)
{
    int nPage = FindPage(pPage);
    RemovePage(nPage);
}

void CeTabSheet::RemovePage(int nPage)
{
    m_arPages.Remove(nPage);		// remove the page from array
    m_tabCtrl.DeleteItem(nPage);	// remove the tab from control
    
    // fix up current page if neccessary
    if (nPage == m_nActivePage)
        if (m_arPages.GetSize() > 0)
        SetActivePage(m_arPages[0]);
    else
        m_nActivePage = -1;
}


LRESULT CeTabSheet::OnNotify(int nCtrlId, LPNMHDR pNMH, bool& bHandled)
{
	if (1000 == pNMH->idFrom)
	{
		switch (pNMH->code)
		{
		case TCN_SELCHANGE:
			bHandled = true;
			return OnNotifyTabChanged();
		case TCN_SELCHANGING:
			bHandled = true;
			return OnNotifyTabChanging();
		}
	}

	return TRUE;
}


LRESULT CeTabSheet::OnNotifyTabChanged()
{
    int nCurSel = m_tabCtrl.GetCurSel();
    if (nCurSel != -1)
        SetActivePage(nCurSel);
    
    // OK
    return 0;
}


LRESULT CeTabSheet::OnNotifyTabChanging() 
{
    CeTabPage *pPage = GetActivePage();
//	if (pPage && ! pPage->UpdateData())
//		// failed data transfer
//		return 1;

    return 0;
}


int CeTabSheet::OnCreate(LPCREATESTRUCT lpCS, bool& bHandled)
{
	CeRect rc(lpCS->x, lpCS->y, lpCS->x + lpCS->cx, lpCS->y + lpCS->cy);

	DWORD dwStyles =
		WS_VISIBLE |
		WS_CHILD |
		TCS_TABS |
		TCS_SINGLELINE |
		TCS_RAGGEDRIGHT |
		TCS_FOCUSNEVER;

    if (! m_tabCtrl.Create(dwStyles, rc, m_hWnd, 1000))
        return -1;
    
    bHandled = false;	// allow call to the default
    return 0;
}


void CeTabSheet::OnPaint( bool& bHandled )
{
    bHandled = false;
}

/*
BOOL CeTabSheet::OnEraseBkgnd(CDC* pDC)
{
    if (GetPageCount() > 0)
    {
        CRect rectWnd;
        
        // get the area available for children
        GetPageRect(rectWnd);
        ScreenToClient(rectWnd);
        
        // exclude it from painting
        pDC->ExcludeClipRect(rectWnd);
    }
    
    // Don't erase the children's area, we will
    // be either on top or below, if below we're painted last
    // and will over write, if on top then it will flash
    // more than neccassary if we do it so let the
    // child page erase instead
    return KXTabCtrl::OnEraseBkgnd(pDC);
}
*/

void CeTabSheet::OnSize( UINT nType, int cx, int cy, bool& bHandled )
{
    // Do base class adjustments
	CeRect rcClient;
	GetClientRect(rcClient);
	m_tabCtrl.SetWindowPos(NULL, rcClient,
		SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOZORDER);
    
    if (m_tabCtrl.GetItemCount() <= 0)
        return;
    
    // Size the active page to fit within borders
    CeRect rectWnd;
    GetPageRect(rectWnd);

    // convert to client coords
    ScreenToClient(rectWnd);
    
    // Note: want to keep Z-order, move and resize....
    GetActivePage()->SetWindowPos(NULL, rectWnd,
        SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOZORDER);
    GetActivePage()->Invalidate();
}

/*
BOOL CeTabSheet::ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags)
{
    if (m_tabCtrl.ModifyStyle(dwRemove, dwAdd, nFlags))
    {
        // Reposition child windows
        CeRect rectWnd;
        
        // calc the area available for children
        GetPageRect(rectWnd);

        // convert to client coords
        ScreenToClient(rectWnd);
        
        HWND hWndInsertAfter = m_hWnd;
        for (int ii = 0; ii < m_arPages.GetSize(); ii++)
        {
            // Note: want to keep Z-order, move and resize....
            // required to keep the tab order in line....
            
            CeTabPage* pPage = GetPage(ii);
            if (! ::IsWindow(pPage->m_hWnd))
                continue;
            
            pPage->SetWindowPos(hWndInsertAfter,
                rectWnd.left, rectWnd.top, rectWnd.Width(), rectWnd.Height(),
                SWP_NOACTIVATE|SWP_NOREDRAW);

            pWndInsertAfter = pPage->m_hWnd;
        }
        
        // fix ordering
//        if (GetStyle() & (KTCS_RIGHT|KTCS_BOTTOM))
//        {
//            // tab goes AFTER all pages, move it back
//            SetWindowPos(pWndInsertAfter, 0, 0, 0, 0,
//                SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW);
//        }
        
        GetPage(m_nActivePage)->Invalidate();
        return TRUE;
    }
    return FALSE;
}
*/

void CeTabSheet::GetPageRect(LPRECT lpRect)
{
	GetClientRect(lpRect);
	m_tabCtrl.AdjustRect(FALSE, lpRect);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Kenny G

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 5 Oct 2000
Article Copyright 2000 by Kenny G
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid