我刚学vc,请问怎样用vc做一个控件,如我在原来CButton上继承了一个类,怎样把它放到control 面板上

解决方案 »

  1.   

    关注~~!
    我也很想知道。
    我还想知道VC能不能像VB一样从部件中调出其它控件,如能调出如何调?
      

  2.   


    zhaowenlong(梦难求)的说法不对,因为我初做控件时也遇到这个问题,应该说很简单,
    也无人给我回答,也有人含糊地这么一说1.先用MFC ActiveX ControlWizard 生成你的工程(假如为test)
    2.把继承的类,添加到你工程中去
    以下是举我的例子,在原来CRichEditCtrl上继承了一个类,把它放到control 面板上class CTestCtrl : public COleControl
    {
    public:
    CmyRichEditCtrl m_rich;
    };int CTestCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (COleControl::OnCreate(lpCreateStruct) == -1)
    return -1;

    // TODO: Add your specialized creation code here // TODO: Add your specialized creation code here
    CRect rect(0,0,100,100);
    m_rich.Create( ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN
    | WS_CHILD | WS_VISIBLE | WS_VSCROLL,
    rect, this, 1);
    return 0;
    }
    void CTestCtrl::OnDraw(
    CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
    {
    // TODO: Replace the following code with your own drawing code.
    //pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
    //pdc->Ellipse(rcBounds); m_rich.MoveWindow(rcBounds,TRUE);
    }void CTestCtrl::OnSize(UINT nType, int cx, int cy) 
    {
    COleControl::OnSize(nType, cx, cy);

    // TODO: Add your message handler code here CRect rect;
    GetClientRect(rect);
    m_rich.SetWindowPos(&wndTop,0,0,rect.right-rect.left,
                    rect.bottom - rect.top, SWP_SHOWWINDOW);
    }