#pragma once
|
|
#include "wobject/xcontrol.hpp"
|
#include "win32/win.hpp"
|
|
|
typedef struct tagLVITEMW
|
{
|
UINT mask;
|
int iItem;
|
int iSubItem;
|
UINT state;
|
UINT stateMask;
|
LPWSTR pszText;
|
int cchTextMax;
|
int iImage;
|
LPARAM lParam;
|
int iIndent;
|
int iGroupId;
|
UINT cColumns; // tile view columns
|
UINT* puColumns;
|
int* piColFmt;
|
int iGroup; // readonly. only valid for owner data.
|
} LVITEMW, * LPLVITEMW;
|
|
typedef struct tagLVCOLUMNW
|
{
|
UINT mask;
|
int fmt;
|
int cx;
|
LPWSTR pszText;
|
int cchTextMax;
|
int iSubItem;
|
int iImage;
|
int iOrder;
|
int cxMin; // min snap point
|
int cxDefault; // default snap point
|
int cxIdeal; // read only. ideal may not eqaul current width if auto sized (LVS_EX_AUTOSIZECOLUMNS_) to a lesser width.
|
} LVCOLUMNW, * LPLVCOLUMNW;
|
|
typedef struct tagLVFINDINFOW
|
{
|
UINT flags;
|
LPCWSTR psz;
|
LPARAM lParam;
|
POINT pt;
|
UINT vkDirection;
|
} LVFINDINFOW, * LPFINDINFOW;
|
|
typedef LVITEMW lvitem;
|
typedef LVCOLUMNW lvcolumn;
|
typedef LVFINDINFOW lvfindinfo;
|
|
struct himagelist
|
{
|
};
|
|
struct imagelist
|
{
|
himagelist hlist;
|
};
|
|
struct NMLISTVIEW : public NMHDR
|
{
|
NMHDR hdr;
|
int iItem;
|
int iSubItem;
|
UINT uNewState;
|
UINT uOldState;
|
UINT uChanged;
|
POINT ptAction;
|
LPARAM lParam;
|
};
|
|
class xlistview : public xcontrol
|
{
|
static int SetdwStyle(HWND hWnd, int dwStyle)//设置风格
|
{
|
int GWL_STYLE_ = -16;
|
int LVS_ICON_ = 0x0000;//大图标
|
int LVS_REPORT_ = 0x0001;
|
int LVS_SMALLICON_ = 0x0002;
|
int LVS_LIST_ = 0x0003;//列表
|
|
int IStyle =GetWindowLong(hWnd, GWL_STYLE_);
|
int LVS_TYPEMASK_ = 0x0003;
|
int LVS_EDITLABELS_ = 0x0200;
|
IStyle &= ~LVS_TYPEMASK_;//清除显示方式位
|
return SetWindowLong(hWnd, GWL_STYLE_, IStyle | dwStyle);
|
}
|
static int SetReportStyle(HWND hWnd)//设置Report风格
|
{
|
//获得原有风格
|
int GWL_STYLE_ = -16;
|
int IStyle = GetWindowLong(hWnd, GWL_STYLE_);
|
int LVS_TYPEMASK_ = 0x0003;
|
int LVS_EDITLABELS_ = 0x0200;
|
IStyle &= ~LVS_TYPEMASK_;//清除显示方式位
|
|
//设定一个新的窗口风格
|
int LVS_REPORT_ = 0x0001;
|
int LVS_NOLABELWRAP_ = 0x0080;
|
int LVS_SHOWSELALWAYS_ = 0x0008;
|
IStyle |= LVS_REPORT_;//设置style为report
|
SetWindowLong(hWnd, GWL_STYLE_, IStyle | LVS_NOLABELWRAP_ | LVS_SHOWSELALWAYS_ | LVS_EDITLABELS_);
|
//设置扩展风格
|
int dwStyle;
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETEXTENDEDLISTVIEWSTYLE_ = LVM_FIRST_ + 55;
|
dwStyle = SendMessage(hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE_, 0, 0);//获取扩展风格
|
int LVS_EX_FULLROWSELECT_ = 0x00000020;//整行选中, applies to report mode only
|
int LVS_EX_GRIDLINES_ = 0x00000001; //网格线
|
int LVS_EX_SUBITEMIMAGES_ = 0x00000002;//可以在列表中加ICON
|
int LVS_EX_CHECKBOXES_ = 0x00000004;//前面加个checkbox
|
dwStyle |= LVS_EX_FULLROWSELECT_ | LVS_EX_GRIDLINES_ | LVS_EX_CHECKBOXES_ | LVS_EX_SUBITEMIMAGES_;
|
|
int LVM_SETEXTENDEDLISTVIEWSTYLE_ = LVM_FIRST_ + 54;
|
return SendMessage(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE_, dwStyle, dwStyle);
|
}
|
|
static int GetImageList(HWND hWnd, int iImageList)//ImageList
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETIMAGELIST_ = LVM_FIRST_ + 2;
|
return SendMessage(hWnd, LVM_GETIMAGELIST_, iImageList, 0);
|
}
|
static int SetImageList(HWND hWnd, int iImageList, int himl)//设置ImageList
|
{
|
/*int LVSIL_NORMAL_ = 0;
|
int LVSIL_SMALL_ = 1;
|
int LVSIL_STATE_ = 2;*/
|
int LVM_FIRST_ = 0x1000;
|
int LVM_SETIMAGELIST_ = LVM_FIRST_ + 3;
|
return SendMessage(hWnd, LVM_SETIMAGELIST_, iImageList, himl);
|
}
|
|
static int InsertColumn(HWND hWnd, int nCol, string label, int nFormat, int nWidth, int nSubItem)//增加列,加入列头
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_INSERTCOLUMN_ = LVM_FIRST_ + 97;
|
|
int LVCF_FMT_ = 0x0001;//对齐方式:left,right
|
int LVCF_WIDTH_ = 0x0002;//列宽度
|
int LVCF_TEXT_ = 0x0004;//文本
|
int LVCF_SUBITEM_ = 0x0008;//为分配给该列的列索引
|
int LVCF_ORDER_ = 0x0020;//列偏移顺序从左到右
|
int LVCFMT_LEFT_ = 0x0000;
|
int LVCFMT_RIGHT_ = 0x0001;
|
int LVCFMT_CENTER_ = 0x0002;
|
|
lvcolumn lvc;
|
lvc.mask = LVCF_FMT_ | LVCF_WIDTH_ | LVCF_TEXT_ | LVCF_SUBITEM_;//风格
|
lvc.fmt = nFormat;
|
|
xrect rect;
|
//GetWindowRect(hWnd,rect);//取得窗口在屏幕坐标系下的RECT坐标(包括客户区和非客户区),这样可以得到窗口的大小和相对屏幕左上角(0,0)的位置。
|
//GetClientRect;
|
lvc.cx = nWidth;//(rect.right - rect.left ) * 3/5; //LVCF_WIDTH ,Width of the column, in pixels.
|
lvc.pszText = (LPWSTR)label;//文字
|
lvc.cchTextMax = 255;
|
lvc.iSubItem = nSubItem;
|
lvc.iImage = 0;
|
lvc.iOrder = 0;
|
return SendMessage(hWnd, LVM_INSERTCOLUMN_, nCol, (LPARAM) & lvc);
|
}
|
|
static int InsertItem(HWND hWnd, int xIndex, string label, int pictureindex = 0)//only the label and picture index need to be specified
|
{
|
int LVM_FIRST_ = 0x1000;// ListView messages
|
int LVM_INSERTITEM_ = LVM_FIRST_ + 77;
|
|
//LVITEM_mask
|
//int LVIF_COLFMT
|
//int LVIF_COLUMNS_ = 0x0200;
|
int LVIF_DI_SETITEM_ = 0x1000;
|
//int LVIF_GROUPID_ = 0x0100;
|
int LVIF_IMAGE_ = 0x0002;
|
//int LVIF_INDENT_ = 0x0010;
|
//int LVIF_NORECOMPUTE_ = 0x0800;
|
int LVIF_PARAM_ = 0x0004;
|
int LVIF_STATE_ = 0x0008;
|
int LVIF_TEXT_ = 0x0001;
|
//LVITEM_state
|
int LVIS_FOCUSED_ = 0x0001;
|
int LVIS_SELECTED_ = 0x0002;
|
int LVIS_OVERLAYMASK_ = 0x0F00;
|
|
lvitem lvi;
|
lvi.mask = LVIF_TEXT_ | LVIF_IMAGE_;
|
lvi.iItem = xIndex; //指定插入项目的行号
|
lvi.iSubItem = 0; //列号
|
//lvi.state = LVIS_FOCUSED_ | LVIS_SELECTED_ | LVIS_OVERLAYMASK_;
|
//lvi.stateMask = ;
|
lvi.pszText = (LPWSTR)label;
|
lvi.cchTextMax = 255;
|
lvi.iImage = pictureindex;
|
//lvi.lParam = data;
|
//lvi.iIndent
|
|
//int LVIF_GROUPID_ = 0x0100;
|
//int I_GROUPIDCALLBACK_ = -1;
|
//int I_GROUPIDNONE_ = -2;
|
//int iGroupId = 1;
|
//lvi.iGroupId = iGroupId;
|
return SendMessage(hWnd, LVM_INSERTITEM_, 0, (LPARAM) & lvi);
|
}
|
|
static int InsertItemEx(HWND hWnd, int xIndex, string label, int pictureindex = 0, int data = 0)//only the label and picture index need to be specified
|
{
|
int LVM_FIRST_ = 0x1000;// ListView messages
|
int LVM_INSERTITEM_ = LVM_FIRST_ + 77;
|
|
//LVITEM_mask
|
//int LVIF_COLFMT
|
//int LVIF_COLUMNS_ = 0x0200;
|
int LVIF_DI_SETITEM_ = 0x1000;
|
//int LVIF_GROUPID_ = 0x0100;
|
int LVIF_IMAGE_ = 0x0002;
|
//int LVIF_INDENT_ = 0x0010;
|
//int LVIF_NORECOMPUTE_ = 0x0800;
|
int LVIF_PARAM_ = 0x0004;
|
int LVIF_STATE_ = 0x0008;
|
int LVIF_TEXT_ = 0x0001;
|
//LVITEM_state
|
int LVIS_FOCUSED_ = 0x0001;
|
int LVIS_SELECTED_ = 0x0002;
|
int LVIS_OVERLAYMASK_ = 0x0F00;
|
|
lvitem lvi;
|
lvi.mask = LVIF_TEXT_ | LVIF_IMAGE_ | LVIF_PARAM_;
|
lvi.iItem = xIndex; //指定插入项目的行号
|
lvi.iSubItem = 0; //列号
|
//lvi.state = LVIS_FOCUSED_ | LVIS_SELECTED_ | LVIS_OVERLAYMASK_;
|
//lvi.stateMask = ;
|
lvi.pszText = (LPWSTR)label;
|
lvi.cchTextMax = 255;
|
lvi.iImage = pictureindex;
|
lvi.lParam = data;
|
//lvi.iIndent
|
|
//int LVIF_GROUPID_ = 0x0100;
|
//int I_GROUPIDCALLBACK_ = -1;
|
//int I_GROUPIDNONE_ = -2;
|
//int iGroupId = 1;
|
//lvi.iGroupId = iGroupId;
|
return SendMessage(hWnd, LVM_INSERTITEM_, 0, (LPARAM)&lvi);
|
}
|
|
static int SetItemText(HWND hWnd, int nItem, int nSubItem, string label)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_SETITEMTEXT_ = LVM_FIRST_ + 116;
|
int LVIF_TEXT_ = 0x0001;
|
|
lvitem lvi;
|
lvi.mask = LVIF_TEXT_;
|
lvi.iSubItem = nSubItem;
|
lvi.pszText = (LPWSTR)label;
|
lvi.cchTextMax = 255;
|
return SendMessage(hWnd, LVM_SETITEMTEXT_, nItem, (LPARAM)&lvi);
|
}
|
|
static int DeleteItemAll(HWND hWnd)//删除所有
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_DELETEALLITEMS_ = LVM_FIRST_ + 9;
|
return SendMessage(hWnd, LVM_DELETEALLITEMS_, 0, 0);
|
}
|
|
static int DeleteColumn(HWND hWnd, int nCol)//删除列
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_DELETECOLUMN_ = LVM_FIRST_ + 28;
|
return SendMessage(hWnd, LVM_DELETECOLUMN_, nCol, 0);
|
}
|
|
static int DeleteItem(HWND hWnd, int nIndex)//删除行
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_DELETEITEM_ = LVM_FIRST_ + 8;
|
return SendMessage(hWnd, LVM_DELETEITEM_, nIndex, 0);
|
}
|
|
static int EditLabel(HWND hWnd, int nIndex)//nIndex= -1表示取消编辑
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_EDITLABEL_ = LVM_FIRST_ + 118;
|
return SendMessage(hWnd, LVM_EDITLABEL_, nIndex, 0);
|
}
|
|
static int FindItem(HWND hWnd, int iStart, string label, bool partial, bool wrap)
|
{
|
//FindItem( int iStart, string label, boolean partial,boolean wrap )
|
//partial=true搜素包含label开头的,=false必须匹配整个标签
|
//wrap =true返回第一个找到的,=false返回最后找到的
|
int LVM_FIRST_ = 0x1000;
|
int LVM_FINDITEM_ = LVM_FIRST_ + 83;
|
|
//flags
|
int LVFI_PARAM_ = 0x0001;
|
int LVFI_STRING_ = 0x0002;
|
int LVFI_PARTIAL_ = 0x0008;
|
int LVFI_WRAP_ = 0x0020;
|
int LVFI_NEARESTXY_ = 0x0040;
|
//vkDirection
|
int VK_PRIOR_ = 0x21;
|
int VK_NEXT_ = 0x22;
|
int VK_END_ = 0x23;
|
int VK_HOME_ = 0x24;
|
int VK_LEFT_ = 0x25;
|
int VK_UP = 0x26;
|
int VK_RIGHT_ = 0x27;
|
int VK_DOWN_ = 0x28;
|
|
lvfindinfo lvfi;
|
if (partial == true)
|
{
|
lvfi.flags = LVFI_PARTIAL_ | LVFI_STRING_;
|
}
|
else
|
lvfi.flags = LVFI_STRING_;
|
if (wrap == true)
|
{
|
lvfi.flags |= LVFI_WRAP_;
|
}
|
lvfi.psz = label;
|
//lvfi.lParam = //为LVFI_PARAM时有效
|
//lvfi.pt //初始搜索位置,为LVFI_NEARESTXY 时有效
|
//lvfi.vkDirection = VK_NEXT_; //搜素方向。This member is valid only if LVFI_NEARESTXY is set in the flags member
|
|
return SendMessage(hWnd, LVM_FINDITEM_, iStart, (LPARAM)&lvfi);
|
}
|
|
static int GetColumn(HWND hWnd, int iCol, lvcolumn lvc)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETCOLUMN_ = LVM_FIRST_ + 95;
|
return SendMessage(hWnd, LVM_GETCOLUMN_, iCol, (LPARAM)&lvc);
|
}
|
|
static int GetItem(HWND hWnd, lvitem& lvi)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETITEM_ = LVM_FIRST_ + 75;
|
return SendMessage(hWnd, LVM_GETITEM_, 0, (LPARAM)&lvi);
|
}
|
|
static int GetItemCount(HWND hWnd)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETITEMCOUNT_ = LVM_FIRST_ + 4;
|
return SendMessage(hWnd, LVM_GETITEMCOUNT_, 0, 0);
|
}
|
|
static int GetItemText(HWND hWnd, int nIndex, lvitem lvi)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETITEMTEXT_ = LVM_FIRST_ + 115;
|
return SendMessage(hWnd, LVM_GETITEMTEXT_, nIndex, (LPARAM)&lvi);
|
}
|
|
static int GetNextItem(HWND hWnd, int nIndex, int flags)//nIndex=-1时从第一个开始
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETNEXTITEM_ = LVM_FIRST_ + 12;
|
return SendMessage(hWnd, LVM_GETNEXTITEM_, nIndex, flags);
|
}
|
|
static int GetSelectColumn(HWND hWnd)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETSELECTEDCOLUMN_ = LVM_FIRST_ + 174;
|
return SendMessage(hWnd, LVM_GETSELECTEDCOLUMN_, 0, 0);
|
}
|
|
static int GetSelectCount(HWND hWnd)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETSELECTEDCOUNT_ = LVM_FIRST_ + 50;
|
return SendMessage(hWnd, LVM_GETSELECTEDCOUNT_, 0, 0);
|
}
|
|
static int SetColumn(HWND hWnd, int iCol, lvcolumn lvc)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_SETCOLUMN_ = LVM_FIRST_ + 96;
|
return SendMessage(hWnd, LVM_SETCOLUMN_, iCol, (LPARAM)&lvc);
|
}
|
|
static int SetItem(HWND hWnd, lvitem lvi)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_SETITEM_ = LVM_FIRST_ + 76;
|
return SendMessage(hWnd, LVM_SETITEM_, 0, (LPARAM)&lvi);
|
}
|
|
static int SetItemText(HWND hWnd, int nIndex, lvitem lvi)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_SETITEMTEXT_ = LVM_FIRST_ + 116;
|
return SendMessage(hWnd, LVM_SETITEMTEXT_, nIndex, (LPARAM)&lvi);
|
}
|
|
static int InsertColumn(HWND hWnd, int nCol, int nFormat, int nWidth, string label, int nSubItem)//增加列
|
{
|
lvcolumn lvc; // 列
|
// ZeroMemory(&lvc, sizeof(lvcolumn));
|
|
int LVCF_FMT_ = 0x0001;
|
int LVCF_WIDTH_ = 0x0002;
|
int LVCF_TEXT_ = 0x0004;
|
int LVCF_SUBITEM_ = 0x0008;
|
int LVCFMT_LEFT_ = 0x0000;
|
lvc.mask = LVCF_FMT_ | LVCF_TEXT_ | LVCF_WIDTH_ | LVCF_SUBITEM_; // 风格
|
lvc.fmt = nFormat;//文本左对齐
|
lvc.cx = nWidth; // cx 是列的宽度(以像素点为单位)。以后您可以发送消息LVM_SETCOLUMNWIDTH 来改变列的宽度。
|
lvc.pszText = (LPWSTR)label; // 文字
|
lvc.cchTextMax = 255; // 文字长度
|
lvc.iSubItem = nSubItem; // 列号
|
|
int LVM_FIRST_ = 0x1000;// ListView messages
|
int LVM_INSERTCOLUMN_ = LVM_FIRST_ + 97;
|
return SendMessage(hWnd, LVM_INSERTCOLUMN_, nCol, (LPARAM)&lvc);
|
//lvc.pszText = "内存使用";
|
//SendMessage(hWnd, LVM_INSERTCOLUMN_, 0, (LPARAM_)&lvc);
|
//lvc.pszText = "ID";
|
//SendMessage(hWnd, LVM_INSERTCOLUMN_, 0, (LPARAM_)&lvc);
|
|
}
|
static int InsertItem(HWND hWnd, int nItem, int nSubItem, string label, int pictureindex)//增加行
|
{
|
lvitem lvi; // 列
|
// ZeroMemory(&lvi, sizeof(lvitem));
|
|
int LVIF_TEXT_ = 0x0001;
|
int LVIF_IMAGE_ = 0x0002;
|
int LVIF_PARAM_ = 0x0004;
|
int LVIF_STATE_ = 0x0008;
|
|
int MAX_PATH_ = 255;
|
int LVIS_STATEIMAGEMASK_ = 0xF000;
|
int LVIS_FOCUSED_ = 0x0001;
|
int LVIS_SELECTED_ = 0x0002;
|
lvi.mask = LVIF_TEXT_ | LVIF_IMAGE_ | LVIF_STATE_ | LVIF_PARAM_; // 文字、图片// 掩码位的组合(下面有对应掩码的元素都已在括号中标出掩码),表明哪些元素是有效的
|
lvi.iItem = nItem; //行号
|
lvi.iSubItem = nSubItem; //列号
|
lvi.pszText = (LPWSTR)label;
|
lvi.cchTextMax = 255; // 文字长度
|
lvi.iImage = pictureindex;
|
lvi.state = LVIS_FOCUSED_; // 状态,下面会列出。(LVIF_STATE)
|
lvi.stateMask = LVIS_STATEIMAGEMASK_;// 状态掩码,用来说明要获取或设置哪些状态。
|
int LVM_FIRST_ = 0x1000;// ListView messages
|
int LVM_INSERTITEM_ = LVM_FIRST_ + 77;
|
return SendMessage(hWnd, LVM_INSERTITEM_, 0, (LPARAM)&lvi);
|
//lvi.pszText = "日本";
|
//SendMessage(hWnd, LVM_INSERTITEM_, 0, (LPARAM_)&lvi);
|
//lvi.pszText = "德国";
|
//SendMessage(hWnd, LVM_INSERTITEM_, 0, (LPARAM_)&lvi);
|
}
|
|
static string GetItemText(HWND hWnd, int nIndex)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_GETITEMTEXT_ = LVM_FIRST_ + 115;
|
int LVIF_TEXT_ = 0x0001;
|
|
lvitem lvi;
|
lvi.mask = LVIF_TEXT_;
|
lvi.iItem = nIndex;
|
lvi.pszText = new wchar_t[255];
|
lvi.cchTextMax = 255;
|
int ret = SendMessage(hWnd, LVM_GETITEMTEXT_, nIndex, (LPARAM)&lvi);
|
//trace("result: %s", ret.toString());
|
return lvi.pszText;
|
}
|
|
/*static int AddItem(HWND hWnd,string label, int pictureindex = 0) //名字和图片
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_INSERTITEM_ = LVM_FIRST_ + 77;
|
lvitem pitem;
|
pitem.iItem = 0;
|
pitem.iSubItem = 0;
|
pitem.pszText = label;
|
pitem.iImage = pictureindex;
|
|
return win__::SendMessage(hWnd, LVM_INSERTITEM_, 0, &pitem);
|
}
|
|
static int AddItem(HWND hWnd,lvitem hItem)
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_INSERTITEM_ = LVM_FIRST_ + 77;
|
return win__::SendMessage(hWnd, LVM_INSERTITEM_, 0, &hItem);
|
}
|
|
|
static int InsertItem(HWND hWnd,int nIndex,lvitem hItem )//more than the label and picture index need to be specified
|
{
|
int LVM_FIRST_ = 0x1000;
|
int LVM_INSERTITEM_ = LVM_FIRST_ + 77;
|
return win__::SendMessage(hWnd, LVM_INSERTITEM_, 0, &hItem);
|
}
|
|
static int Sort (HWND hWnd,int hItem ,string sorttype )
|
{
|
}
|
|
//-------
|
static int AddLargePicture()
|
{
|
}
|
static int AddStatePicture()
|
{
|
}
|
static int DeleteLargePicture(int nIndex)
|
{
|
}
|
static int DeleteLargePictures()
|
{
|
}
|
static int DeleteStatePictures()
|
{
|
}
|
static int Drag ()
|
{
|
//dragmode = Begin!,Cancel!,End!
|
}
|
static int SetColumn (HWND hWnd,int nIndex,string label,string alignment,int width )
|
{
|
}*/
|
|
};
|