动态创建控件,设置控件属性

我在对对话框里的一个按钮下动态建立一个CListBox控件。CMyButton*pbt=newCMyButton();pbt->Create(LBS_SORT|LB... 我在对对话框里的一个按钮下动态建立一个CListBox控件。
CMyButton *pbt = new CMyButton();
pbt->Create(LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL |

WS_HSCROLL | WS_TABSTOP |WS_CHILD |WS_VISIBLE,

CRect(100,100,200,200),this,IDC_BTN);
pbt->InsertString(0,"str");
还写了一个消息响应双击str字符串的消息,做了消息映射,但是没能调用消息函数。
后来我手动的建立一个控件,右键在属性话框把控件样式的Notify勾去掉,那么这个手动的CListBox控件同样不能响应事件。
请问在代码里怎么给动态控件设置Notify样式
展开
 我来答
匿名用户
2013-09-13
展开全部
LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL |

WS_HSCROLL | WS_TABSTOP |WS_CHILD |WS_VISIBLE|LBS_NOTIFY
;在上面第一个位置;这个下面是文档的信息;这个样式组要是决定了是否通知父类的消息;

BEGIN_MESSAGE_MAP(CDynamicCtrlDlg, CDialog)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CMyButton, CListBox)
//这个加入你要的消息

如WM_CLOSE
END_MESSAGE_MAP()

强调下啊,在这个消息映射表的的信息可以由本窗口处理,其他的消息,你没有给出定义的消息函数的,都交给上一层的基类处理;
很多都是因为上面有相关的处理;

MFC Library Reference
List-Box Styles
See Also Send Feedback

Updated: November 2007

LBS_DISABLENOSCROLL
The list box shows a disabled vertical scroll bar when the list box does not contain enough items to scroll. Without this style, the scroll bar is hidden when the list box does not contain enough items.

LBS_EXTENDEDSEL
The user can select multiple items using the SHIFT key and the mouse or special key combinations.

LBS_HASSTRINGS
Specifies an owner-draw list box that contains items consisting of strings. The list box maintains the memory and pointers for the strings so the application can use the GetText member function to retrieve the text for a particular item.

LBS_MULTICOLUMN
Specifies a multicolumn list box that is scrolled horizontally. The SetColumnWidth member function sets the width of the columns.

LBS_MULTIPLESEL
String selection is toggled each time the user clicks or double-clicks the string. Any number of strings can be selected.

LBS_NODATA
Specifies a no-data list box. Specify this style when the count of items in the list box will exceed one thousand. A no-data list box must also have the LBS_OWNERDRAWFIXED style, but must not have the LBS_SORT or LBS_HASSTRINGS style.

A no-data list box resembles an owner-drawn list box except that it contains no string or bitmap data for an item. Commands to add, insert, or delete an item always ignore any given item data; requests to find a string within the list box always fail. The system sends the WM_DRAWITEM message to the owner window when an item must be drawn. The itemID member of the DRAWITEMSTRUCT structure passed with the WM_DRAWITEM message specifies the line number of the item to be drawn. A no-data list box does not send a WM_DELETEITEM message.

LBS_NOINTEGRALHEIGHT
The size of the list box is exactly the size specified by the application when it created the list box. Usually, Windows sizes a list box so that the list box does not display partial items.

LBS_NOREDRAW
List-box display is not updated when changes are made. This style can be changed at any time by sending a WM_SETREDRAW message.

LBS_NOSEL
Specifies that the list box contains items that can be viewed but not selected.

LBS_NOTIFY
Parent window receives an input message whenever the user clicks or double-clicks a string.

LBS_OWNERDRAWFIXED
The owner of the list box is responsible for drawing its contents; the items in the list box are the same height.

LBS_OWNERDRAWVARIABLE
The owner of the list box is responsible for drawing its contents; the items in the list box are variable in height.

LBS_SORT
Strings in the list box are sorted alphabetically.

LBS_STANDARD
Strings in the list box are sorted alphabetically, and
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式