Int32 CtrlAddItemToWin_Label(TWindow*pWin, Coord nX, Coord nY, Coord nWidth, Int32 FontSize, TUChar* pszString, ColorRefType Color) { TLabel* pLabel = new TLabel(); Int32 nLabelID = 0; if(pLabel->Create(pWin)) { TRectangle obBtnRec(0,0,0,0); if(nWidth == 0) { nWidth = 80; obBtnRec.SetRect(nX, nY, nWidth, FontSize); pLabel->SetBounds(&obBtnRec); pLabel->SetAutoSize(TRUE); CtrlSetFont((TCtrl*)pLabel, FontSize, Color); pLabel->SetCaption(pszString,FALSE); } else { obBtnRec.SetRect(nX, nY, nWidth, FontSize); pLabel->SetBounds(&obBtnRec); pLabel->SetAutoSize(FALSE); pLabel->SetScrollMode(lsmNone); TFont tFont; tFont.Create(FontSize, FontSize); ShowAsShort((TCtrl *)pLabel, pszString, tFont); pLabel->SetFont(tFont); pLabel->SetColor(CTL_COLOR_TYPE_FORE, Color); } } return nLabelID; }
//添加Label控件到CoolBarList, // pszString必须是动态的(非Static) // nWidth 为0 -- 自动长度 Int32 CtrlAddItemToCoolBarList_Lable(TWindow*pWin, TBarListItem* pListItem, Coord nX, Coord nY, Coord nWidth, Int32 FontSize, TUChar* pszString, ColorRefType Color) { TRectangle obBtnRec(0,0,0,0); Int32 nLabelNameId = pListItem->AddCtrl(CTL_CLASS_LABEL, 0, 0); TLabel* pLabelName = static_cast<TLabel*>(pWin->GetControlPtr(nLabelNameId)); if(nWidth == 0) { nWidth = 80; obBtnRec.SetRect(nX, nY, nWidth, FontSize); pLabelName->SetBounds(&obBtnRec); pLabelName->SetAutoSize(TRUE); CtrlSetFont((TCtrl*)pLabelName, FontSize, Color); pLabelName->SetCaption(pszString,FALSE); } else { obBtnRec.SetRect(nX, nY, nWidth, FontSize+6); //调整高度,防止字体底部被截断 pLabelName->SetBounds(&obBtnRec); pLabelName->SetAutoSize(FALSE); pLabelName->SetScrollMode(lsmNone); TFont tFont; tFont.Create(FontSize, FontSize); ShowAsShort((TCtrl *)pLabelName, pszString, tFont); pLabelName->SetFont(tFont); pLabelName->SetColor(CTL_COLOR_TYPE_FORE, Color); } pLabelName->SetEnabled(FALSE); return nLabelNameId; }