ExampleCButton myButton1, myButton2, myButton3, myButton4;// Create a push button. myButton1.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), pParentWnd, 1);// Create a radio button. myButton2.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON, CRect(10,40,100,70), pParentWnd, 2);// Create an auto 3-state button. myButton3.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_AUTO3STATE, CRect(10,70,100,100), pParentWnd, 3);// Create an auto check box. myButton4.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect(10,100,100,130), pParentWnd, 4);
CButton btn; btb.create(...); 具体可以参考帮助文档。
注意CButton类型变量的生命周期,最好设为类的成员变量
MSDN我也会查啦! 添加了按钮当然是要用的啦,怎么写响应函数啊?
在创建button是的函数create中有个参数就是这个按钮的响应函数,你把这个函数写好不就ok了
这个MSDN里面说的比较好,以CListBox 为例: You can create a list box either from a dialog template or directly in your code. To create it directly, construct the CListBox object, then call the Create member function to create the Windows list-box control and attach it to the CListBox object. 关于你说的添加响应函数问题: MFC里控件的消息响应函数都已被封装,你直接用就行了,每个控件它都提供了很多的接口函数,应该够用了。如果你非要自己弄,可以从建个新类,从MFC的控件类继承,然后重载各个响应函数
myButton1.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
CRect(10,10,100,30), pParentWnd, 1);// Create a radio button.
myButton2.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,
CRect(10,40,100,70), pParentWnd, 2);// Create an auto 3-state button.
myButton3.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_AUTO3STATE,
CRect(10,70,100,100), pParentWnd, 3);// Create an auto check box.
myButton4.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,
CRect(10,100,100,130), pParentWnd, 4);
btb.create(...);
具体可以参考帮助文档。
添加了按钮当然是要用的啦,怎么写响应函数啊?
You can create a list box either from a dialog template or directly in your code. To create it directly, construct the CListBox object, then call the Create member function to create the Windows list-box control and attach it to the CListBox object.
关于你说的添加响应函数问题:
MFC里控件的消息响应函数都已被封装,你直接用就行了,每个控件它都提供了很多的接口函数,应该够用了。如果你非要自己弄,可以从建个新类,从MFC的控件类继承,然后重载各个响应函数