Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4739978
  • 博文数量: 206
  • 博客积分: 5240
  • 博客等级: 大校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-12 21:40
文章分类

全部博文(206)

文章存档

2013年(13)

2012年(8)

2011年(33)

2010年(152)

我的朋友

分类:

2010-10-18 01:20:20

参考
1.
2.

Windows 窗体  控件用于在下拉组合框中显示数据。默认情况下, 控件分两个部分显示:顶部是一个允许用户键入列表项的文本框。第二部分是一个列表框,它显示一个项列表,用户可从中选择一项。有关组合框的其他样式的更多信息,请参见 

 属性返回一个整数值,该值与选择的列表项相对应。通过在代码中更改  值,可以编程方式更改选择项;列表中的相应项将出现在组合框的文本框部分。如果未选定任何项,则  值为 -1。如果选择列表中的第一项,则  值为 0。 属性类似于 ,但它返回项本身,通常是字符串值。 属性反映列表的项数,由于  是从零开始的,所以  属性的值通常比  的最大可能值大一。

若要在  控件中添加或删除项,请使用  或  方法。或者,可以在设计器中使用  属性向列表添加项。


一。快手语法

创建控件语句

combobox={ bottom=69;right=192;left=30;top=49;font=LOGFONT( name="宋体";h=-12);text="combobox";z=1;
items={ };mode="dropdown";edge=1;cls="combobox" }//未添加items子项



text=" " 获取或设置与此控件关联的文本 

items={ }   中所包含项的集合

mode=" " 有三种模式形式:dropdown(默认)- 可书写修改下拉框值;dropdownlist-不可书写或修改下拉框值,只能选择下拉框值(通用模式);simple-下拉框的值全部显示出来,不隐藏(没意义的模式)


combobox={ bottom=69;right=192;left=30;top=49;font=LOGFONT( name="宋体";h=-12);text="+";z=1;
items={ "+";"-";"*";"/" };mode="dropdownlist";edge=1;cls="combobox" }



响应事件命令

如:响应下拉框选择事件命令

winform.combobox.oncommand = function(id,event){
    //win.msgbox( winform.combobox.text );
    if(event==0x9/*_CBN_SELENDOK*/){

win.msgbox(winform.combobox.selIndex)

}

    
}//endproc



在AAuto中,会将部份通知消息转发到控件的事件函数中(就是你双击控件自动创建的oncommand函数),并将通知消息ID发送给event参数。


组合框

_CBN_CLOSEUP 组合框的列表框被关闭
_CBN_DBLCLK 用户双击了一个字符串
_CBN_DROPDOWN 组合框的列表框被拉出
_CBN_EDITCHANGE 用户修改了编辑框中的文本
_CBN_EDITUPDATE 编辑框内的文本即将更新
_CBN_ERRSPACE 组合框内存不足
_CBN_KILLFOCUS 组合框失去输入焦点
_CBN_SELCHANGE 在组合框中选择了一项
_CBN_SELENDCANCEL 用户的选择应当被取消
_CBN_SELENDOK 用户的选择是合法的
_CBN_SETFOCUS 组合框获得输入焦点



库中源码(\win\ui\ctrl*控件集合)


class combobox{

    ctor(parent,tvalue){

       if(type(tvalue)==type.table)

       {

       select(tvalue.mode)

{

case "dropdown" 

tvalue.style |= 0x2/*_CBS_DROPDOWN*/         //创建一个下拉式组合框

case "dropdownlist"  

tvalue.style |= 0x3/*_CBS_DROPDOWNLIST*/     //创建一个下拉式列表框

case "simple" 

tvalue.style |= 0x1/*_CBS_SIMPLE*/              

//case "autohscroll" 

// tvalue.style |= 0x40/*_CBS_AUTOHSCROLL*/   //当用户在编辑区域键入字符时,列表框自动滚动,使当前项的名称与键入的字符排序相同

}  

tvalue.bottom += 100;

       if(tvalue.edge) tvalue.exstyle |= 0x200/*_WS_EX_CLIENTEDGE*/;

 

       }

    }

    oncreate = function(){

     this.orgclientrect.bottom+=100;

    } 

   

add = function( str){//listbox添加项 

        ::SendMessage(this.hwnd  , 0x143/*_CB_ADDSTRING*/, topointer( this.count ),str)

    } 

    clear = function(){

       ::SendMessage(this.hwnd , 0x14B/*_CB_RESETCONTENT*/ )

    } 

    delete = function(ind){

       if(!ind)

       ind=this.selIndex;

       ::SendMessage(this.hwnd , 0x144/*_CB_DELETESTRING*/, topointer(ind-1 ) )

    }

    find = function(v){//在列表框里查找指定的项

     var  ind =  ::SendMessage(owner.hwnd ,  0x14C/*_CB_FINDSTRING*/,  ,v);  

     return ind!=-1/*_CB_ERR*/?ind+1:0 

    }  

findEx = function( str ){//精确查找指定的项

var ind = ::SendMessage(this.hwnd , 0x158/*_CB_FINDSTRINGEXACT*/, , str ) ;

return ind!=-1/*_CB_ERR*/?ind+1:0

    


@metaProperty; 

 

}


combobox.metaProperty = ..win.ui.ctrl.metaProperty(


count = {

_get = function(){ 

return ::SendMessage(owner.hwnd, 0x146/*_CB_GETCOUNT*/, null,null) 

}

};

selIndex = {

_get = function(){ 

return ::SendMessage(owner.hwnd, 0x147/*_CB_GETCURSEL*/) + 1;

}

_set = function( v ){

::SendMessage(owner.hwnd, 0x14E/*_CB_SETCURSEL*/, topointer(v-1) )  

   }

}; 

selText = {

_get = function(){ 

var sel =  ::SendMessage(owner.hwnd, 0x147/*_CB_GETCURSEL*/ )

     var len = ::SendMessage(owner.hwnd, 0x149/*_CB_GETLBTEXTLEN*/, topointer(sel)); 

     var re ,text = ::SendMessageByString(owner.hwnd, 0x148/*_CB_GETLBTEXT*/,  sel  ,len+1);

     return  ..string.str( text )

_set = function(v){

::SendMessage(owner.hwnd, 0x14D/*_CB_SELECTSTRING*/, ,v);

}

}; 

items = {

_get = function(){ 

var count = ::SendMessage(owner.hwnd, 0x146/*_CB_GETCOUNT*/, null);

tab = {};

for(i=0;count-1;1){

var len = ::SendMessage(owner.hwnd, _CB_GETTEXTLEN, topointer(i),null) ;  

var ret,text  =  ::SendMessageByString(owner.hwnd , _CB_GETTEXT,i,len+1);


               ..table.push(tab,..string.str( text) )

            }

            

return tab;

}

_set = function( v ){

if( type(v) == type.table )

      for( i=1;#(v) ){ //0x14A/*_CB_INSERTSTRING*/插入,不排序,0x143/*_CB_ADDSTRING*/插入,支持0x100/*_CBS_SORT*/排序

       ::SendMessage(owner.hwnd , 0x143/*_CB_ADDSTRING*/, null,v[i]);  

}

}

}

)



ComboBox快手属性

!combobox.find(__/*请输入文本*/) = 查找列表项

!combobox.items = 组合框内容

!combobox.selText = 读取或设置组合框当前选中文本

!combobox.count = 列表项数目

!combobox.selIndex = 获取或指定当前选中的项(第一项=1)

!combobox.selText = 获取或指定当前选中的文本

!combobox.add(__/*请输入文本*/) = 添加到组合框

!combobox.clear() = 清除组合框所有内容

!combobox.delete() = 删除当前选中项

!combobox.findEx = 精确查找指定的项\n找不到返回0 

!combobox.hwnd = 控件句柄

!combobox.id = 控件ID

!combobox.parent = 父窗口

!combobox.parent.hwnd = 父窗口句柄

!combobox.hide = 控件是否隐藏

!combobox.disabled = 控件ID

!combobox.left = 左侧坐标

!combobox.right = 右侧坐标

!combobox.top = 顶部坐标

!combobox.bottom = 底部坐标

!combobox.redraw() = 刷新

!combobox.show(true__) = 显示控件

!combobox.rect = 控件区块位置(::RECT结构体)

!combobox.clientRect =  控件客户区块位置(::RECT结构体)

!combobox.font = 控件字体(::LOGFONT结构体)

!combobox.clientRect =  获取控件客户区块位置(::RECT结构体)

!combobox.theme = 外观主题,例如\nwinform.button.theme = "Explorer"\nwinform.button.theme = false

!combobox.modifyStyle(.(remove,add) = 如果指定第三个参数,则使用此参数调用::SetWidnowPos 

!combobox.modifyStyleEx(.(remove,add) = 如果指定第三个参数,则使用此参数调用::SetWidnowPos

!combobox.capture = 是否捕获全局鼠标消自息

!combobox.close() = 关闭控件窗口

!combobox.invalidate(__/*可选使用::RECT()对象指定客户区*/) = 使窗口绘图区无效

!combobox.invalidate(__/*可选使用::RECT()对象指定客户区*/,0) = 使窗口绘图区无效\n不刷新背景

!combobox.update() = 重绘invalidate函数指定的区块

?win.ui.ctrl.combobox  =!combobox.



获得焦点
  通常要判断控件是否获得了焦点,可以用GetFocus()函数
  例如:if(GetFocus()==GetDlgItem(IDC_EDIT_VALUE2))//判断焦点是否在编辑框
  IDC_EDIT_VALUE2 内。
  但是combobox 的焦点不同,因为它是由edit和listbox两部分组成的。
  所以获得焦点要用GetParent():if ((GetFocus()->GetParent())==GetDlgItem(IDC_COMBO_F))。


阅读(16909) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~