永发信息网

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

答案:1  悬赏:20  手机版
解决时间 2021-03-10 11:39
我在对对话框里的一个按钮下动态建立一个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样式
最佳答案
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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
怎样挑选荔浦芋
东头小学这个地址在什么地方,我要处理点事
雷克萨斯保养免费吗
天龙八部纯副本火逍遥如何打石头,还有雕纹
西安事变中,蒋介石被释放的原因是什么
钟缘便当同曦鸣城店地址在什么地方,想过去办
魔兽世界战友招募提升等级是什么意思?
御来三汁焖锅门源加盟店在哪里啊,我有事要去
呼包鄂乌四地的交通地图
【杨玉环的故事】白朴的()第一次把唐明皇和杨
今华生物能源科技发展有限公司地址在哪,我要
找一张动态图片是一个人跳街舞然后有一个心图
青岛城阳区的社保基数是多少
临清名吃扣碗在什么地方啊,我要过去处理事情
【下面火柴棒摆成的算是都是错误的,移动一根
推荐资讯
电池命名,电池R14中14代表什么
壳牌机油的优缺点是什么?
关于爱情的4个字的对联
想办炉窑工程施工资质注册公司经营范围怎么写
杜甫本人则被称为什么
已知水电解的方程式,在不同条件下1摩尔氢气和
鱼缸经常在阳光下晒有好处吗
研究物体的浮沉条件 漂浮 悬浮 下沉 上浮 物
封神太子2白虎殿在哪 怎么去
杭州小强热线免费法律援助
【剑网3】称号“赤炼”如何获得?
用牛奶洗皮肤和用醋洗头真的有好效果么?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?