Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / MFC

Simple Snap-to-Grid cursor to your graphics application

Rate me:
Please Sign up or sign in to vote.
4.98/5 (23 votes)
26 Oct 20024 min read 117.4K   7K   74  
Simple Class to add Snap-to-Grid capability to a Windows drawing program.
// SnapCursorDemoView.h : interface of the CSnapCursorDemoView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_SNAPCURSORDEMOVIEW_H__AF2C387E_C51C_4573_918F_945606FDD0E6__INCLUDED_)
#define AFX_SNAPCURSORDEMOVIEW_H__AF2C387E_C51C_4573_918F_945606FDD0E6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CSnapCursorDemoDoc;
class CSceneView;

class CSnapCursorDemoView : public CFormView
{
protected: // create from serialization only
	CSnapCursorDemoView();
	DECLARE_DYNCREATE(CSnapCursorDemoView)

public:
	//{{AFX_DATA(CSnapCursorDemoView)
	enum { IDD = IDD_SNAPCURSORDEMO_FORM };
	int		m_RadioSnapIncrement;
	//}}AFX_DATA

// Attributes
public:
	CSnapCursorDemoDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSnapCursorDemoView)
	public:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual void OnInitialUpdate(); // called first time after construct
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CSnapCursorDemoView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CSnapCursorDemoView)
	afx_msg void OnRadioSnapincrement5();
	afx_msg void OnRadioSnapincrement10();
	afx_msg void OnRadioSnapIncrement50();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in SnapCursorDemoView.cpp
inline CSnapCursorDemoDoc* CSnapCursorDemoView::GetDocument()
   { return (CSnapCursorDemoDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

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

#endif // !defined(AFX_SNAPCURSORDEMOVIEW_H__AF2C387E_C51C_4573_918F_945606FDD0E6__INCLUDED_)

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
United States United States
I am a hybrid CS and EE professional and 3D Animator/Modeler.

I have been a software developer since 1975, having coded in numerous languages, including C, C++, Java, Perl, Basic, PDP-11 and other assembly languages.

I have worked in the UNIX/C/Shellscript world as well as Windows/C++/Visual C++ platform areas.

I use 3DS MAX 7 for Animation and 3D modeling, combined with other graphics applications for overall production

I have worked on a wide variety of projects: language interpreters/compilers, graphics, automatic gpib test control programs, real-time automation in embedded systems, scientific and engineering applications as well as financial and business. I prefer the scientific, control system and engineering related software.

Major companies include Bell Labs, Singer Corporate Research and Tycom Submarine systems both as full-time and a contractor.

Other interests include Vacuum Tube collecting, Ham Radio (WA2WHV), Photography, 3D art, antiques, Abyssinian cats, Piano, travel, nature.

Comments and Discussions