Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / C#

Canvas implementation for C#

Rate me:
Please Sign up or sign in to vote.
4.43/5 (29 votes)
21 Mar 20044 min read 256.3K   9.6K   118  
Design and implementation of canvas in C#
// CanvasThreadDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CanvasThread.h"
#include "CanvasThreadDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCanvasThreadDlg dialog

CCanvasThreadDlg::CCanvasThreadDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCanvasThreadDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCanvasThreadDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCanvasThreadDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCanvasThreadDlg)
	DDX_Control(pDX, IDC_CANVAS, m_canvas);
	//}}AFX_DATA_MAP
	DDX_Control(pDX, IDC_SUNKEN, flat);
}

BEGIN_MESSAGE_MAP(CCanvasThreadDlg, CDialog)
	//{{AFX_MSG_MAP(CCanvasThreadDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_NCHITTEST()
	ON_BN_CLICKED(IDC_SUNKEN, OnRadio1)
	ON_BN_CLICKED(IDC_ABOVE, OnRadio2)
	ON_BN_CLICKED(IDC_FLAT, OnRadio3)
	ON_BN_CLICKED(IDC_OTHER, OnRadio4)
	ON_BN_CLICKED(IDC_LOW, OnLow)
	ON_BN_CLICKED(IDC_UP, OnUp)
	ON_BN_CLICKED(IDC_SIMPLE, OnSimple)
	ON_BN_CLICKED(IDC_LIGHT_FRAME, OnLightFrame)
	ON_BN_CLICKED(IDC_THIN_FRAME, OnThinFrame)
	ON_BN_CLICKED(IDC_THIN_LIGHT_FRAME, OnThinLightFrame)
	ON_BN_CLICKED(IDC_ETCHED, OnEtched)
	ON_BN_CLICKED(IDC_ETCHED2, OnEtched2)
	ON_WM_CHAR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCanvasThreadDlg message handlers

BOOL CCanvasThreadDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	flat.SetCheck(1);
//	m_canvas.SubclassDlgItem(IDC_CANVAS,this);

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCanvasThreadDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCanvasThreadDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

UINT CCanvasThreadDlg::OnNcHitTest(CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	UINT nHit = CDialog::OnNcHitTest(point);
	if ( nHit == HTCLIENT )
		nHit = HTCAPTION;
	return nHit;
}

void CCanvasThreadDlg::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::SUNKEN);
	m_canvas.Repaint();
}

void CCanvasThreadDlg::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::HIGH);
	m_canvas.Repaint();
}

void CCanvasThreadDlg::OnRadio3() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::FLAT);
	m_canvas.Repaint();
}

void CCanvasThreadDlg::OnRadio4() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::FRAME);
	m_canvas.Repaint();
}

void CCanvasThreadDlg::OnLow() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::LOW);
	m_canvas.Repaint();
}

void CCanvasThreadDlg::OnUp() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::UP);
	m_canvas.Repaint();
}

void CCanvasThreadDlg::OnSimple() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::SIMPLE);
	m_canvas.Repaint();	
}

void CCanvasThreadDlg::OnLightFrame() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::LIGHT_FRAME);
	m_canvas.Repaint();	
}

void CCanvasThreadDlg::OnThinFrame() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::THIN_FRAME);
	m_canvas.Repaint();	
}

void CCanvasThreadDlg::OnThinLightFrame() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::THIN_LIGHT_FRAME);
	m_canvas.Repaint();
}

void CCanvasThreadDlg::OnEtched() 
{
	// TODO: Add your control notification handler code here
	
	m_canvas.SetBorder(CTest::ETCHED);
	m_canvas.Repaint();	
}

void CCanvasThreadDlg::OnEtched2() 
{
	// TODO: Add your control notification handler code here
	m_canvas.SetBorder(CTest::ETCHED2);
	m_canvas.Repaint();	
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
Baranovsky Eduard has been a software developer for more then 10 years. He has an experence in image processing, computer graphics and distributed systems design.

Comments and Discussions