//设置应用标题栏按钮 Int32 SetAppTitleButton(TWindow * pWindow, Int32 nResId, int ButtonPosition) { Int32 m_BtnID = 0; TButton *pBtn; TRectangle BtnRC_Left(TITLE_BUTTON_X, TITLE_BUTTON_Y, TITLE_BUTTON_W, TITLE_BUTTON_H); TRectangle BtnRC_Right(SCR_W-TITLE_BUTTON_X-TITLE_BUTTON_W, TITLE_BUTTON_Y, TITLE_BUTTON_W, TITLE_BUTTON_H); TFont tFont; const TBitmap * pNormalBmp = TResource::LoadConstBitmap(APP_KA_ID_BITMAP_button53); const TBitmap * pOverBmp = TResource::LoadConstBitmap(APP_KA_ID_BITMAP_button53_over); if(TUString::StrLen(TResource::LoadConstString(nResId)) <= 2) tFont.Create(FONT_NORMAL, FONT_NORMAL, FONT_STYLE_BOLD); else tFont.Create(FONT_MIDDLE, FONT_MIDDLE, FONT_STYLE_BOLD); pBtn = new TButton; if(pBtn->Create(pWindow)) { if(ButtonPosition == TITLE_BUTTON_LEFT) pBtn->SetBounds(&BtnRC_Left); else pBtn->SetBounds(&BtnRC_Right); m_BtnID = pBtn->GetId(); pBtn->SetFont(tFont); pBtn->SetColor(CTL_COLOR_TYPE_FORE,RGB_COLOR_WHITE); pBtn->SetColor(CTL_COLOR_TYPE_BACK,RGB_COLOR_WHITE); pBtn->SetColor(CTL_COLOR_TYPE_FOCUS_FORE,RGB_COLOR_WHITE); pBtn->SetColor(CTL_COLOR_TYPE_FOCUS_BACK,RGB_COLOR_WHITE); pBtn->SetCaption(TResource::LoadConstString(nResId),FALSE); pBtn->SetStyles(BTN_STYLES_GRAPGICS); pBtn->SetImage(pNormalBmp,0); pBtn->SetImage(pOverBmp,1); pBtn->Show(TRUE); } return m_BtnID; }
Int32 SetAppTitleButton(TWindow * pWindow, const TUChar* pszResTxt, int ButtonPosition) { Int32 m_BtnID = 0; TRectangle BtnRC_Left(TITLE_BUTTON_X, TITLE_BUTTON_Y, TITLE_BUTTON_W, TITLE_BUTTON_H); TRectangle BtnRC_Right(SCR_W-TITLE_BUTTON_X-TITLE_BUTTON_W, TITLE_BUTTON_Y, TITLE_BUTTON_W, TITLE_BUTTON_H); Coord nWidth = 0; Int32 nResIDNormal = 0; Int32 nResIDOver = 0; int nFontSize = 0; //根据显示文本的长短设置图标及文字大小 switch( TUString::StrLen(pszResTxt) ) { case 2: { nWidth = TITLE_BUTTON_W; nFontSize = FONT_NORMAL; nResIDNormal = APP_KA_ID_BITMAP_button53; nResIDOver = APP_KA_ID_BITMAP_button53_over; } break; case 3: { nWidth = TITLE_BUTTON_W; nFontSize = FONT_NORMAL; nResIDNormal = APP_KA_ID_BITMAP_button53; nResIDOver = APP_KA_ID_BITMAP_button53_over; } break; case 4: { nWidth = TITLE_BUTTON_W; nFontSize = FONT_NORMAL; nResIDNormal = APP_KA_ID_BITMAP_button53; nResIDOver = APP_KA_ID_BITMAP_button53_over; } break; case 5: { nWidth = TITLE_BUTTON_W; nFontSize = FONT_MIDDLE; nResIDNormal = APP_KA_ID_BITMAP_button53; nResIDOver = APP_KA_ID_BITMAP_button53_over; } break; case 6: default: { nWidth = TITLE_BUTTON_W; nFontSize = FONT_SMALL; nResIDNormal = APP_KA_ID_BITMAP_button53; nResIDOver = APP_KA_ID_BITMAP_button53_over; } break; } TFont tFont; const TBitmap* pNormalBmp = TResource::LoadConstBitmap(nResIDNormal); const TBitmap* pOverBmp = TResource::LoadConstBitmap(nResIDOver); tFont.Create(nFontSize, nFontSize, FONT_STYLE_BOLD); TButton* pBtn = new TButton; if(pBtn->Create(pWindow)) { BtnRC_Left.SetWidth(nWidth); BtnRC_Right.SetWidth(nWidth); BtnRC_Right.SetX(SCR_W-TITLE_BUTTON_X-nWidth); if(ButtonPosition == TITLE_BUTTON_LEFT) pBtn->SetBounds(&BtnRC_Left); else pBtn->SetBounds(&BtnRC_Right); m_BtnID = pBtn->GetId(); pBtn->SetFont(tFont); pBtn->SetColor(CTL_COLOR_TYPE_FORE,RGB_COLOR_WHITE); pBtn->SetColor(CTL_COLOR_TYPE_BACK,RGB_COLOR_WHITE); pBtn->SetColor(CTL_COLOR_TYPE_FOCUS_FORE,RGB_COLOR_WHITE); pBtn->SetColor(CTL_COLOR_TYPE_FOCUS_BACK,RGB_COLOR_WHITE); pBtn->SetCaption(pszResTxt,FALSE); pBtn->SetStyles(BTN_STYLES_GRAPGICS); pBtn->SetImage(pNormalBmp,0); pBtn->SetImage(pOverBmp,1); pBtn->Show(TRUE); } return m_BtnID; }