Click here to Skip to main content
12,950,618 members (58,259 online)
Click here to Skip to main content


76 bookmarked
Posted 9 Mar 2002

XGetopt - A Unix-compatible getopt() for MFC and Win32

, 20 May 2003 CPOL
XGetopt provides drop-in Unix-style command line processing for Win32 and MFC applications
// XListBox.h
// Author:  Hans Dietrich
// This software is released into the public domain.
// You are free to use it in any way you like.
// This software is provided "as is" with no expressed
// or implied warranty.  I accept no liability for any
// damage or loss of business that this software may cause.

#ifndef XLISTBOX_H
#define XLISTBOX_H

//  CXListBox class

class CXListBox : public CListBox
// Constructors

// Attributes
	int				m_cxExtent;
	int				m_nTabPosition;
	BOOL			m_bColor;
	COLORREF		m_ColorWindow;
	COLORREF		m_ColorHighlight;
	COLORREF		m_ColorWindowText;
	COLORREF		m_ColorHighlightText;

	// NOTE - following list must be kept in sync with ColorPickerCB.cpp

	enum Color { Black,  White, Maroon,  Green,
				 Olive,  Navy,  Purple,  Teal,
				 Silver, Gray,  Red,     Lime,
				 Yellow, Blue,  Fuschia, Aqua };

	void EnableColor(BOOL bEnable);

// Operations
	void AddLine(Color tc, Color bc, LPCTSTR lpszLine);
	void AddString(LPCTSTR lpszItem);
	int FindString(int nStartAfter, LPCTSTR lpszItem) const;
	int FindStringExact(int nStartAfter, LPCTSTR lpszItem) const;
	int GetText(int nIndex, LPTSTR lpszBuffer) const;
	void GetText(int nIndex, CString& rString) const;
	int GetTextLen(int nIndex) const;
	int GetTextWithColor(int nIndex, LPTSTR lpszBuffer) const;
	void GetTextWithColor(int nIndex, CString& rString) const;
	int GetVisibleLines();
	int InsertString(int nIndex, LPCTSTR lpszItem);
	void _cdecl Printf(Color tc, Color bc, UINT nID, LPCTSTR lpszFmt, ...);
	virtual void ResetContent();
	int SelectString(int nStartAfter, LPCTSTR lpszItem);
	void SetContextMenuId(UINT nId) { m_nContextMenuId = nId; }
	virtual void SetFont(CFont *pFont, BOOL bRedraw = TRUE);
	void SetTabPosition(int nSpacesPerTab);

// Implementation
	int SearchString(int nStartAfter, LPCTSTR lpszItem, BOOL bExact) const;

	#define MAXTABSTOPS 100
	int m_nTabStopPositions[MAXTABSTOPS];
	int m_nSpaceWidth;
	int m_nAveCharWidth;
	UINT m_nContextMenuId;

	virtual int  CompareItem (LPCOMPAREITEMSTRUCT lpCIS);
	virtual void DrawItem (LPDRAWITEMSTRUCT lpDIS);
	virtual void MeasureItem (LPMEASUREITEMSTRUCT lpMIS);

	// Generated message map functions
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnEditCopy();
	afx_msg void OnEditClear();
	afx_msg void OnEditSelectAll();


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.


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


About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 21 May 2003
Article Copyright 2002 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid