永发信息网

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

答案:1  悬赏:20  手机版
解决时间 2021-03-10 11:39
  • 提问者网友:却不属于对方
  • 2021-03-09 16:07
我在对对话框里的一个按钮下动态建立一个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样式
最佳答案
  • 五星知识达人网友:廢物販賣機
  • 2021-03-09 16:32
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
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯