ifndef _MCONTROLS_HPP_ define _MCONTROLS_HPP_ include windows include

  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
118
119
120
121
122
123
#ifndef _MCONTROLS_HPP_
#define _MCONTROLS_HPP_
#include <windows.h>
#include <commctrl.h>
#include <iostream>
#include <string>
using namespace std;
// ListView
int lv_GetSelectedItem( HWND hwnd )
{
for (int i = ListView_GetItemCount(hwnd); i>=0; i--)
if ( ListView_GetItemState(hwnd, i, LVIS_SELECTED) == LVIS_SELECTED )
return i;
return -1;
}
int lv_InsertColum( HWND hList,
LPSTR szColumnName,
int iSubItem,
int iWidth,
UINT uiMask,
int iFormat )
{
LV_COLUMN lvc;
memset(&lvc, 0, sizeof(lvc));
lvc.mask = uiMask;
lvc.fmt = iFormat;
lvc.cx = iWidth;
lvc.iSubItem = iSubItem;
lvc.pszText = szColumnName;
return ListView_InsertColumn(hList, iSubItem, &lvc);
}
int lv_addItem( HWND hwndList, const char *wsCaption )
{
LV_ITEM lvi;
memset(&lvi, 0, sizeof(lvi));
int iIndex = ListView_GetItemCount(hwndList);
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
lvi.cchTextMax = 40;
lvi.iItem = iIndex;
//lvi.iImage = ImageList_GetImageCount(hImageList)-1;
lvi.iSubItem = 0;
lvi.pszText = LPSTR(wsCaption);
ListView_InsertItem(hwndList, &lvi);
return iIndex;
}
bool lv_addSubItem( HWND hwndList,
int iIndex,
int iSubItem,
const char *wsText )
{
if (iIndex >= 0 && iIndex < ListView_GetItemCount(hwndList))
{
ListView_SetItemText(hwndList, iIndex, iSubItem, (LPSTR)wsText);
}
else
{
return false;
}
return true;
}
std::string lv_getItemCaption( HWND hwndList, int iIndex )
{
std::string wsCaption;
if ( iIndex > 0 && iIndex < ListView_GetItemCount(hwndList) )
{
char szCaption[256] = {0};
ListView_GetItemText(hwndList, iIndex, 0, szCaption, 256);
wsCaption = szCaption;
}
return wsCaption;
}
std::string lv_getSubItemText( HWND hwndList, int iIndex, int iSubItem )
{
std::string wsText;
if ( iIndex > 0 && iIndex < ListView_GetItemCount(hwndList) )
{
char szText[256] = {0};
ListView_GetItemText(hwndList, iIndex, iSubItem, szText, 256);
wsText = szText;
}
return wsText;
}
int lv_findItemByCaption( HWND hwndList, const string & wsCaption )
{
for ( int i=0; i<ListView_GetItemCount(hwndList); i++ )
if ( lv_getItemCaption(hwndList, i) == wsCaption )
return i;
return -1;
}
int lv_findItem( HWND hwndList, int iSubItem, const string & wsString )
{
for ( int i = 0; i<ListView_GetItemCount(hwndList); i++ )
if ( lv_getSubItemText(hwndList, i, iSubItem) == wsString )
return i;
return -1;
}
#endif // _MCONTROLS_HPP_