有没大虾知道如何用VC++ WIN32api做多列列表框的,不用MFC,做了后如何去调用(使用SENDMESSAGE调用)
有没大虾知道如何用VC++WIN32api做多列列表框的,不用MFC,做了后如何去调用(使用消息调用)非常感谢”真诚到永远”,不过确实有点复杂,我现在想用WIN32调用l...
有没大虾知道如何用VC++ WIN32api做多列列表框的,不用MFC,做了后如何去调用(使用消息调用)
非常感谢”真诚到永远”,不过确实有点复杂,我现在想用WIN32调用list contral 控件进行,将属性框内style属性改为report可以得到多列列表框,但是无法进行调用,MFC有相关的调用办法,api不知道如何调用,请高手再指点一二. 展开
非常感谢”真诚到永远”,不过确实有点复杂,我现在想用WIN32调用list contral 控件进行,将属性框内style属性改为report可以得到多列列表框,但是无法进行调用,MFC有相关的调用办法,api不知道如何调用,请高手再指点一二. 展开
2个回答
展开全部
给你现成的代码参考下吧,自己写的:下面的代码大部分来自于MSDN,虽然没有显式地SendMessage调用,取而代之的是宏调用,但宏调用的根本还是SendMessage
HWND MyCreateListWindow(HWND hParent,HINSTANCE hInstance)//这个函数是用来创建一个报表样式的列表,也就是多列的
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
HWND hWndListView = CreateWindow(WC_LISTVIEWA, "",
WS_CHILD|LVS_REPORT|WS_VISIBLE|LVS_SHOWSELALWAYS|LVS_SINGLESEL,
0, 0, 0,0,
hParent, 0, hInstance, NULL);
SendMessage(hWndListView,LVM_SETEXTENDEDLISTVIEWSTYLE,0,(LPARAM)LVS_EX_FULLROWSELECT);
int index=ListView_GetItemCount(hWndListView);
return hWndListView;
}
BOOL InitListViewColumns(HWND hWndListView) //初始化这个列表,添加四个列
{
RECT rect;
GetWindowRect(hWndListView,&rect);
int nWidth=rect.right-rect.left;
char szColumns[6][32]={"操作", "数据(ASCII)", "源IP:端口", "目标IP:端口"};
int nColWid[4]={nWidth/10,nWidth/5*3};
nColWid[2]=(nWidth-(nColWid[0]+nColWid[1]))/2;
nColWid[3]=nWidth-(nColWid[0]+nColWid[1])-nColWid[2];
LVCOLUMN lvc;
int iCol;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT |
LVCF_SUBITEM;
lvc.fmt = LVCFMT_LEFT;
for(iCol=0;iCol<4;iCol++)
{
lvc.iSubItem = iCol;
lvc.pszText = szColumns[iCol];
lvc.cx=nColWid[iCol];
if (ListView_InsertColumn(hWndListView, iCol,&lvc) == -1) //插入一个列。这是宏,不是函数,是通过发消息来实现的。
return FALSE;
}
return TRUE;
}
HWND MyInsertItem(HWND hWndListView,LPSTR szOperation,LPSTR szData,LPSTR szSrcSock,LPSTR szDstSock)//这个函数往最后一列添加数据
{
int index=ListView_GetItemCount(hWndListView);//这处宏是返回列表的条目的总数
LVITEM lvI;
lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
lvI.state = 0;
lvI.stateMask = 0;
// Initialize LVITEM members that are different for each item.
lvI.iItem = index;
lvI.iSubItem =0;
lvI.pszText = szOperation; // sends an
if(ListView_InsertItem(hWndListView, &lvI) == -1)//先插入一个项目,这样一行的第一列就有内容了,但接下来的几个列就要用下面的宏来实现了
return NULL;
ListView_SetItemText(hWndListView,index,1,szData);
ListView_SetItemText(hWndListView,index,2,szSrcSock);
ListView_SetItemText(hWndListView,index,3,szDstSock);
}
HWND MyCreateListWindow(HWND hParent,HINSTANCE hInstance)//这个函数是用来创建一个报表样式的列表,也就是多列的
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
HWND hWndListView = CreateWindow(WC_LISTVIEWA, "",
WS_CHILD|LVS_REPORT|WS_VISIBLE|LVS_SHOWSELALWAYS|LVS_SINGLESEL,
0, 0, 0,0,
hParent, 0, hInstance, NULL);
SendMessage(hWndListView,LVM_SETEXTENDEDLISTVIEWSTYLE,0,(LPARAM)LVS_EX_FULLROWSELECT);
int index=ListView_GetItemCount(hWndListView);
return hWndListView;
}
BOOL InitListViewColumns(HWND hWndListView) //初始化这个列表,添加四个列
{
RECT rect;
GetWindowRect(hWndListView,&rect);
int nWidth=rect.right-rect.left;
char szColumns[6][32]={"操作", "数据(ASCII)", "源IP:端口", "目标IP:端口"};
int nColWid[4]={nWidth/10,nWidth/5*3};
nColWid[2]=(nWidth-(nColWid[0]+nColWid[1]))/2;
nColWid[3]=nWidth-(nColWid[0]+nColWid[1])-nColWid[2];
LVCOLUMN lvc;
int iCol;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT |
LVCF_SUBITEM;
lvc.fmt = LVCFMT_LEFT;
for(iCol=0;iCol<4;iCol++)
{
lvc.iSubItem = iCol;
lvc.pszText = szColumns[iCol];
lvc.cx=nColWid[iCol];
if (ListView_InsertColumn(hWndListView, iCol,&lvc) == -1) //插入一个列。这是宏,不是函数,是通过发消息来实现的。
return FALSE;
}
return TRUE;
}
HWND MyInsertItem(HWND hWndListView,LPSTR szOperation,LPSTR szData,LPSTR szSrcSock,LPSTR szDstSock)//这个函数往最后一列添加数据
{
int index=ListView_GetItemCount(hWndListView);//这处宏是返回列表的条目的总数
LVITEM lvI;
lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
lvI.state = 0;
lvI.stateMask = 0;
// Initialize LVITEM members that are different for each item.
lvI.iItem = index;
lvI.iSubItem =0;
lvI.pszText = szOperation; // sends an
if(ListView_InsertItem(hWndListView, &lvI) == -1)//先插入一个项目,这样一行的第一列就有内容了,但接下来的几个列就要用下面的宏来实现了
return NULL;
ListView_SetItemText(hWndListView,index,1,szData);
ListView_SetItemText(hWndListView,index,2,szSrcSock);
ListView_SetItemText(hWndListView,index,3,szDstSock);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询