1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#ifndef LISTVIEW_H
#define LISTVIEW_H
#include <commctrl.h>
class ListView
{
HWND hwnd;
int id;
int columns;
unsigned int style;
public:
ListView(){ id=0; columns=0; style=0; hwnd=0;}
// Create a ListView
HWND Create(const HWND hParent,const HINSTANCE hInst,DWORD dwStyle,const RECT& rc,const int id);
// Destroiy ListView
void Destroy();
// Add a column at specified pos
int AddColumn(const char *str,int width,int pos);
// Add a column at the end
int AddColumn(const char *str,int width);
// Inserts a new item
int InsertItem(const char *str);
// Set item data
int SetItem(const char*str,int row,int col);
// Add style
unsigned int AddStyle(unsigned int _style);
// Remove style
unsigned int RemoveStyle(unsigned int _style);
};
unsigned int ListView::AddStyle(unsigned int _style)
{
style|=_style;
ListView_SetExtendedListViewStyle(hwnd,style);
return style;
}
unsigned int ListView::RemoveStyle(unsigned int _style)
{
style&=(~_style);
ListView_SetExtendedListViewStyle(hwnd,style);
return style;
}
int ListView::SetItem(const char*str,int row,int col)
{
LVITEM tmp={LVIF_TEXT, row,col, 0,0, (char*)str,0, 0,0 };
ListView_SetItem(hwnd, &tmp);
}
int ListView::InsertItem(const char *str)
{
LVITEM tmp={LVIF_TEXT, 0,0, 0,0, (char*)str,0, 0,0 };
ListView_InsertItem(hwnd, &tmp);
}
int ListView::AddColumn(const char *str,int width,int pos)
{
int ColumnMask = LVCF_TEXT|LVCF_FMT|LVCF_SUBITEM|LVCF_WIDTH;
LVCOLUMN lvc={ ColumnMask, 0, width, (char*)str, 0, 0 };
ListView_InsertColumn(hwnd, pos, &lvc);
return pos;
}
int ListView::AddColumn(const char *str,int width)
{
int ColumnMask = LVCF_TEXT|LVCF_FMT|LVCF_SUBITEM|LVCF_WIDTH;
LVCOLUMN lvc={ ColumnMask, 0, width, (char*)str, 0, 0 };
ListView_InsertColumn(hwnd, ++columns, &lvc);
return columns;
}
HWND ListView::Create(const HWND hParent,const HINSTANCE hInst,DWORD dwStyle,const RECT& rc,const int id)
{
dwStyle|=WS_CHILD|WS_VISIBLE;
hwnd=CreateWindowEx(0, //extended styles
WC_LISTVIEW, //control 'class' name
0, //control caption
dwStyle, //wnd style
rc.left, //position: left
rc.top, //position: top
rc.right, //width
rc.bottom, //height
hParent, //parent window handle
//control's ID
reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
hInst, //instance
0); //user defined info
return hwnd;
}
void ListView::Destroy()
{
DestroyWindow(hwnd);
}
#endif
|