Click here to Skip to main content
11,716,938 members (86,769 online)
Click here to Skip to main content
Add your own
alternative version

A Spell Checking Engine

, 5 Feb 2001 204.5K 5.6K 107
A free spell checking engine for use in your C++ applications. Includes the current US English dictionary
/*

  Copyright:		2000
  Author:			Matthew T Gullett
  Email:			gullettm@yahoo.com
  Name:				CFPSSpellingEditCtrl
  Part of:			Spell Checking Engine 
  Requires:			

  DESCRIPTION
  ----------------------------------------------------------
  This class is designed to implement a self spell-checking
  edit control.  It utilized the FPS Spell Checking Engine
  to provide dictionary and suggestion support.


  INFO:
  ----------------------------------------------------------
  This class is provided -as is-.  No warranty as to the
  function or performance of this class is provided either 
  written or implied.  
  
  You may freely use this code and modify it as necessary,
  as long as this header is unmodified and credit is given
  to the author in the application(s) in which it is
  incorporated.

*/


#if !defined(AFX_FPSSPELLINGEDITCTRL_H__74A6568D_680D_463D_A805_D928175A3A76__INCLUDED_)
#define AFX_FPSSPELLINGEDITCTRL_H__74A6568D_680D_463D_A805_D928175A3A76__INCLUDED_

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

#include "Afxtempl.h"
class CFPSSpellCheckEngine;

typedef struct FPSSPELLEDIT_ERRORSTAG
{
	CRect rctArea;
	CString strWord;
	int iChar;
} FPSSPELLEDIT_ERRORS;

typedef struct FPSSPELLEDIT_HOTKEYTAG
{
	BOOL bShift;
	BOOL bControl;
	BOOL bAlt;
	UINT uiKey;
} FPSSPELLEDIT_HOTKEY;


#define FPSSPELLEDIT_SPELL_CHECK_WAIT		1000
/////////////////////////////////////////////////////////////////////////////
// CFPSSpellingEditCtrl window

class CFPSSpellingEditCtrl : public CEdit
{
// Construction
public:
	virtual void AttachEdit(CWnd* pWnd, UINT uiControlID);
	static BOOL IsInitialized() {return m_pEngine != NULL;}
	static int InitSpellingEngine (LPCSTR lpszConfigFile = NULL);
	static void SetEngine(CFPSSpellCheckEngine* pEngine) {m_pEngine = pEngine;}
	CFPSSpellingEditCtrl();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CFPSSpellingEditCtrl)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

// Implementation
public:
	static void Terminate();
	static void SetHotKey(BOOL bShift, BOOL bControl, BOOL bAlt, UINT uiKey);
	virtual ~CFPSSpellingEditCtrl();

	// Generated message map functions
protected:
	virtual BOOL IsHotKey(MSG* pMsg, FPSSPELLEDIT_HOTKEY& HotKey);
	virtual void CheckSpelling();
	virtual BOOL IsPaintErrorsOK();
	virtual CString GetReplaceWord(int iPos);
	virtual void SelectAll();
	virtual void ReplaceSpellingError(UINT uid);
	virtual BOOL IsSelection();
	virtual FPSSPELLEDIT_ERRORS* FindError(CPoint pt);
	virtual void InvalidateSpellCheck();
	virtual void ClearSpellingErrors();
	virtual void DrawSquigly(CDC& dc, int iLeftX, int iWidth, int iY);
	virtual void DrawSpellingError(LPCSTR lpszWord, int iChar, CClientDC& dc);
	virtual void RedrawSpellingErrors(int iLine, int iLineLen, int iChar, LPCSTR lpszText, CClientDC& dc);
	virtual void RedrawSpellingErrors();
	//{{AFX_MSG(CFPSSpellingEditCtrl)
	afx_msg void OnPaint();
	afx_msg void OnChange();
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnDestroy();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnUpdate();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	//}}AFX_MSG
	afx_msg void OnAddWord();
	afx_msg void OnIgnoreWord();
	DECLARE_MESSAGE_MAP()

	CTypedPtrList<CPtrList, FPSSPELLEDIT_ERRORS*> m_SpellingErrors;

	static CFPSSpellCheckEngine* m_pEngine;
	UINT m_uiTimerID;
	DWORD m_dwLastTick;
	BOOL m_bErrorsDrawn;

	FPSSPELLEDIT_ERRORS*	m_pCurrentSel;
	CStringList				m_SpellingMatches;

	static FPSSPELLEDIT_HOTKEY		m_HotKey;

private:
};

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

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

#endif // !defined(AFX_FPSSPELLINGEDITCTRL_H__74A6568D_680D_463D_A805_D928175A3A76__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

Share

About the Author

Matt Gullett
Web Developer
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150901.1 | Last Updated 6 Feb 2001
Article Copyright 2001 by Matt Gullett
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid