listbox.h

来自「一个自己写的游戏引擎,用DirectX 写成」· C头文件 代码 · 共 93 行

H
93
字号
//--------------------------------------------------
//  Desc: ListBox
//  Date: 2006.11.28 /update
//  Author: artsylee
//
//  Copyright (C) 2006 artsylee
//
//--------------------------------------------------

#ifndef _LISTBOX_
#define _LISTBOX_

#include <vector>
#include "Window.h"
#include "ScrollBar.h"
#include "../Core/Font.h"

struct ListBoxItem
{
	char	strText[256];
	void*	pData;

	RECT	rcActive;
	bool	bSelected;
};

enum STYLE 
{
	SINGLESELECTION	= 0,
	MULTISELECTION = 1,
};

#define FONT_HEIGHT		16

class ASE_DLL GListBox : public CWindow
{
public:
	GListBox(CWindow* pParent = NULL);
	virtual ~GListBox();

	virtual bool	LoadFromIni(char* pfilename, char* pIndex);
	virtual void	Render();
	virtual DWORD	ProcessEvent();
	virtual	void	OffSet(int x, int y);

	ListBoxItem*	GetItem(int nIndex);
	int				GetSelectedIndex(int nPreviousSelected = -1);
	ListBoxItem*	GetSelectedItem(int nPreviousSelected = -1);
	void			SelectItem(int nNewIndex, bool bPost = false);

	bool	AddItem(char *szText, void *pData);
	bool	InsertItem(int nIndex, char *szText, void *pData);
	void	RemoveItem(int nIndex);
	void	RemoveAllItems();

	DWORD	GetStyle()					{ return m_dwStyle;		}
	void	SetStyle(DWORD dwStyle)		{ m_dwStyle = dwStyle;	}
	int		GetSize()					{ return m_Items.size();}
	void	SetBorder(int nBorder, int nMargin);

protected:
	void		UpdateRect();
	void		RenderText();

protected:
	GScrollBar*		m_pScroll;
	GFont			m_Font;
	GRect			m_rcSelection;
	GRect			m_rcText;
	int				m_nBorder;
	int				m_nMargin;
	int				m_nTextHeight;

	DWORD			m_dwStyle;
	int				m_nSelected;
	int				m_nSelStart;
	bool			m_bDrag;
	DWORD			m_hBack;
	DWORD			m_hHighLight;

	std::vector<ListBoxItem*> m_Items;
};

class ASE_DLL CoolListBox : public GListBox
{
public:
	CoolListBox(CWindow* pParent = NULL);

	virtual bool	LoadFromIni(char* pfilename, char* pIndex);
	virtual void	Render();
};

#endif // _LISTBOX_

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?