Results 1 to 10 of 15

Thread: Create ActiveX Button

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Join Date
    Mar 2009
    Posts
    1,424

    Default Re: Create ActiveX Button

    Also added font characteristics:

    Code:
    void CActiveXButtonCtrl::OnDraw(
        CDC* pdc, const CRect& rcBounds, const CRect& /* rcInvalid */)
    {
        if (!pdc)
            return;
    
        DoSuperclassPaint(pdc, rcBounds);
    
        RECT bounds = rcBounds;
    
        CFont font;
        VERIFY(font.CreateFont(
            0,                       // nHeight
            0,                        // nWidth
            0,                        // nEscapement
            0,                        // nOrientation
            FW_BOLD,                  // nWeight (FW_NORMAL, FW_REGULAR, FW_BOLD, FW_DONTCARE)
            FALSE,                    // bItalic
            FALSE,                    // bUnderline
            FALSE,                    // cStrikeOut
            ANSI_CHARSET,             // nCharSet
            OUT_DEFAULT_PRECIS,       // nOutPrecision
            CLIP_DEFAULT_PRECIS,      // nClipPrecision
            DEFAULT_QUALITY,          // nQuality
            DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
            _T("Arial")));            // lpszFacename  "Times New Roman"
    
        // Do something with the font just created...
        CClientDC dc(this);
        CFont* def_font = dc.SelectObject(&font);
    
        CBrush bkBrush(TranslateColor(GetBackColor()));
        pdc->FillRect(rcBounds, &bkBrush);
        pdc->DrawEdge(&bounds, EDGE_RAISED, BF_RECT);
        dc.SetTextColor(TranslateColor(GetForeColor()));
        dc.SetBkMode(TRANSPARENT);
        dc.DrawText(InternalGetText(), -1, &bounds, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
    
        dc.SelectObject(def_font);
    
        // Done with the font.  Delete the font object.
        font.DeleteObject();
    
    }
    Last edited by Sam Neuner; 1-Apr-2021 at 02:32 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •