MiniGUI编程--列表框

列表框
LBS(ListBoxStyle)
以CTRL_LIST/"list"为类名调用CreateWindow
多选风格:LBS_MULTIPLESEL
高级风各:LBS_USEICON
LBS_CHECKBOX
LBS_AUTOCHECK
加上边框WS_BORDER
加垂直滚动条WS_VSCROLL
加水平滚动条WS_HSCROLL
允许通知消息:LBS_NOTIFY
排序LBS_SORT
常用风格组合:
LBS_NOTIFY|LBS_SORT|WS_VSCROLL|WS_BORDER
加入字符串LB_ADDSTRING
最上面索引值为0
SendMessage传递字符串时节lParam指向字符串
添加以未尾
SendMessage(hwndlist,LB_ADDSTRING,0,(LPARAM)string);
插入字符串LB_INSERTSTRING
SendMessage(hwndlist,LB_INSERTSTRING,index,(LPARAM)string);
如指定期LBS_CHECKBOX/LBS_USEICON风格添加时不能传字符串指针,而要使用LISTBOXITEMINFO结构
HICON hIcon1;
LISTBOXITEMINFO lbii;
hIcon1=LoadIconFromFile(HDC_SCREEN,"res/audio.ico",1);
lbii.hIcon=hIcon1;
lbii.cmFlag=CMFLAG_CHECKED;
lbii.string="ABCDEFG";
SendMessage(hwnd,LB_ADDSTRING,0,(LPARAM)&lbii);
cmFlag:CMFLAG_CHECKED,CMFLAG_BLANK,CMFLAG_PARTCHECKED
在列表框中显示位图
IMGFLAG_BITMAP
lbii.hIcon=(DWORD)GetSystemBitmap(SYSBMP_MAXIMIZE);
lbii.cmFlag=CMFLAG_CHECKED|IMGFLAG_BITMAP;
lbii.string="ABCDEF";
SendMessage(hwndlist,LB_ADDSTRING,0,(LPARAM)&lbii);
删除指定条目
发送LB_DELETESTRING消息
SendMessage(hwndlist,LB_DELETESTRING,index,0);
清空
SendMessage(hwndlist,LB_DELETESTRING,0,0);
获取条目个数
发送LB_GETCOUNT消息
count=SendMessage(hwndlist,LB_GETCOUNT,0,0);
获取指定条目字符串长度
发送LB_GETTEXTLEN
length=SendMessage(hwndlist,LB_GETTEXTLEN,index,0);
获取条目
length=SendMessage(hwndlist,LB_GETTEXTLEN,index,(LPARAM)buffer);
设置条目
LB_SETTEXT
SendMessage(hwndlist,LB_SETTEXT,index,buffer);
高级列形框要使用LB_GETITEMDATA/LB_SETITEMDATA
HICON hIocn1;
LISTBOXITEMINFO lbii;
hIcon1=LoadIconFromFile(HDC_SCREEN,"rest/audio.ico",1);
lbii.hIcon=hIcon1;
lbii.cmFlag=CMFLAG_CHECKED;
lbii.string="new item";
SendMessage(hwndlist,LB_SETITEMDATA,index,(LPARAM)&lbii);
获取当前选择项
LB_GETCURSEL
index=SendMessage(hwndlist,LB_GETCURSEL,0,0);
设置当前选择项
SendMessage(hwndlist,LB_SETCURSEL,index,0);
多选:
LB_GETSELCOUNT获得被选中的条目个数
LB_GETSELITEMS获得所有被选索引值
int i,sel_count;
int *sel_itmes;
sel_count=SendMessage(hwndlist,LB_GETSELCOUNT,0,0L);
if(sel_count==0)
return;
sel_items=alloca(sizeof(int)*sel_count);
SendMessage(hwndlist,LB_GETSELITEMS,sel_count,sel_items);
for(i=0;i...
查所字符串
模糊查找LB_FINDSTRING
精确查找LB_FINDSTRINGEXACT
index=SendMessage(hwndlist,LB_FINDSTRING,(LPARAM)string);
获取检查框状态
status=SendMessage(hwndlist,LB_GETCHECKMARK,index,0);
返回值:
CMFLAG_CHECKED选择状态
CMFLAG_PARTCHECKED部分选择状态
CMFLAG_BLANK未选择状态
设检查框状态
ret=SendMessage(hwndlist,LB_SETCHECKMARK,index,(LPARAM)status);
返回值:
LB_ERR失败
LB_OKAY成功
为每个条目附加一个32位数据,在需要时取出该值
LB_SETITEMADDDATA
LB_GETITEMADDDATA
设置条目所占高度
LB_SETITEMHEIGHT
返回条目所占高度
LB_GETITEMHEIGHT
通知码:
必须指定LBS_NOTIFY风格
LBN_ERRSPACE内存分配失败
LBN_SELCHANGE当前选择项发生变化
LBN_CLICKED单击
LBN_DBLCLK双击
LBN_SELCANCEL取消选择
LBN_SETFOCUS列表框获得焦点
LBN_KILLFOCUS列表框失去焦点
LBN_CLICKCHECKMARK单击条目检查框
LBN_ENTER在列表框中按下Enter键
只有指下LBS_NOTIFY时,列表框才会向父窗口发送通知消息
如果用SetNotificationCallback设定了通知回调函数
则控件不发送MSG_COMMAND通知消息,而会直接调用设定的通知回调函数

你可能感兴趣的:(MiniGUI编程--列表框)