VC基本控件风格、类介绍
发布时间:2011年3月6日 作者:未知 查看次数:1478
VC基本控件风格、类介绍
Button 按钮控件、单选钮控件、复选框控件、分组框控件(风格是以BS_开头) ComboBox 组合框控件 (风格是以CBS_开头) Edit 编辑框控件 (风格是以ES_开头) ListBox 列表框控件 (风格是以LBS_开头) Static 静态文本控件 (风格是以SS_开头) ScrollBar滚动条控件 (风格是以SBS_开头)
Windwos 的常用控件的创建主要是基于以上这6个中类,这6个类就是系统注册的窗口类,也有自己的窗口过程,也接收消息,而它的父窗口也会接受到WM_COMAND消息 For Example: BM_CLICK Simulates the user clicking a button. This message causes the button to receive the WM_LBUTTONDOWN and WM_LBUTTONUP messages, and the button's parent window to receive a BN_CLICKED notification message. 模拟用户点击这个按钮 模拟用户点击这个按钮,这个按钮(因为按钮也是一个窗口)的窗口过程会接收两个窗口消息WM_LBUTTONDOWN and WM_LBUTTONUP(因为按钮也是一个窗口,它本身也有窗口过程,这个窗口过程的所属就是Button类,这个是系统内部的类)(其它控件类也是雷同),这个子窗口的父窗口的窗口过程会接收到该子窗口引发的的COMMAND消息,消息的通知码是BN_CLICKED End Example
用CreateWindwoEx函数创建基于这5类的控件
基于Button类的控件 [ szButton db 'Button',0 ] 按钮控件(不用风格时,默认就是按钮控件) invoke CreateWindowEx,NULL,\ offset szButton,offset szButtonText,\ WS_CHILD or WS_VISIBLE,\ 180,10,40,22,\ hWnd,WM_USER+1,hInstance,NULL 图标充当按钮界面(.ico文件) invoke CreateWindowEx,NULL,\ offset szButton,offset szButtonText,\ WS_CHILD or WS_VISIBLE or BS_ICON,\ 180,10,100,50,\ hWnd,WM_USER+1,hInstance,NULL invoke SendMessage,eax,BM_SETIMAGE,IMAGE_ICON,hIco1 在程序开始时用LoadIcon从可执行文件的资源节区中读取图标文件 invoke GetModuleHandle,NULL mov hInstance,eax invoke LoadIcon,hInstance,IDB_11 .if eax mov hIco1,eax .endif 图象充当按钮界面(.Bmp文件) invoke CreateWindowEx,NULL,\ offset szButton,offset szButtonText,\ WS_CHILD or WS_VISIBLE or BS_BITMAP,\ 180,10,100,50,\ hWnd,WM_USER+1,hInstance,NULL invoke SendMessage,eax,BM_SETIMAGE,IMAGE_BITMAP,hBmp1 在程序开始时用LoadIcon从可执行文件的资源节区中读取位图文件 invoke LoadBitmap,hInstance,IDB_1 mov hBmp1,eax
单选钮控件 invoke CreateWindowEx,NULL,\ offset szButton,offset szButtonText,\ WS_CHILD or WS_VISIBLE or BS_AUTORADIOBUTTON,\ 60,10,40,22,\ hWnd,WM_USER+3,hInstance,NULL 复选框控件 invoke CreateWindowEx,NULL,\ offset szButton,offset szButtonText,\ WS_CHILD or WS_VISIBLE or BS_AUTOCHECKBOX,\ 10,10,40,22,\ hWnd,WM_USER+2,hInstance,NULL 分组框控件 invoke CreateWindowEx,NULL,\ offset szButton,offset szButtonText,\ WS_CHILD or WS_VISIBLE or BS_GROUPBOX,\ 120,10,60,22,\ hWnd,1,hInstance,NULL 基于ComboBox 类的控件 [ szComboBox db 'ComboBox',0 ] 组合框控件 invoke CreateWindowEx,NULL,\ offset szComboBox,NULL,\ WS_CHILD or WS_VISIBLE or CBS_DROPDOWNLIST,\ 10,180,200,200,\ hWnd,WM_USER+6,hInstance,NULL Style CBS_SIMPLE:可输入,不是下拉菜单 CBS_DROPDOWN:可输入,带下拉菜单 CBS_DROPDOWNLIST:不可输入,带下拉菜单 ;以下代码是用于初始化组合框控件 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_ADDSTRING,0,addr szText11 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_ADDSTRING,0,addr szText22 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_ADDSTRING,0,addr szText33
基于Edit 类的控件 [ szEdit db 'Edit',0 ] 编辑框控件(因为Edit类的控件只有编辑框控件一种,所以不用设置样式也可以制定是编辑框控件) invoke CreateWindowEx,NULL,\ offset szEdit,NULL,\ WS_CHILD or WS_VISIBLE or WS_BORDER,\ 10,70,80,22,\ hWnd,WM_USER+4,hInstance,NULL Style WS_BORDER代表编辑框的边线 ES_NUMBER编辑框中只能输入数字 ES_AUTOHSCROLL文本自动向右滚动 ES_UPPERCASE将所有字符转换为大写 ES_LOWERCASE将所有字符转换为小写 ES_CENTER 文本从中间开始 ES_PASSWORD以*的形式输出 ;多行编辑时并支持回车时用风格ES_WANTRETURN(插入回车符) or ES_MULTILINE(多行编辑) or ES_AUTOHSCROLL(文字自动向右滚动) or ES_AUTOVSCROLL(行自动向上翻动) 基于ListBox 类的控件 [ szListBox db 'ListBox',0 ] 列表框控件 invoke CreateWindowEx,NULL,\ offset szListBox,NULL,\ WS_CHILD or WS_VISIBLE or WS_HSCROLL or LBS_STANDARD,\ 10,140,200,22,\ hWnd,WM_USER+5,hInstance,NULL Style LBS_MULTIPLESEL允许多选 LBS_STANDARD:该风格包含了下列的风格 LBS_NOTIFY;用户单击或双击项目时向父窗口发送WM_COMMAND消息,消息中包含了通知码 LBS_SORT:自动按字母顺序配列 WS_VSCROLL:垂直滚动条(WS代表是窗口风格) WS_BORDER:单线条边框(WS代表是窗口风格) 以下代码是用于初始化列表框控件 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_ADDSTRING,0,addr szText1 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_ADDSTRING,0,addr szText2 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_ADDSTRING,0,addr szText3 基于Static 类的控件 [ szStatic db 'Static',0 ] Style SS_BITMAP:用于输出图像 SS_ICON:用于输出图标 SS_NOTIFY会向窗口过程发送WM_COMMAND消息 静态控件(静态控件不向窗口过程发WM_COMMAND消息(除非设置了SS_NOTIFY样式,所以一般不用设置ID,如果要在程序中改变属性时就应该设置ID) invoke CreateWindowEx,NULL,\ offset szStatic,NULL,\ WS_CHILD or WS_VISIBLE,\ 10,220,300,200,\ hWnd,NULL,hInstance,NULL 设置静态控件的文字 invoke SetWindowText,eax,addr szButton;通过调用win32 api ,其实这个函数也是控件发送了WM_SETTEXT消息实现的(MSDN中可以看到) invoke SendMessage,eax,WM_SETTEXT,0,addr szComboBox;通过发送WM_SETTEXT来实现 设置静态控件的图片 invoke SendMessage,eax,STM_SETIMAGE,IMAGE_BITMAP,hBmp1;用于设置控件上的图片,CreateWindowEx中样式用SS_BITMAP invoke GetDlgItem,hWnd,WM_USER+7;用于更改控件上的图片 invoke SendMessage,eax,STM_SETIMAGE,IMAGE_BITMAP,hBmp2
invoke SendMessage,eax,STM_SETIMAGE,IMAGE_ICON,hIco1;用于输出图标,CreateWindowEx中样式用SS_ICON
基于ScrollBar类的控件 [ szScrollBar db 'ScrollBar',0 ] 和其他子窗口不同,垂直滚动条(风格为SBS_HORZ)向父窗口过程发送WM_VSCROLL消息,而水平滚动条(风格为SBS_VERT)发送WM_HSCROLL消息,创建后要发送SBM_SETRANGE消息设置初始值 invoke CreateWindowEx,NULL,offset szScrollBar,NULL,WS_CHILD or WS_VISIBLE or SBS_HORZ,\;SBS_VERT为垂直滚动条 SBS_HORZ水平滚动条 250,300,200,20,hWnd,WM_USER+20,hInstance,NULL invoke SendDlgItemMessage,hWnd,WM_USER+20,SBM_SETRANGE,0,100;发送SBM_SETRANGE消息设置初始值 窗口过程中: .elseif eax == WM_HSCROLL;和其他子窗口不同,垂直滚动条(风格为SBS_HORZ)向父窗口过程发送WM_VSCROLL消息,而水平滚动条(风格为SBS_VERT)发送WM_HSCROLL消息,创建后要发送SBM_SETRANGE消息设置初始值 mov eax,wParam .if ax == SB_LINELEFT dec dwPos .elseif ax == SB_LINERIGHT inc dwPos .elseif ax == SB_PAGELEFT sub dwPos,10 .elseif ax == SB_PAGERIGHT add dwPos,10 .elseif ax == SB_THUMBPOSITION || ax == SB_THUMBTRACK mov eax,wParam shr eax,16 mov dwPos,eax .else mov eax,TRUE ret .endif cmp dwPos,0 jge @F mov dwPos,0 @@: cmp dwPos,100 jle @F mov dwPos,100 @@: invoke SetDlgItemInt,hWnd,WM_USER+1,dwPos,FALSE;将数值型数据转换成字符串并设置到控件上去 invoke GetDlgItemInt,hWnd,WM_USER+1,NULL,FALSE;当控件上的串是数字时,这个函数将串转换成数值型数据并保存到EAX中 invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK invoke SendDlgItemMessage,hWnd,WM_USER+20,SBM_SETPOS,dwPos,TRUE: 程序通过调用SendMessage发送消息来对控件实现控制,而在程序的窗口过程中监控控件引发的通知消息可通过MSDN查到相关子窗口的信息,如样式,支持的事件和控制消息等。。。。 1.输入:CreateWindowEx 2.CreateWindowEx Function::windows management 这样就可以看到创建子窗口时支持的类,进入某个类后就可看到子窗口支持的 Messages 和 Notifications
Messages(程序用来控制子窗口的消息)(程序发送给子窗口的,程序用于控制子窗口的消息) Notifications(这里显示的就是WM_COMMAND消息的高16位的通知码,这里是控件引发的消息) 子窗口发送给程序的消息,消息大多数以WM_COMMAND发送,高16位就是通知码,低16位是控件ID,lParam是控件句柄。 以下是总结各类常用的Messages 和 Notifications
Button类 Button-Messages BM_CLICK Simulates the user clicking a button. This message causes the button to receive the WM_LBUTTONDOWN and WM_LBUTTONUP messages, and the button's parent window to receive a BN_CLICKED notification message. 模拟用户点击这个按钮 模拟用户点击这个按钮,这个按钮(因为按钮也是一个窗口)的窗口过程会接收两个窗口消息WM_LBUTTONDOWN and WM_LBUTTONUP(因为按钮也是一个窗口,它本身也有窗口过程,这个窗口过程的所属就是Button类,这个是系统内部的类)(其它控件类也是雷同),这个子窗口的父窗口的窗口过程会接收到WM_USER+1的COMMAND消息,消息的通知码是BN_CLICKED invoke SendMessage,eax,BM_CLICK,0,0; 窗口过程会接收到WM_USER+1的COMMAND消息,消息的通知码是BN_CLICKED
BM_SETIMAGE Associates a new image (icon or bitmap) with the button.用一个图片或图标来显示一个按钮 invoke SendMessage,eax,BM_SETIMAGE,IMAGE_BITMAP,hBmp1;设置按钮为图标显示,CreateWindowEx时风格为BS_ICON invoke SendMessage,eax,BM_SETIMAGE,IMAGE_ICON,hIco1;设置按钮为位图显示BS_BITMAP BM_SETCHECK Sets the check state of a radio button or check box. 设置单选钮或者复选框的状态 invoke SendMessage,eax,BM_SETCHECK,BST_CHECKED,0
BM_GETCHECK Gets the check state of a radio button or check box. 返回单选钮或者复选框的选中状态 BST_CHECKED mov ebx,BST_UNCHECKED invoke SendMessage,eax,BM_GETCHECK,0,0 .if ebx==eax invoke MessageBox,NULL,offset TestResult,offset szCaption,MB_OK .endif BM_GETSTATE Determines the state of a button or check box. 返回单选钮或者复选框的选中状态比BM_GETCHECK返回的更全面,如焦点判断等 Parameters wParam Not used; must be zero. lParam Not used; must be zero. Return Value The return value specifies the current state of the button. You can use the following values to extract information about the state. Value invoke SendMessage,eax, BM_GETSTATE,0,0 BM_SETIMAGE Associates a new image (icon or bitmap) with the button. 用一个图片或图标来显示一个按钮 invoke SendMessage,eax,BM_SETIMAGE,IMAGE_BITMAP,hBmp1;设置按钮为图标显示,CreateWindowEx时风格BS_BITMAP invoke SendMessage,eax,BM_SETIMAGE,IMAGE_ICON,hIco1;设置按钮为位图显示为BS_ICON BM_GETIMAGE Retrieves a handle to the image (icon or bitmap) associated with the button.当按钮联合了图片或图标时,用这个函数可以返回图片或图标的句柄 invoke GetDlgItem,hWnd,WM_USER+1 invoke SendMessage,eax,BM_GETIMAGE,IMAGE_ICON,hIco1 .if hIco1==eax invoke MessageBox,NULL,offset TestResult,offset szCaption,MB_OK .endif BM_SETSTATE Changes the highlight state of a button. The highlight state indicates whether the button is highlighted as if the user had pushed it. 按钮的显示状态改为用户按下的状态 invoke SendMessage,eax,BM_SETSTATE,TRUE,0 BM_SETSTYLE Changes the style of a button. 改变按钮的样式,如变成单选钮或者复选框 Parameters wParam The new button style. This parameter can be a combination of button styles. For a table of button styles, see Button Styles. lParam The low-order word of lParam specifies whether the button is to be redrawn. A value of TRUE redraws the button; a value of FALSE does not redraw the button. 制定是否重画按钮 invoke SendMessage,eax,BM_SETSTYLE,BS_RADIOBUTTON,TRUE
Button-Notifications 格式: .elseif eax == WM_COMMAND; mov eax,wParam .if ax ==WM_USER+1 ;按钮 shr eax,16 .if ax ==BN_CLICKED invoke MessageBox,NULL,offset szButton1,offset szCaption,MB_OK .endif BN_CLICKED Sent when the user clicks a button. 当用户点击时发送 The parent window of the button receives the BN_CLICKED notification code through the WM_COMMAND message. 父窗口接收一个WM_COMMAND消息,通知码为BN_CLICKED BN_DBLCLK Sent when the user double-clicks a button. This notification is sent automatically for BS_USERBUTTON, BS_RADIOBUTTON, and BS_OWNERDRAW buttons. Other button types send BN_DBLCLK only if they have the BS_NOTIFY style. The parent window of the button receives the BN_DBLCLK notification code through the WM_COMMAND message. 双击子窗口时, 父窗口接收一个WM_COMMAND消息,通知码为BN_DBLCLK,但是子窗口必须指定了BS_NOTIFY样式 BN_KILLFOCUS Sent when a button loses the keyboard focus. The button must have the BS_NOTIFY style to send this notification message. The parent window of the button receives the BN_KILLFOCUS notification code through the WM_COMMAND message. 当这个子窗口遗失焦点时, 父窗口接收一个WM_COMMAND消息,通知码BN_KILLFOCUS,但是子窗口必须指定了BS_NOTIFY样式 BN_SETFOCUS Sent when a button receives the keyboard focus. The button must have the BS_NOTIFY style to send this notification message. The parent window of the button receives the BN_SETFOCUS notification code through the WM_COMMAND message. 当这个子窗口获得焦点时, 父窗口接收一个WM_COMMAND消息,通知码BN_KILLFOCUS,但是子窗口必须指定了BS_NOTIFY样式
ComboBox类 ComboBox-Messages CB_ADDSTRING Adds a string to the list box of a combo box. If the combo box does not have the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted. 添加一个字符串到组合框的列表中,条件是那个组合框不能是有CBS_SORT样式,那字符串是添加到那列表的结尾 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_ADDSTRING,0,addr szText11 CB_DELETESTRING Deletes a string in the list box of a combo box. 从组合框的列表框中删除一个字符串 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_DELETESTRING,1,0 CB_DIR Adds names to the list displayed by the combo box. The message adds the names of directories and files that match a specified string and set of file attributes. CB_DIR can also add mapped drive letters to the list. 列出某个盘符下的文件名或者所有盘 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_DIR,DDL_DIRECTORY,addr szDisk;szDisk db 'C:\*',0 列出C盘下的所有文件 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_DIR,DDL_DRIVES,addr szDisk;szDisk db '0',0 列出全部盘符 CB_FINDSTRING Searches the list box of a combo box for an item beginning with the characters in a specified string. 从组合框所属的列表框中的一个条目开始搜索指定的字符串,也就是搜索条目的第一个字符匹配 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_FINDSTRING,0,addr szSearch CB_FINDSTRINGEXACT Finds the first list box string in a combo box that matches the string specified in the lParam parameter. 搜索列表框中的字符串,与条目的匹配,不是查找条目中包含的字符,而是整个条目需要匹配 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_FINDSTRINGEXACT,-1,addr szSearch 搜索列表框中的字符串,与条目的匹配,不是查找条目中包含的字符,而是整个条目需要匹配 CB_GETCOUNT Gets the number of items in the list box of a combo box. 获得列表框条目的总数 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_GETCOUNT,0,0 .if eax!=CB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif CB_GETCURSEL An application sends a CB_GETCURSEL message to retrieve the index of the currently selected item, if any, in the list box of a combo box. 一个应用程序发送CB_GETCURSEL消息并接受一个选中项目的索引,如果在这个列表框中有选中的话 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_GETCURSEL,0,0 .if eax!=CB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif CB_GETDROPPEDSTATE Determines whether the list box of a combo box is dropped down.检测列表的下拉状态 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_GETDROPPEDSTATE,0,0 .if !eax invoke MessageBox,NULL,offset szState,offset szCaption,MB_OK .endif CB_SETEDITSEL An application sends a CB_SETEDITSEL message to select characters in the edit control of a combo box. 用一个字符串设置编辑框的字符 invoke SendDlgItemMessage,hWnd,WM_USER+6,WM_SETTEXT,0,addr szText11;用这个方法来代替 CB_GETDROPPEDWIDTH Gets the minimum allowable width, in pixels, of the list box of a combo box with the CBS_DROPDOWN or CBS_DROPDOWNLIST style. 获取列表框的宽,样式不是CBS_SIMPLE组合框 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_GETDROPPEDWIDTH,0,0 .if eax!=CB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif CB_SETDROPPEDWIDTH An application sends the CB_SETDROPPEDWIDTH message to set the maximum allowable width, in pixels, of the list box of a combo box with the CBS_DROPDOWN or CBS_DROPDOWNLIST style. 设置列表框的宽,样式不是CBS_SIMPLE组合框 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_SETDROPPEDWIDTH,2250,0 CB_GETITEMHEIGHT Determines the height of list items or the selection field in a combo box. 测试列表框项目或编辑框的高,-1为编辑框的高,0位列表框项目的高 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_GETITEMHEIGHT,0,-1 .if eax!=CB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif CB_GETLBTEXT Gets a string from the list of a combo box. 从列表框中获得一个字符串 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_GETLBTEXT,2,addr szBuffer invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK CB_GETLBTEXTLEN Gets the length, in characters, of a string in the list of a combo box. 获得指定条目的字符数(UNCODE)或字节数(ANSI) invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_GETLBTEXTLEN,2,0 .if eax!=CB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif CB_GETTOPINDEX An application sends the CB_GETTOPINDEX message to retrieve the zero-based index of the first visible item in the list box portion of a combo box. Initially, the item with index 0 is at the top of the list box, but if the list box contents have been scrolled, another item may be at the top. 获得列表框第一个 可见条目的索引 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_GETTOPINDEX,0,0 CB_INSERTSTRING Inserts a string into the list box of a combo box. Unlike the CB_ADDSTRING message, the CB_INSERTSTRING message does not cause a list with the CBS_SORT style to be sorted. 在制定位置插入字符串 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_INSERTSTRING,-1,addr szText22 CB_LIMITTEXT Limits the length of the text the user may type into the edit control of a combo box. 设置编辑框的输入的最大长度 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_LIMITTEXT,5,0 CB_RESETCONTENT Removes all items from the list box and edit control of a combo box. 删除列表框和编辑框所有的条目 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_RESETCONTENT,0,0 CB_SELECTSTRING Searches the list of a combo box for an item that begins with the characters in a specified string. If a matching item is found, it is selected and copied to the edit control. 在列表框中搜索一个指定的字符串,若列表框中的某个条目的第一个字符与指定的字符串匹配的话就选入组合框的编辑框控件中 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_SELECTSTRING,2,addr szSearch
CB_SETCURSEL An application sends a CB_SETCURSEL message to select a string in the list of a combo box. If necessary, the list scrolls the string into view. The text in the edit control of the combo box changes to reflect the new selection, and any previous selection in the list is removed. 组合框中显示的项目 ,wParam是索引号,lParam为0 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_SETCURSEL,0,0 CB_SETITEMHEIGHT An application sends a CB_SETITEMHEIGHT message to set the height of list items or the selection field in a combo box. 设置列表框项目或编辑框的高,-1为编辑框的高,0位列表框项目的高 invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_SETITEMHEIGHT,-1,8 CB_SHOWDROPDOWN An application sends a CB_SHOWDROPDOWN message to show or hide the list box of a combo box that has the CBS_DROPDOWN or CBS_DROPDOWNLIST style. 发送消息显示或者隐藏组合框的列表框,前提是样式不能为CBS_SIMPLE invoke SendDlgItemMessage,hWnd,WM_USER+6,CB_SHOWDROPDOWN,TRUE,0
ComboBox-Notifications CBN_SELENDOK The CBN_SELENDOK notification message is sent when the user selects a list item, or selects an item and then closes the list. It indicates that the user's selection is to be processed. The parent window of the combo box receives this notification message through the WM_COMMAND message. 当用户选择了列表框的某个条目时组合框的父窗口接受WM_COMMAND消息,通知码就是CBN_SELENDOK
LIST类 List-Messages LB_ADDSTRING 添加一个字符串到的列表框中,那字符串是添加到那列表的结尾 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_ADDSTRING,0,addr szText3 LB_DELETESTRING从列表框中删除一个字符串 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_DELETESTRING,1,0 LB_FINDSTRING搜索列表框中的第一个开头的字符串 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_FINDSTRING,0,addr szSearch .if eax==1 invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif LB_FINDSTRINGEXACT搜索列表框中的字符串,与条目的匹配,不是查找条目中包含的字符,而是整个条目需要匹配 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_FINDSTRINGEXACT,-1,addr szText22 .if eax==1 invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif LB_GETCOUNT返回条目总数 invoke SendDlgItemMessage,hWnd,WM_USER+5,CB_LETCOUNT,0,0 .if eax!=LB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif LB_GETCURSEL和LB_SETCURSEL 一个应用程序发送LB_GETCURSEL消息并接受一个选中项目的索引,如果在这个列表框中有选中的话,先用LB_SETCURSEL invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_SETCURSEL,0,0 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_GETCURSEL,0,0 .if eax!=LB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif LB_GETTEXT获得指定条目的字符串 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_GETTEXT,2,addr szBuffer invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK LB_GETTEXTLEN获得指定条目的字符数(UNCODE)或字节数(ANSI) invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_GETTEXTLEN,2,0 .if eax!=LB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif LB_GETTOPINDEX获得第一个条目的索引 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_GETTOPINDEX,0,0 LB_INSERTSTRING在制定位置插入字符串 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_INSERTSTRING,-1,addr szText22 LB_RESETCONTENT删除列表框和编辑框所有的条目 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_RESETCONTENT,0,0 LB_SELECTSTRING在列表框中搜索一个指定的字符串,若列表框中的某个条目的第一个字符与指定的字符串匹配的话就选中 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_SELECTSTRING,2,addr szSearch LB_DIR列出某个盘符下的文件名或者所有盘符 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_DIR,DDL_DIRECTORY,addr szDisk;szDisk db 'C:\*',0 列出C盘下的所有文件 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_DIR,DDL_DRIVES,addr szDisk;szDisk db '0',0 列出全部盘符 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_DIR,0,addr szDisk;szDisk db '*.*',0 列出可执行文件的所在目录的文件 LB_SELITEMRANGE选定一个范围(lParam的高字节是END的条目,低字节是START的条目) invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_SELITEMRANGE,TRUE,00020001h LB_SETSEL在列表框中将一个条目选定或清除 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_SETSEL,TRUE,2 LB_GETSELCOUNT在列表框中返回选中的总数 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_GETSELCOUNT,0,0 .if eax!=LB_ERR invoke wsprintf,addr szBuffer,addr szStart,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif LB_GETSELITEMS在列表框中选中的索引存入一个缓冲区 invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_GETSELITEMS,128/4,addr @szBuffer
List-Notifications LBN_DBLCLK 当用户在列表框上双击了一个项目时,父窗口过程会受到通知码为LBN_DBLCLK的WM_COMMAND消息 .elseif ax ==WM_USER+5;列表框,需要判断通知码 shr eax,16 .if ax ==LBN_DBLCLK;BN_SETFOCUS;BN_DBLCLK;BN_CLICKED invoke SendDlgItemMessage,hWnd,WM_USER+5,LB_GETCURSEL,0,0 .if eax!=LB_ERR invoke wsprintf,addr szBuffer,addr szStart2,eax invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK .endif .endif
Edit类 Edit-Messages EM_LIMITTEXT设置编辑框可输入的最多的字符串个数 invoke SendDlgItemMessage,hWnd,WM_USER+4,EM_LIMITTEXT,4,0;一个中文占2个字节 EM_REPLACESEL用制定字符串替换选中的字符,如果未选中任何字符的话,自动追加到末尾. invoke SendDlgItemMessage,hWnd,WM_USER+4,EM_REPLACESEL,0,addr szText11 invoke SendDlgItemMessage,hWnd,WM_USER+4,EM_REPLACESEL,0,addr szText22 WM_SETTEXT设置编辑框的字符串 invoke SendDlgItemMessage,hWnd,WM_USER+4,WM_SETTEXT,0,addr szText11 WM_GETTEXT获得编辑框的字符串 invoke SendDlgItemMessage,hWnd,WM_USER+4,WM_GETTEXT,sizeof @szBuffer2,addr @szBuffer2 invoke MessageBox,NULL,addr @szBuffer2,offset szCaption,MB_OK;注意局部变量时必须用addr伪指令
Static类 Static-Messages 以下是用两种方式向控件发送消息来控制控件的 invoke SendMessage,eax,STM_SETIMAGE,IMAGE_BITMAP,hBmp1;CreateWindowEx中样式用SS_BITMAP invoke GetDlgItem,hWnd,WM_USER+7;用于更改控件上的图片 invoke SendMessage,eax,STM_SETIMAGE,IMAGE_BITMAP,hBmp2 invoke SendMessage,eax,STM_SETIMAGE,IMAGE_ICON,hIco1;用于输出图标,CreateWindowEx中样式用SS_ICON
设置STATIC控件上的文字 invoke SetWindowText,eax,addr szButton;通过调用win32 api ,其实这个函数也是控件发送了WM_SETTEXT消息实现的(MSDN中可以看到) invoke SendMessage,eax,WM_SETTEXT,0,addr szComboBox;通过发送WM_S, ETTEXT来实现 Static- Notifications STN_CLICKED elseif ax ==WM_USER+7;静态控件,CreateWindwoEx时制定了SS_NOTIFY shr eax,16 .if ax ==STN_CLICKED ;用户从列表框中选择了一个条目 invoke MessageBox,NULL,offset jk,offset jk,MB_OK .endif
原文:http://www.jiangkai.net/layertwo/mandn.html
|
|
|