飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 4477|回复: 7

[其他源码] 程序开发皮肤+皮肤组件源码

[复制链接]
  • TA的每日心情
    慵懒
    2020-9-27 20:02
  • 签到天数: 7 天

    [LV.3]偶尔看看II

    发表于 2012-4-4 18:14:38 | 显示全部楼层 |阅读模式
    源码发布概况
    编程语言: VC/C++
    详细描述: VC程序开发皮肤+皮肤组件源码
    网址: bbs.chinapyg.com
    本帖最后由 爱民 于 2012-4-7 11:27 编辑



    1. #include "FlatTab.h"
    2. namespace FreeCL
    3. {
    4. FlatPage::FlatPage() : mPropertyBegin(this)
    5. {
    6. mTag = 0;
    7. m_Index = -1;
    8. m_Image = -1;
    9. m_Owner = NULL;
    10. m_TextColor = (uint)::GetSysColor(COLOR_BTNTEXT);
    11. }
    12. FlatPage::~FlatPage()
    13. {
    14. while(m_ControlList.size() > 0)
    15.   RemoveControl(m_ControlList.back());
    16. }   
    17. sint FlatPage::GetIndex()
    18. {
    19. return m_Index;
    20. }
    21. void FlatPage::SetText(cstr name)
    22. {
    23. m_Name = name;
    24. m_Owner->UpdateLabelRect(m_Index);
    25. if(m_Owner->IsVisible())
    26.   ::InvalidateRect(m_Owner->GetHandle(), NULL, TRUE);
    27. }
    28. cstr FlatPage::GetText()
    29. {
    30. return m_Name.c_str();
    31. }
    32. void FlatPage::SetImage(int image)
    33. {
    34. m_Image = image;
    35. if(m_Owner->IsVisible())
    36.   ::InvalidateRect(m_Owner->GetHandle(), (const RECT*)&m_Rect, TRUE);
    37. }
    38. sint FlatPage::GetImage()
    39. {
    40. return m_Image;
    41. }
    42. void FlatPage::SetTextColor(uint color)
    43. {
    44. m_TextColor = color & 0x00ffffff;
    45. if(m_Owner->IsVisible())
    46.   ::InvalidateRect(m_Owner->GetHandle(), (const RECT*)&m_Rect, TRUE);
    47. }
    48. uint FlatPage::GetTextColor()
    49. {
    50. return m_TextColor;
    51. }
    52. Rect FlatPage::GetRect()
    53. {
    54. return m_Rect;
    55. }
    56. FlatTab* FlatPage::GetParent()
    57. {
    58. return m_Owner;
    59. }
    60. WinControl* FlatPage::GetOwner()
    61. {
    62. return m_Owner;
    63. }
    64. bool FlatPage::IsClientEmpty()
    65. {
    66. return false;
    67. }
    68. void FlatPage::AddControl(WinControl* control)
    69. {
    70. if(!control || control->IsMenu() || control == m_Owner || control->m_SubRegion ||
    71.   (control->GetParent() != m_Owner->GetParent() && control->GetParent() != m_Owner))
    72. {
    73. #ifdef _DEBUG
    74.   ::DebugBreak();
    75. #endif
    76.   return;
    77. }
    78. bool found = false;
    79. for(int i = 0; i < int(m_ControlList.size()); i++)
    80. {
    81.   if(m_ControlList == control)
    82.   {
    83.    found = true;
    84.    break;
    85.   }
    86. }
    87. if(!found)
    88. {
    89.   m_ControlList.push_back(control);
    90.   control->m_SubRegion = this;
    91.   if(m_Owner->GetSelectedPage() != this)
    92.    control->Hide();   
    93.   if(control->IsWinControl())
    94.    ((WinControl*)control)->InsertFront(m_Owner);
    95. }
    96. }
    97. void FlatPage::RemoveControl(WinControl* control)
    98. {
    99. for(int i = 0; i < int(m_ControlList.size()); i++)
    100. {
    101.   if(m_ControlList == control)
    102.   {           
    103.    if(this != m_Owner->GetSelectedPage())
    104.     control->Show();
    105.    control->m_SubRegion = NULL;
    106.    m_ControlList.erase(m_ControlList.begin()+i);
    107.    return;
    108.   }
    109. }
    110. }
    111. void FlatPage::ShowAllControl()
    112. {
    113. for(uint i=0; i < m_ControlList.size(); i++)
    114.   m_ControlList->Show();
    115. }
    116. void FlatPage::HideAllControl()
    117. {
    118. for(uint i=0; i < m_ControlList.size(); i++)
    119.   m_ControlList->Hide();
    120. }
    121. //---------------------------------------------------------------------------------------------------------------------------------------
    122. FlatTab::FlatTab() : mEventBegin(this), mPropertyBegin(this)
    123. {      
    124. m_ImageList = NULL;
    125. m_SelectedPage = NULL;
    126. }
    127. FlatTab::~FlatTab()
    128. {
    129. }
    130. bool FlatTab::CreateFlatTab(WinContainer* parent,int left,int top,int width,int height,FlatTabDesc& desc)
    131. {
    132. if(parent)
    133. {
    134.   DWORD style = WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
    135.   m_Handle = ::CreateWindowEx(WS_EX_CONTROLPARENT, "FreeCL_Common_Window", "", style,
    136.    left, top, width, height, parent->GetHandle(), NULL, gModule, NULL);
    137.   if(m_Handle)
    138.   {   
    139.    m_Desc = desc;
    140.    m_Parent = parent;
    141.    
    142.    m_OldLeft = left;
    143.    m_OldTop = top;
    144.    m_OldWidth = width;
    145.    m_OldHeight = height;
    146.    m_Left = left;
    147.    m_Top = top;
    148.    m_Width = width;
    149.    m_Height = height;  
    150.    ::SendMessage(m_Handle, WM_SETFONT, (WPARAM)parent->GetFont(), FALSE);
    151.    ::SetWindowLong(m_Handle, GWL_ID, (LONG)m_Id);
    152.    m_Parent->AddWinControl(this);
    153.    OnControlCreate();
    154.    OnCreate();  
    155.    ::ShowWindow(m_Handle, SW_SHOW);
    156.    return true;
    157.   }
    158. #ifdef _DEBUG
    159.   else
    160.    ::DebugBreak();
    161. #endif
    162. }
    163. return false;
    164. }
    165. bool FlatTab::CreateControl(WinContainer* parent,int left,int top,int width,int height)
    166. {
    167. FlatTabDesc desc;
    168. return CreateFlatTab(parent,left,top,width,height,desc);
    169. }
    170. void FlatTab::DestroyControl()
    171. {   
    172. DeleteAllPage();
    173. WinContainer::DestroyControl();
    174. m_ImageList = NULL;
    175. m_SelectedPage = NULL;
    176. m_Desc = FlatTabDesc();
    177. }
    178. cstr FlatTab::GetClass()
    179. {
    180. return "FlatTab";
    181. }
    182. bool FlatTab::IsFlatTab()
    183. {
    184. return true;
    185. }
    186. cstr FlatTab::GetCaption()
    187. {
    188. return "";
    189. }
    190. void FlatTab::SetCaption(cstr)
    191. {
    192. }
    193. void FlatTab::Hide()
    194. {
    195. WinContainer::Hide();
    196. int count = GetPageCount();
    197. for(int i = 0; i < count; i++)
    198. {
    199.   FlatPage* page = GetPage(i);
    200.   page->HideAllControl();
    201. }
    202. }
    203. void FlatTab::Show()
    204. {
    205. WinContainer::Show();
    206. int count = GetPageCount();
    207. for(int i = 0; i < count; i++)
    208. {
    209.   FlatPage* page = GetPage(i);
    210.   page->ShowAllControl();
    211. }
    212. }
    213. bool FlatTab::UseDoubleBuffer()
    214. {
    215. return true;
    216. }
    217. void FlatTab::OnCreate()
    218. {
    219. }
    220. HFONT FlatTab::GetFont()
    221. {
    222. return m_Parent->GetFont();
    223. }
    224. inline bool TestRect(const RECT& r1, const RECT& r2)
    225. {
    226. return bool(r2.right <= r1.left || r1.right <= r2.left || r2.bottom <= r1.top || r1.bottom <= r2.top);
    227. }
    228. void FlatTab::UpdateLabelRect(int index)
    229. { //重新计算指定标签及其后面的所有标签的矩形
    230. if(0 <= index && index < GetPageCount())
    231. {
    232.   RECT cRect;
    233.   ::GetClientRect(m_Handle, &cRect);
    234.   int xOffset;
    235.   if(index == 0)
    236.    xOffset = 1;
    237.   else
    238.   {
    239.    FlatPage* page = GetPage(index-1);
    240.    if(page != GetSelectedPage())
    241.     xOffset = page->GetRect().mRight;
    242.    else
    243.     xOffset = page->GetRect().mRight-1;
    244.   }
    245.   int iSpace = m_Desc.mSpace;
    246.   HDC dc = ::GetDC(m_Handle);
    247.   HGDIOBJ iFont = ::SelectObject(dc, m_Parent->GetFont());
    248.   WinImageList* imageList = GetImageList();
    249.   for(uint i = index; i < m_PageList.size(); i++)
    250.   {
    251.    FlatPage* page = GetPage(i);
    252.    int iWidth = 2 + m_Desc.mMargin*2;
    253.    if(imageList)
    254.     iWidth += imageList->GetImageWidth() + iSpace;
    255.    cstr iText = page->GetText();
    256.    int iLen = strlen(iText);
    257.    if(iLen > 0)
    258.    {
    259.     SIZE iSize;
    260.     ::GetTextExtentPoint32(dc, iText, iLen, &iSize);
    261.     iWidth += iSize.cx;
    262.    }
    263.    if(GetSelectedPage() != page)
    264.    {
    265.     page->m_Rect.mLeft = xOffset;
    266.     page->m_Rect.mRight = xOffset + iWidth;
    267.     if(!m_Desc.mBottom)
    268.     {
    269.      page->m_Rect.mTop = 1;
    270.      page->m_Rect.mBottom = m_Desc.mTabHeight;
    271.     }
    272.     else
    273.     {
    274.      page->m_Rect.mTop = cRect.bottom - m_Desc.mTabHeight;
    275.      page->m_Rect.mBottom = cRect.bottom - 1;
    276.     }
    277.    }
    278.    else
    279.    {  
    280.     page->m_Rect.mLeft = xOffset - 1;
    281.     page->m_Rect.mRight = xOffset + iWidth + 1;
    282.     if(!m_Desc.mBottom)
    283.     {
    284.      page->m_Rect.mTop = 0;
    285.      page->m_Rect.mBottom = m_Desc.mTabHeight;
    286.     }
    287.     else
    288.     {
    289.      page->m_Rect.mTop = cRect.bottom - m_Desc.mTabHeight;
    290.      page->m_Rect.mBottom = cRect.bottom;
    291.     }
    292.    }
    293.    xOffset += iWidth;
    294.   }
    295.   ::SelectObject(dc, iFont);
    296.   ::ReleaseDC(m_Handle, dc);
    297. }
    298. }
    299. void FlatTab::DrawTopTab(HDC dc, RECT rect)
    300. { //细节多得令人发指,累得满月眼冒金星
    301. int width = GetWidth();
    302. int height = GetHeight();
    303. RECT lRect;
    304. lRect.left = 0;
    305. lRect.right = 1;
    306. lRect.top = m_Desc.mTabHeight;
    307. lRect.bottom = height;
    308. ::FillRect(dc, &lRect, HBRUSH(COLOR_3DHIGHLIGHT+1)); //left line
    309. lRect.left = width-1;
    310. lRect.right = width;
    311. ::FillRect(dc, &lRect, HBRUSH(COLOR_3DSHADOW+1));  //right line
    312. lRect.left = 0;
    313. lRect.right = width;
    314. lRect.top = height-1;
    315. lRect.bottom = height;
    316. ::FillRect(dc, &lRect, HBRUSH(COLOR_3DSHADOW+1));  //bottom line

    317. int iMode = ::SetBkMode(dc, TRANSPARENT);
    318. HGDIOBJ iFont = ::SelectObject(dc, m_Parent->GetFont());   
    319. int iSpace = m_Desc.mSpace; //图标与文本之间的间隔距离
    320. for(uint i = 0; i < m_PageList.size(); i++)
    321. {
    322.   FlatPage* page = GetPage(i);
    323.   Rect pRect = page->GetRect();
    324.   WinImageList* imageList = GetImageList();
    325.   if(page != GetSelectedPage())
    326.   {
    327.    RECT iRect = *(RECT*)&pRect;
    328.    if(!TestRect(iRect, rect) && OnDrawPage(dc, pRect, page))
    329.    {
    330.     iRect.left = pRect.mLeft;
    331.     iRect.right = pRect.mLeft + 1;
    332.     iRect.top = pRect.mTop;
    333.     iRect.bottom = pRect.mBottom;
    334.     ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's left line
    335.     iRect.left = pRect.mRight - 1;
    336.     iRect.right = pRect.mRight;  
    337.     ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's right line
    338.     iRect.left = pRect.mLeft + 1;
    339.     iRect.right = pRect.mRight - 1;
    340.     iRect.top = pRect.mTop;
    341.     iRect.bottom = pRect.mTop + 1;  
    342.     ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's bottom line
    343.         
    344.     int image = imageList ? page->GetImage() : -1;
    345.     if(image >= 0)
    346.     {
    347.      int iLeft = pRect.mLeft + 1 + m_Desc.mMargin;
    348.      int iTop = (pRect.mTop+1) + (pRect.mBottom-pRect.mTop-2-imageList->GetImageHeight())/2;
    349.      ::ImageList_DrawEx(imageList->GetHandle(), image, dc, iLeft, iTop,
    350.       imageList->GetImageWidth(), imageList->GetImageHeight(), CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
    351.     }
    352.     cstr iText = page->GetText();
    353.     int iLen = strlen(iText);
    354.     if(iLen > 0)
    355.     {
    356.      COLORREF iColor = ::SetTextColor(dc, page->GetTextColor());
    357.      iRect.left = pRect.mLeft + 1 + m_Desc.mMargin;
    358.      if(imageList)
    359.       iRect.left += imageList->GetImageWidth() + iSpace;
    360.      iRect.right = pRect.mRight - 1;
    361.      iRect.top = pRect.mTop + 1;
    362.      iRect.bottom = pRect.mBottom - 1;
    363.      ::DrawText(dc, iText, iLen, &iRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    364.      ::SetTextColor(dc, iColor);
    365.     }
    366.    }
    367.   }
    368. }
    369.         
    370. FlatPage* sPage = GetSelectedPage();
    371. Rect spRect = sPage->GetRect();
    372. RECT sRect = *(RECT*)&spRect;
    373. if(!TestRect(rect, sRect) && OnDrawPage(dc, spRect, sPage))
    374. {
    375.   sRect.left = spRect.mLeft;
    376.   sRect.right = spRect.mLeft + 1;
    377.   sRect.top = spRect.mTop;
    378.   sRect.bottom = spRect.mBottom;
    379.   ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's left line
    380.   sRect.left = spRect.mRight - 1;
    381.   sRect.right = spRect.mRight;
    382.   ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's right line
    383.   sRect.left = spRect.mLeft + 1;
    384.   sRect.right = spRect.mRight - 1;
    385.   sRect.bottom = spRect.mTop + 1;  
    386.   ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's top line
    387.   WinImageList* imageList = GetImageList();
    388.   int image = imageList ? sPage->GetImage() : -1;
    389.   if(image >= 0)
    390.   {
    391.    int iLeft = spRect.mLeft + /*expand*/1 + /*line*/1 + m_Desc.mMargin - /*offset*/1;
    392.    int iTop = (spRect.mTop + /*expand*/1 + /*line*/1) + (spRect.mBottom-spRect.mTop-3-imageList->GetImageHeight())/2 - /*offset*/1;
    393.    ::ImageList_DrawEx(imageList->GetHandle(), image, dc, iLeft, iTop,
    394.     imageList->GetImageWidth(), imageList->GetImageHeight(), CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
    395.   }
    396.   cstr iText = sPage->GetText();
    397.   int iLen = strlen(iText);
    398.   if(iLen > 0)
    399.   {
    400.    COLORREF iColor = ::SetTextColor(dc, sPage->GetTextColor());
    401.    sRect.left = spRect.mLeft + /*expand*/1 + /*line*/1 + m_Desc.mMargin;
    402.    if(imageList)
    403.     sRect.left += imageList->GetImageWidth() + iSpace;
    404.    sRect.right = spRect.mRight - /*expand*/1 - /*line*/1;
    405.    sRect.top = spRect.mTop + /*expand*/1 + /*line*/1;
    406.    sRect.bottom = spRect.mBottom - /*line*/1;
    407.    ::OffsetRect(&sRect, -1, -1);
    408.    ::DrawText(dc, iText, iLen, &sRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    409.    ::SetTextColor(dc, iColor);
    410.   }
    411. }
    412. RECT bRect;
    413. bRect.top = spRect.mBottom;
    414. bRect.bottom = spRect.mBottom + 1;
    415. bRect.left = 0;
    416. bRect.right = spRect.mLeft+1;
    417. ::FillRect(dc, &bRect, HBRUSH(1+COLOR_3DHIGHLIGHT));
    418. bRect.left = spRect.mRight;
    419. bRect.right = rect.right;
    420. if(bRect.right == width)
    421.   bRect.right--;
    422. ::FillRect(dc, &bRect, HBRUSH(1+COLOR_3DHIGHLIGHT));
    423. ::SelectObject(dc,iFont);
    424. ::SetBkMode(dc, iMode);
    425. }
    426. void FlatTab::DrawBottomTab(HDC dc, RECT rect)
    427. {
    428. int width = GetWidth();
    429. int height = GetHeight();
    430. RECT lRect; //line's rect
    431. lRect.left = 0;
    432. lRect.right = 1;
    433. lRect.top = 0;
    434. lRect.bottom = height - m_Desc.mTabHeight;
    435. ::FillRect(dc, &lRect, HBRUSH(COLOR_3DHIGHLIGHT+1)); //left line
    436. lRect.left = width-1;
    437. lRect.right = width;
    438. ::FillRect(dc, &lRect, HBRUSH(COLOR_3DSHADOW+1));  //right line
    439. lRect.left = 1;
    440. lRect.right = width-1;
    441. lRect.bottom = lRect.top + 1;
    442. ::FillRect(dc, &lRect, HBRUSH(COLOR_3DHIGHLIGHT+1));  //top line
    443.    
    444. int iMode = ::SetBkMode(dc, TRANSPARENT);
    445. HGDIOBJ iFont = ::SelectObject(dc, m_Parent->GetFont());   
    446. int iSpace = m_Desc.mSpace;  //图标与文本之间的间隔距离
    447. for(uint i = 0; i < m_PageList.size(); i++)
    448. {
    449.   FlatPage* page = GetPage(i);
    450.   Rect pRect = page->GetRect();
    451.   if(page != GetSelectedPage())
    452.   {         
    453.    RECT iRect = *(RECT*)&pRect;
    454.    if(!TestRect(iRect, rect) && OnDrawPage(dc, pRect, page))
    455.    {
    456.     iRect.left = pRect.mLeft;
    457.     iRect.right = pRect.mLeft + 1;
    458.     iRect.top = pRect.mTop;
    459.     iRect.bottom = pRect.mBottom-1;
    460.     ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's left line
    461.     iRect.left = pRect.mRight - 1;
    462.     iRect.right = pRect.mRight;  
    463.     ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's right line
    464.     iRect.left = pRect.mLeft;
    465.     iRect.right = pRect.mRight;
    466.     iRect.top = pRect.mBottom - 1;
    467.     iRect.bottom = pRect.mBottom;  
    468.     ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's bottom line
    469.     WinImageList* imageList = GetImageList();
    470.     int image = imageList ? page->GetImage() : -1;
    471.     if(image >= 0)
    472.     {
    473.      int iLeft = pRect.mLeft + 1 + m_Desc.mMargin;
    474.      int iTop = (pRect.mTop+1) + (pRect.mBottom-pRect.mTop-2-imageList->GetImageHeight())/2;
    475.      ::ImageList_DrawEx(imageList->GetHandle(), image, dc, iLeft, iTop,
    476.       imageList->GetImageWidth(), imageList->GetImageHeight(), CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
    477.     }
    478.     cstr iText = page->GetText();
    479.     int iLen = strlen(iText);
    480.     if(iLen > 0)
    481.     {
    482.      COLORREF iColor = ::SetTextColor(dc, page->GetTextColor());
    483.      iRect.left = pRect.mLeft + 1 + m_Desc.mMargin;
    484.      if(imageList)
    485.       iRect.left += imageList->GetImageWidth() + iSpace;
    486.      iRect.right = pRect.mRight-1;
    487.      iRect.top = pRect.mTop + 1;
    488.      iRect.bottom = pRect.mBottom - 1;
    489.      ::DrawText(dc, iText, iLen, &iRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    490.      ::SetTextColor(dc, iColor);
    491.     }
    492.    }
    493.   }
    494. }
    495. FlatPage* sPage = GetSelectedPage();
    496. Rect spRect = sPage->GetRect();
    497. RECT sRect = *(RECT*)&spRect;//selected label's rect
    498. if(!TestRect(rect, sRect) && OnDrawPage(dc, spRect, sPage))
    499. {
    500.   sRect.left = spRect.mLeft;
    501.   sRect.right = spRect.mLeft + 1;
    502.   sRect.top = spRect.mTop;
    503.   sRect.bottom = spRect.mBottom - 1;
    504.   ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's left line
    505.   sRect.left = spRect.mRight - 1;
    506.   sRect.right = spRect.mRight;  
    507.   ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DSHADOW));  //Label's right line
    508.   sRect.left = spRect.mLeft;
    509.   sRect.right = spRect.mRight;
    510.   sRect.top = spRect.mBottom-1;
    511.   sRect.bottom = spRect.mBottom;
    512.   ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DSHADOW));  //Label's bottom line
    513.             
    514.   FlatPage* page = GetSelectedPage();
    515.   WinImageList* imageList = GetImageList();
    516.   int image = imageList ? page->GetImage() : -1;
    517.   if(image >= 0)
    518.   {
    519.    int iLeft = spRect.mLeft + /*expand*/1 + /*line*/1 + m_Desc.mMargin + /*Select offset*/1;
    520.    int iTop = (spRect.mTop+1) + (spRect.mBottom-/*expand*/1-spRect.mTop-2-imageList->GetImageHeight())/2 + /*Select offset*/1;
    521.    ::ImageList_DrawEx(imageList->GetHandle(), image, dc, iLeft, iTop,
    522.     imageList->GetImageWidth(), imageList->GetImageHeight(), CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
    523.   }
    524.   cstr iText = page->GetText();
    525.   int iLen = strlen(iText);
    526.   if(iLen > 0)
    527.   {
    528.    COLORREF iColor = ::SetTextColor(dc, (COLORREF)(page->GetTextColor()));
    529.    sRect.left = spRect.mLeft + /*expand*/1 + /*line*/1 + m_Desc.mMargin;   
    530.    if(imageList)
    531.     sRect.left += imageList->GetImageWidth() + iSpace;
    532.    sRect.right = spRect.mRight - /*expand*/1 - /*line*/1;
    533.    sRect.top = (spRect.mTop + /*line*/1);
    534.    sRect.bottom = spRect.mBottom - /*expand*/1 - /*line*/1;
    535.    ::OffsetRect(&sRect, 1, 1);
    536.    ::DrawText(dc, iText, iLen, &sRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    537.    ::SetTextColor(dc, iColor);
    538.   }
    539. }
    540. RECT bRect;
    541. bRect.top = spRect.mTop - 1;
    542. bRect.bottom = spRect.mTop;
    543. bRect.left = 0;
    544. bRect.right = spRect.mLeft;
    545. ::FillRect(dc, &bRect, HBRUSH(1+COLOR_3DSHADOW));
    546. bRect.left = spRect.mRight-1;
    547. bRect.right = rect.right;   
    548. ::FillRect(dc, &bRect, HBRUSH(1+COLOR_3DSHADOW));
    549. ::SelectObject(dc,iFont);
    550. ::SetBkMode(dc, iMode);
    551. }
    552. void FlatTab::FlatTabPaint(HDC dc, RECT rect)
    553. {
    554. if(GetPageCount() > 0)
    555. {
    556.   if(!m_Desc.mBottom)//Tab标签在顶部的情形
    557.    DrawTopTab(dc, rect);
    558.   else
    559.    DrawBottomTab(dc, rect);
    560. }
    561. else
    562. {
    563.   RECT cRect;
    564.   ::GetClientRect(m_Handle, &cRect);
    565.   RECT lRect;
    566.   lRect.left = 0;
    567.   lRect.right = 1;
    568.   lRect.top = 0;
    569.   lRect.bottom = cRect.bottom - 1;
    570.   ::FillRect(dc, &lRect, HBRUSH(1+COLOR_3DHIGHLIGHT));  //LEFT
    571.   lRect.right = cRect.right - 1;
    572.   lRect.bottom = 1;
    573.   ::FillRect(dc, &lRect, HBRUSH(1+COLOR_3DHIGHLIGHT));  //TOP
    574.   lRect.left = cRect.right - 1;
    575.   lRect.right = cRect.right;
    576.   lRect.bottom = cRect.bottom;
    577.   ::FillRect(dc, &lRect, HBRUSH(1+COLOR_3DSHADOW));   //RIGHT
    578.   lRect.left = 0;
    579.   lRect.top = cRect.bottom - 1;
    580.   ::FillRect(dc, &lRect, HBRUSH(1+COLOR_3DSHADOW));   //BOTTOM
    581. }
    582. #ifdef __Design__
    583. if(mBoxList.size() > 0)
    584. {
    585.   Rect bRect;
    586.   ::GetClipBox(dc, (RECT*)&bRect);
    587.   for(uint i = 0; i < mBoxList.size(); i++)
    588.   {
    589.    if(bRect.IntersectRect(Rect(mBoxList)))
    590.     mBoxList.DrawBox(dc, HBRUSH(COLOR_HIGHLIGHT+1));
    591.   }
    592. }
    593. #endif
    594. }
    595. FlatPage* FlatTab::AddPage()
    596. {
    597. if(m_Handle)
    598. {
    599.   FlatPage* page = new FlatPage;
    600.   page->m_Index = GetPageCount();
    601.   page->m_Owner = this;
    602.   m_PageList.push_back(page);
    603.   UpdateLabelRect(page->m_Index);
    604.   FlatPage* iPage = GetSelectedPage();
    605.   if(!iPage)
    606.   {
    607.    m_SelectedPage = page;
    608.    if(mOnSelectChanged != NULL)
    609.    { //触发当前选择页改变事件
    610.     if(!mOnSelectChanged.mThis)
    611.      (GetParent()->*mOnSelectChanged)(this, iPage, page);
    612.     else
    613.      mOnSelectChanged(this, iPage, page);
    614.    }
    615.   }
    616.   if(IsVisible())
    617.    ::InvalidateRect(m_Handle, (const RECT*)&page->m_Rect, FALSE);
    618.   return page;
    619. }
    620. return NULL;
    621. }
    622. void FlatTab::DeletePage(FlatPage* page)
    623. {
    624. if(!page)
    625.   return;
    626. for(int i = 0; i < GetPageCount(); i++)
    627. {
    628.   if(page == m_PageList)
    629.   {
    630.    DeletePage(i);
    631.    return;
    632.   }
    633. }
    634. }
    635. void FlatTab::DeletePage(int index)
    636. {
    637. if(0 <= index && index < GetPageCount())
    638. {   
    639.   FlatPage* dPage = m_PageList[index];
    640.   m_PageList.erase(m_PageList.begin()+index);
    641.   for(int i = index; i < GetPageCount(); i++)
    642.    m_PageList->m_Index = i;
    643.   UpdateLabelRect(index);
    644.   if(m_SelectedPage == dPage)
    645.   { //删除选择页
    646.    if(m_PageList.size() == 0)
    647.     m_SelectedPage = NULL;
    648.    else
    649.    {
    650.     m_SelectedPage = m_PageList[0];
    651.     m_SelectedPage->ShowAllControl();
    652.     if(mOnSelectChanged != NULL)
    653.     {
    654.      if(!mOnSelectChanged.mThis)
    655.       (GetParent()->*mOnSelectChanged)(this, dPage, m_SelectedPage);
    656.      else
    657.       mOnSelectChanged(this, dPage, m_SelectedPage);
    658.     }
    659.    }
    660.   }
    661.   delete dPage;
    662.   if(IsVisible())
    663.    ::InvalidateRect(m_Handle, NULL, TRUE);
    664. }
    665. }
    666. void FlatTab::DeleteAllPage()
    667. {
    668. if(m_PageList.size() == 0)
    669.   return;
    670. SetRedraw(false);
    671. while(GetPageCount() > 0)
    672. {
    673.   delete m_PageList.back();
    674.   m_PageList.pop_back();
    675. }   
    676. m_SelectedPage = NULL;
    677. SetRedraw(true);
    678. RedrawControl(false);
    679. }
    680. sint FlatTab::GetPageCount()
    681. {
    682. return sint(m_PageList.size());
    683. }
    684. void FlatTab::SetImageList(WinImageList* imageList)
    685. {
    686. if(imageList && imageList->GetHandle() == NULL)
    687. {         
    688. #ifdef _DEBUG
    689.   ::DebugBreak();   
    690. #endif
    691.   return;
    692. }
    693. if(m_Handle)
    694. {
    695.   m_ImageList = imageList;
    696.   if(GetPageCount() > 0 && IsVisible())
    697.    ::InvalidateRect(m_Handle, NULL, TRUE);
    698. }
    699. }
    700. WinImageList* FlatTab::GetImageList()
    701. {
    702. return m_ImageList;
    703. }
    704. void FlatTab::SelectPage(FlatPage* page)
    705. {
    706. if(!page || page == m_SelectedPage)
    707.   return;
    708. bool find = false;
    709. for(int i = 0; i < int(m_PageList.size()); i++)
    710. {
    711.   if(page == m_PageList)
    712.   {
    713.    find = true;
    714.    break;
    715.   }
    716. }
    717. if(find)
    718. {
    719.   bool may = true;
    720.   if(mOnSelectChanging != NULL)
    721.   {
    722.    if(!mOnSelectChanging.mThis)
    723.     may = (GetParent()->*mOnSelectChanging)(this, m_SelectedPage);
    724.    else
    725.     may = mOnSelectChanging(this, m_SelectedPage);
    726.   }
    727.   if(may)
    728.   {
    729.    Rect iRect, nRect;
    730.    FlatPage* iPage = m_SelectedPage;
    731.    iRect = iPage->GetRect();
    732.    m_SelectedPage = page;  
    733.    iPage->HideAllControl();
    734.    page->ShowAllControl();
    735.    int iIndex = iPage->m_Index;
    736.    int nIndex = page->m_Index;
    737.    UpdateLabelRect(iIndex<nIndex ? iIndex : nIndex);
    738.    nRect = page->GetRect();
    739.    if(mOnSelectChanged != NULL)
    740.    {
    741.     if(!mOnSelectChanged.mThis)
    742.      (GetParent()->*mOnSelectChanged)(this, iPage, page);
    743.     else
    744.      mOnSelectChanged(this, iPage, page);
    745.    }
    746.    if(IsVisible())
    747.    {
    748.     if(!m_Desc.mBottom)
    749.     {
    750.      iRect.mBottom++;
    751.      nRect.mBottom++;
    752.     }
    753.     else
    754.     {
    755.      iRect.mTop--;
    756.      nRect.mTop--;
    757.     }
    758.     ::InvalidateRect(m_Handle, (RECT*)&iRect, TRUE);
    759.     ::InvalidateRect(m_Handle, (RECT*)&nRect, TRUE);
    760.    }
    761.   }
    762. }
    763. #ifdef _DEBUG
    764. else
    765.   ::DebugBreak();//page不属于此控件!
    766. #endif
    767. }
    768. FlatPage* FlatTab::GetSelectedPage()
    769. {
    770. return m_SelectedPage;
    771. }
    772. FlatPage* FlatTab::GetPage(int index)
    773. {
    774. if(0 <= index && index < GetPageCount())
    775.   return m_PageList[index];
    776. return NULL;
    777. }
    778. LRESULT FlatTab::WmEraseBkGnd(WPARAM wParam, LPARAM lParam)
    779. {
    780. HDC dc = (HDC)wParam;
    781. if(mOnDrawSkin != NULL)
    782. {
    783.   bool bCode;
    784.   FlatTabSkinData data;
    785.   data.mDC = dc;
    786.   data.mClientRect = this->GetClientRect();
    787.   if(!mOnDrawSkin.mThis)
    788.    bCode = (GetParent()->*mOnDrawSkin)(this, data);
    789.   else
    790.    bCode = mOnDrawSkin(this, data);
    791.   if(!bCode)
    792.    return TRUE;
    793. }
    794.   
    795. DrawSkin((HDC)wParam, NULL);
    796. return TRUE;
    797. }
    798. LRESULT FlatTab::WmPaint(WPARAM wParam, LPARAM lParam)
    799. {   
    800. if(m_Desc.mDoubleBuffer)
    801. {
    802.   if(DoubleBufferPaint(wParam, lParam))
    803.   {   
    804.    RECT uRect;
    805.    HDC dc = (HDC)wParam;
    806.    ::GetClipBox(dc, &uRect);
    807.    FlatTabPaint((HDC)wParam, uRect);
    808.   }
    809. }
    810. else
    811. {
    812.   if(wParam == 0)
    813.   {
    814.    PAINTSTRUCT ps;
    815.    HDC dc = ::BeginPaint(m_Handle, &ps);
    816.    FlatTabPaint(dc, ps.rcPaint);
    817.    ::EndPaint(m_Handle, &ps);
    818.   }
    819.   else
    820.   {
    821.    RECT uRect;
    822.    HDC dc = (HDC)wParam;
    823.    ::GetClipBox(dc, &uRect);
    824.    FlatTabPaint((HDC)wParam, uRect);
    825.   }
    826. }
    827. return 0;
    828. }
    829. LRESULT FlatTab::WmMove(WPARAM wParam, LPARAM lParam)
    830. {   
    831. if(!m_MoveSize)
    832. { //系统可能会自动调整控件位置
    833.   RECT wRect;
    834.   ::GetWindowRect(m_Handle, &wRect);
    835.   ::ScreenToClient(m_Parent->GetHandle(), (POINT*)&wRect);
    836.   m_Left = wRect.left;
    837.   m_Top = wRect.top;
    838. }
    839. OnContainerMove(m_Left, m_Top);
    840. if(mOnDrawSkin != NULL)
    841.   RedrawControl(true);
    842. else if(m_ParentSkin)
    843. {
    844.   SkinMode pMode = GetSkinMode();
    845.   if(pMode == SkinMode_BitmapResource || pMode == SkinMode_BitmapFile || GetBrush() == NULL)
    846.    RedrawControl(true);
    847. }
    848. return 0;
    849. }
    850. LRESULT FlatTab::WmSize(WPARAM wParam, LPARAM lParam)
    851. {
    852. if(!m_MoveSize)
    853. { //系统可能会自动调整控件尺寸
    854.   RECT wRect;
    855.   ::GetWindowRect(m_Handle, &wRect);   
    856.   m_OldWidth = m_Width;
    857.   m_OldHeight = m_Height;
    858.   m_Width = wRect.right - wRect.left;
    859.   m_Height = wRect.bottom - wRect.top;
    860. }
    861. if(m_Width != m_OldHeight || m_Height != m_OldHeight)
    862. {
    863.   if(m_Desc.mBottom && GetPageCount() > 0 && m_Height != m_OldHeight)
    864.    UpdateLabelRect(0);
    865.   OnContainerSize(m_Width, m_Height);
    866.   if(IsVisible())
    867.   {
    868.    if(mOnDrawSkin != NULL)
    869.     RedrawControl(true);
    870.    else
    871.    {
    872.     int left = m_Width;
    873.     if(m_Width != m_OldWidth)
    874.     { //控件自身需要刷新   
    875.      RECT wRect;
    876.      if(m_Width > m_OldWidth)
    877.      {
    878.       wRect.left = m_OldWidth - 1;   
    879.       wRect.right = m_Width;
    880.      }
    881.      else
    882.      {
    883.       wRect.left = m_Width - 1;
    884.       wRect.right = m_Width;
    885.      }
    886.      wRect.top = 0;
    887.      wRect.bottom = m_Height;
    888.      ::InvalidateRect(m_Handle, &wRect, TRUE);
    889.      ::UpdateWindow(m_Handle);
    890.      left = wRect.left;
    891.     }
    892.     if(m_Height != m_OldHeight)
    893.     {  
    894.      RECT hRect;
    895.      if(m_Height > m_OldHeight)
    896.      {        
    897.       if(!m_Desc.mBottom)
    898.        hRect.top = m_OldHeight - 1;
    899.       else
    900.        hRect.top = m_OldHeight - m_Desc.mTabHeight - 1;
    901.       hRect.bottom = m_Height;
    902.      }
    903.      else
    904.      {
    905.       if(!m_Desc.mBottom)
    906.        hRect.top = m_Height - 1;
    907.       else
    908.        hRect.top = m_Height - m_Desc.mTabHeight - 1;
    909.       hRect.bottom = m_Height;
    910.      }
    911.      hRect.left = 0;
    912.      hRect.right = left;
    913.      ::InvalidateRect(m_Handle, &hRect, TRUE);
    914.      ::UpdateWindow(m_Handle);
    915.     }
    916.    }
    917.   }
    918. }
    919. return 0;
    920. }
    921. LRESULT FlatTab::WmLButtonDown(WPARAM wParam, LPARAM lParam)
    922. {  
    923. int xPos = (int)(short)(LOWORD(lParam));
    924. int yPos = (int)(short)(HIWORD(lParam));
    925. for(int i = 0; i < GetPageCount(); i++)
    926. {
    927.   FlatPage* page = GetPage(i);
    928.   Rect iRect = page->GetRect();
    929.   if(iRect.InsideRect(xPos, yPos))
    930.   {
    931.    SelectPage(page);
    932.    break;
    933.   }
    934. }
    935. return 0;
    936. }  
    937. LRESULT FlatTab::WmThemeChanged(WPARAM wParam, LPARAM lParam)
    938. {
    939. CallDefaultProc(WM_THEMECHANGED, wParam, lParam);
    940. FreeCL::InitTheme();
    941. ::SendMessage(m_Handle, WM_SETFONT, WPARAM(m_Parent->GetFont()), (LPARAM)TRUE);
    942. return 0;
    943. }
    944. bool FlatTab::OnDrawPage(HDC dc, const Rect& rect, FlatPage* page)
    945. {
    946. if(mOnDrawPage != NULL)
    947. {
    948.   FlatPageDrawData data;
    949.   data.mDC = dc;
    950.   data.mRect = rect;
    951.   if(!mOnDrawPage.mThis)
    952.    return (GetParent()->*mOnDrawPage)(this, page, data);
    953.   else
    954.    return mOnDrawPage(this, page, data);
    955. }
    956. return true;
    957. }
    958. }

    复制代码






    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?加入我们

    x
    PYG19周年生日快乐!
  • TA的每日心情
    奋斗
    前天 07:35
  • 签到天数: 2313 天

    [LV.Master]伴坛终老

    发表于 2012-4-4 20:44:58 | 显示全部楼层
    爱民兄好给力,下载收藏个
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2024-7-17 08:58
  • 签到天数: 178 天

    [LV.7]常住居民III

    发表于 2012-4-5 10:24:57 | 显示全部楼层
    暂时还看不懂。。
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-5-27 19:51:03 | 显示全部楼层
    暂时我也还看不懂。。
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-6-13 11:09:22 | 显示全部楼层
    还看不大懂,老点注社最好
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-6-24 00:49:22 | 显示全部楼层
    这是好东西,必须留下
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-8-8 00:23:27 | 显示全部楼层
    不会用,能有视频教程就好了
    PYG19周年生日快乐!
  • TA的每日心情
    无聊
    2024-11-30 23:12
  • 签到天数: 90 天

    [LV.6]常住居民II

    发表于 2014-11-4 21:28:40 | 显示全部楼层
    怎么没有图啊??
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表