为按钮添加事件

lodemenwwwww 2010-04-08 05:02:02
我现在有一个按钮
当我按下的时候就又创建出来一个按钮

新创建出来的按钮的位置怎么控制?
如何给它上面添加图片并添加鼠标的电击事件呢?

谢谢各位了
...全文
206 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoling8825 2010-04-08
  • 打赏
  • 举报
回复
btn3 = new CButton();
int n = 10001;
btn3->Create("按钮3",BS_PUSHBUTTON|WS_VISIBLE|WS_CHILD,
CRect(250,250,320,270),this,n);
n++;
这样就想创建多少就创建多少了。
zxdyu2009 2010-04-08
  • 打赏
  • 举报
回复
new 一个CButton 用Create函数创建她,

CButton::Create
BOOL Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );

Return Value

Nonzero if successful; otherwise 0.

Parameters

lpszCaption

Specifies the button control’s text.

dwStyle

Specifies the button control’s style. Apply any combination of button styles to the button.

rect

Specifies the button control’s size and position. It can be either a CRect object or a RECT structure.

pParentWnd

Specifies the button control’s parent window, usually a CDialog. It must not be NULL.

nID

Specifies the button control’s ID.

参数rect指示了Button的大小与位置,参数ID指示了这个新创建的Button的ID号,你给定。

hzy694358 2010-04-08
  • 打赏
  • 举报
回复
根据ID,然后MoveWindow,或SetWindowPos
zxdlms 2010-04-08
  • 打赏
  • 举报
回复
不知道ID号怎么能创建啊。

使用使用create的时候会传入一个ID值的,然后你用这个ID值做消息映射就好了。
hellward 2010-04-08
  • 打赏
  • 举报
回复
按钮的动态创建,及添加消息响应函数
btn3 = new CButton();
btn3->Create("按钮3",BS_PUSHBUTTON|WS_VISIBLE|WS_CHILD,
CRect(250,250,320,270),this,10003);
其中最后一个参数10003,是ID号,一定要大于100,因为100以内为VC编译系统使用.
父窗口重载 PreTranslateMessage(MSG* pMsg)
if(pMsg->hwnd == m_button.m_hWnd) //按钮窗口句柄
{
if(pMsg->message == WM_LBUTTONDOWN)//鼠标点击消息
{
//在这里处理
Beep(1000,100);
}
}
Eleven 2010-04-08
  • 打赏
  • 举报
回复
你的按钮不是Create出来的吗?最后一个参数是ID值啊
lodemenwwwww 2010-04-08
  • 打赏
  • 举报
回复
这个新按钮时在程序运行的时候创建出来的
我不清楚如何得到他的ID号阿
Eleven 2010-04-08
  • 打赏
  • 举报
回复
你创建这个新按钮的时候不是有个ID号吗?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧