Click here to Skip to main content
15,884,537 members
Articles / Desktop Programming / MFC

ControlObjectList

Rate me:
Please Sign up or sign in to vote.
3.00/5 (6 votes)
16 Aug 2002CPOL 62.6K   2.1K   25  
Add/Remove/Scroll/Sort Object List (CButton, CStatic, etc..)
// FormatIcon.cpp : implementation file
//

#include "stdafx.h"
#include "Icon Manager.h"
#include "FormatIcon.h"
#include "FormatDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFormatIcon

CFormatIcon::CFormatIcon(CFormatDlg* pParent)
{
	m_pParent = pParent;
}

CFormatIcon::~CFormatIcon()
{
}


BEGIN_MESSAGE_MAP(CFormatIcon, CStatic)
	//{{AFX_MSG_MAP(CFormatIcon)
	ON_WM_LBUTTONDOWN()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFormatIcon message handlers
void CFormatIcon::AddFormat(CSize Size, int nColor, int nID)
{
	m_Size = Size;
	m_nColor = nColor;
	m_nID = nID;
}

void CFormatIcon::OnLButtonDown(UINT nFlags, CPoint point) 
{
	NotifyScroll();
	//CStatic::OnLButtonDown(nFlags, point);
}

void CFormatIcon::NotifyScroll()
{
	m_pParent->ScrollTo(m_Rect.top+(m_Rect.Height() / 2), m_nID);
}

void CFormatIcon::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CRect rc;
	CString szBuf;

	GetClientRect(rc);
	szBuf.Format("%dx%d\n%d (%d)", m_Size.cx , m_Size.cy, m_nColor, m_nID);
	dc.SetBkMode(TRANSPARENT); 
	dc.DrawText(szBuf, rc, DT_CENTER|DT_VCENTER);	
	// Do not call CStatic::OnPaint() for painting messages
}

void CFormatIcon::SetBoxRect(CRect rc, BOOL bRedraw)
{
	m_Rect = rc;
	if (bRedraw) {
		SetWindowPos(NULL, 0, m_Rect.top, 0, 0, SWP_NOSIZE);
	}
}

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)


Written By
CEO
Canada Canada

Comments and Discussions