在界面上有一个static控件,想根据这个控件的大小来填充其内部的颜色,该怎么获得这个控件的大小啊,还是有什么别的办法,谢谢了。

解决方案 »

  1.   

    先获得窗口句柄
    CWnd *pWnd = (CWnd*)GetDlgItem(IDC_STATIC);//该控件ID
    RECT rect;
    pWnd->GetClientRect(&rect);
      

  2.   

    简单的办法响应窗口ON_CTLCOLOR消息,返回需要颜色的刷子就成
      

  3.   

    HBRUSH CFmsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    if (IDC_STT_TITLE == pWnd->GetDlgCtrlID())
        {
            pDC->SetTextColor(RGB(0, 0, 255));
            pDC->SetBkMode(TRANSPARENT);
            hbr = m_hTitleBrush; //这里是你需要的颜色的画刷
        }
    // TODO: Return a different brush if the default is not desired
    return hbr;
    }