您的位置:程序门 -> vc/mfc -> 基础类



框架内创建控件问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


框架内创建控件问题[已结贴,结贴人:caitian6]
发表于:2007-07-21 16:21:09 楼主
int   cmainframe::oncreate(lpcreatestruct   lpcreatestruct)
{
if   (cframewnd::oncreate(lpcreatestruct)   ==   -1)
return   -1;
m_button.create( "button ",   bs_pushbutton,   crect(   0,25,70,   70),this,100);
m_button.showwindow(sw_show);
m_button.enablewindow(true);
}
为什么m_button总是处于非编辑状态,怎么才可以让它响应单击事件了?
发表于:2007-07-21 16:32:511楼 得分:0
自己加消息响应就可以了`
发表于:2007-07-21 16:47:012楼 得分:0
添加过了消息,就是不能响应,
整个按钮都是灰的,明明enablewindow(true)了
发表于:2007-07-21 16:53:223楼 得分:10
贴出你加的代码```
发表于:2007-07-21 17:07:564楼 得分:0
mainframe.h
afx   void     onbutton();

mainframe.cpp

on_bn_clicked(100,   mybutton)

void   cmainframe::mybutton()
{
messagebox( "aaa ");
}
这是消息响应的代码,都在这了

发表于:2007-07-21 22:38:275楼 得分:0
ws_child?
发表于:2007-07-23 08:26:266楼 得分:0
试过了,还是没用
发表于:2007-07-23 10:30:137楼 得分:10
当你以bs_pushbutton类型创建一个button时,此button将通过wm_command来传递相关消息,你应该在cmainframe里重载oncommnd()虚函数来响应单击消息,比如:
        bool   cxxxx::oncommnd(wparam   wparam,   lparam   lparam)
              {
                  if(hiword(wparam)   ==   bn_clicked)//notify   message
                  {
                      if(loword(wparam)==   100)//control   id
                      {
                          //do   someting   you   want
                        }
                  }
                  return   cwnd::oncommand(wparam,lparam)
 
              }
发表于:2007-07-23 12:19:588楼 得分:0
谢谢,但我的问题是整个按钮都用不了,是灰色的
如何才能使它变为可用啊???


快速检索

最新资讯
热门点击