现在我有一个继承的mybutton,在formview初始化时已经放在了formview上,定义有OnLButtonUp消息,我希望当触发mybutton的OnLButtonUp消息时,在formview另外添加一个mybutton
请问如何实现?
小弟刚开始学vc还希望高人多多指点

解决方案 »

  1.   

    同楼上,那就在OnLButtonUp的响应函数里动态创建一个按钮阿动态创建按钮自己在CSDN搜把,一搜一大堆
      

  2.   

    在OnLButtonUp消息函数中动态创建 CreateWindow
      

  3.   

    OnLButton是在Button的类中定义的
    如果要在FormView上创建Button
    parent指针怎么取得呢?
      

  4.   

    但是在Button类的OnLButton消息处理中调用create如下
    // create shapes for button
    // make sure that region is in button client coordinates HRGN r; 
    // RECTANGULAR BUTTONS
    r = CreateEllipticRgn(0, 0, 63, 63);
    this->Create("Btn 1", WS_CHILD | WS_VISIBLE, CPoint(150, 150), r, this->GetParent, 1002,RGB(255, 255, 0));
    DeleteObject(r);
    这样总是运行会有错误
      

  5.   

    r应该是LPRECT类型的,或者CRect。
      

  6.   

    // create shapes for button
    // make sure that region is in button client coordinates HRGN r; 
    // RECTANGULAR BUTTONS
    r = CreateEllipticRgn(0, 0, 63, 63);
    m_Btn1.Create("Btn 1", WS_CHILD | WS_VISIBLE, CPoint(150, 150), r, this, 1002,RGB(255, 255, 0));
    DeleteObject(r);
    在Formview的初始化函数里调用上述代码,得到的结果是正确的。
    CreateEllipticRgn是因为我继承CButton 后,重载DrawItem绘制圆形的按钮,所以使用画圆的区域。
    在OnLButton使用
    // create shapes for button
    // make sure that region is in button client coordinates HRGN r; 
    // RECTANGULAR BUTTONS
    r = CreateEllipticRgn(0, 0, 63, 63);
    this->Create("Btn 1", WS_CHILD | WS_VISIBLE, CPoint(150, 150), r, this->GetParent, 1002,RGB(255, 255, 0));
    DeleteObject(r);
    这一代码时,程序可以运行,但触发OnLButton消息后,程序出错,显示debug assertion failed!