SkinTab.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /************************************************************************
  2. * 程序名: 精仿QQ主界面
  3. * 制作人: 李克平, 2011年04月11日
  4. * 版本号: 1.0
  5. ************************************************************************/
  6. // BmpTab.cpp : implementation file
  7. #include "stdafx.h"
  8. #include "QQ.h"
  9. #include "SkinTab.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CSkinTab
  17. CSkinTab::CSkinTab()
  18. {
  19. m_bIsCDC=FALSE;
  20. m_dwState=HTNORMAL;
  21. m_hIconHand=AfxGetApp()->LoadCursor(IDC_CURSOR_HAND);
  22. m_iCurrentSelect=1;
  23. m_iCurrentFouce=-1;
  24. }
  25. CSkinTab::~CSkinTab()
  26. {
  27. }
  28. BEGIN_MESSAGE_MAP(CSkinTab, CStatic)
  29. //{{AFX_MSG_MAP(CSkinTab)
  30. ON_WM_PAINT()
  31. ON_WM_LBUTTONDOWN()
  32. ON_WM_ERASEBKGND()
  33. ON_WM_MOUSEMOVE()
  34. ON_WM_TIMER()
  35. ON_WM_SETCURSOR()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CSkinTab message handlers
  40. void CSkinTab::PreSubclassWindow()
  41. {
  42. // TODO: Add your specialized code here and/or call the base class
  43. ModifyStyle(0,SS_NOTIFY);
  44. CStatic::PreSubclassWindow();
  45. }
  46. void CSkinTab::OnPaint()
  47. {
  48. CPaintDC dc(this);
  49. CRect rc;GetClientRect(&rc);
  50. CDC memDC;memDC.CreateCompatibleDC(&dc);
  51. CBitmap bmpBack;bmpBack.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
  52. CBitmap *bmpOld=memDC.SelectObject(&bmpBack);
  53. memDC.BitBlt(0,0,rc.Width(),rc.Height(),&m_memDC,0,0,SRCCOPY);
  54. if(m_bmpBG.m_hObject != NULL)
  55. m_bmpBG.ExtendDraw(&memDC,rc,10,50);
  56. CRect rcItem;
  57. TABITEM* tabItem;
  58. for(int i=0;i<m_aryItem.GetSize();i++)
  59. {
  60. CDC tmpDC;tmpDC.CreateCompatibleDC(&dc);
  61. tabItem=(TABITEM*)m_aryItem.GetAt(i);
  62. // if(tabItem->pVoid)
  63. // ((CWnd*)(tabItem->pVoid))->ShowWindow(SW_HIDE);
  64. GetTabItemRect(i,&rcItem);
  65. bmpOld=tmpDC.SelectObject(&m_bmpNormal);
  66. if(m_iCurrentFouce==i)
  67. {
  68. bmpOld=tmpDC.SelectObject(&m_bmpHover);
  69. }
  70. if(m_iCurrentSelect==i)
  71. {
  72. bmpOld=tmpDC.SelectObject(&m_bmpHdown);
  73. // if(tabItem->pVoid)
  74. // ((CWnd*)(tabItem->pVoid))->ShowWindow(SW_NORMAL);
  75. }
  76. memDC.BitBlt(rcItem.left+1,rcItem.top,rcItem.Width(),rcItem.Height(),&tmpDC,0,0,SRCCOPY);
  77. tmpDC.SelectObject(bmpOld);
  78. ReleaseDC(&tmpDC);
  79. tmpDC.DeleteDC();
  80. ::DrawIconEx(memDC,rcItem.left+8,rcItem.top+3,tabItem->icon,24,24,0,NULL,DI_NORMAL);
  81. }
  82. dc.BitBlt(0,0,rc.Width(),rc.Height(),&memDC,0,0,SRCCOPY);
  83. memDC.DeleteDC();
  84. // CStatic::OnPaint();
  85. }
  86. void CSkinTab::OnLButtonDown(UINT nFlags, CPoint point)
  87. {
  88. // TODO: Add your message handler code here and/or call default
  89. // AfxMessageBox("dd");
  90. //m_dwState=HTHDOWN;
  91. CRect rcItem;
  92. for(int i=0;i<m_aryItem.GetSize();i++)
  93. {
  94. CWnd *tabItemView;
  95. tabItemView=(CWnd*)((TABITEM*)m_aryItem.GetAt(i))->pVoid;
  96. CRect recTab(0,0,Width(),Heighth());
  97. if(tabItemView && recTab.PtInRect(point))
  98. tabItemView->ShowWindow(SW_HIDE);
  99. GetTabItemRect(i,&rcItem);
  100. if(rcItem.PtInRect(point))
  101. {
  102. m_iCurrentSelect=i;
  103. if((m_aryItem.GetAt(i))!=NULL)
  104. {
  105. if(tabItemView)
  106. tabItemView->ShowWindow(SW_NORMAL);
  107. }
  108. }
  109. }
  110. Invalidate();
  111. CStatic::OnLButtonDown(nFlags, point);
  112. }
  113. BOOL CSkinTab::OnEraseBkgnd(CDC* pDC)
  114. {
  115. // TODO: Add your message handler code here and/or call default
  116. if(!m_bIsCDC)
  117. {
  118. m_memDC.CreateCompatibleDC(pDC);
  119. CRect rc;GetClientRect(&rc);
  120. CBitmap bmpBack;bmpBack.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());
  121. m_memDC.SelectObject(&bmpBack);
  122. m_memDC.BitBlt(0,0,rc.Width(),rc.Height(),pDC,0,0,SRCCOPY);
  123. // m_memDC.SelectObject(bmpOld);
  124. // bmpOld->DeleteObject();
  125. m_bIsCDC=TRUE;
  126. bmpBack.DeleteObject();
  127. }
  128. return TRUE;
  129. //return CStatic::OnEraseBkgnd(pDC);
  130. }
  131. void CSkinTab::SetIcon(int nIndex,UINT nIcon,void *pVoid)
  132. {
  133. TABITEM* tabItem=new TABITEM;
  134. tabItem->nIndex=nIndex;
  135. tabItem->icon=AfxGetApp()->LoadIcon(nIcon);
  136. tabItem->pVoid=pVoid;
  137. m_aryItem.Add(tabItem);
  138. }
  139. void CSkinTab::SetIcon(int nIndex,LPCTSTR szIcon,void *pVoid)
  140. {
  141. TABITEM* tabItem=new TABITEM;
  142. tabItem->nIndex=nIndex;
  143. tabItem->icon=(HICON)::LoadImage(AfxGetApp()->m_hInstance,szIcon,IMAGE_ICON,24,24,LR_LOADFROMFILE);
  144. tabItem->pVoid=pVoid;
  145. m_aryItem.Add(tabItem);
  146. }
  147. void CSkinTab::SetBmp(UINT nBmpNormal, UINT nBmpHover, UINT nBmpHdown)
  148. {
  149. m_bmpNormal.LoadBitmap(nBmpNormal);
  150. m_bmpHover.LoadBitmap(nBmpHover);
  151. m_bmpHdown.LoadBitmap(nBmpHdown);
  152. }
  153. void CSkinTab::SetSkin(CString strNormal, CString strHover, CString strDown)
  154. {
  155. m_bmpNormal.LoadImage(strNormal);
  156. m_bmpHover.LoadImage(strHover);
  157. m_bmpHdown.LoadImage(strDown);
  158. }
  159. void CSkinTab::SetSkin(CString strBmpTab)
  160. {
  161. CEnBitmap bmp;
  162. bmp.LoadImage(strBmpTab);
  163. if(bmp.m_hObject != NULL)
  164. {
  165. bmp.DrawImage(m_bmpNormal,1,1,3,1);
  166. bmp.DrawImage(m_bmpHover,2,1,3,1);
  167. bmp.DrawImage(m_bmpHdown,3,1,3,1);
  168. }
  169. if(bmp.m_hObject != NULL) bmp.DeleteObject();
  170. }
  171. void CSkinTab::SetSkinBG(CString strBmpBG)
  172. {
  173. m_bmpBG.LoadImage(strBmpBG);
  174. }
  175. void CSkinTab::AddTabItem(TABITEM &item)
  176. {
  177. //m_aryItem.Add(&item);
  178. }
  179. void CSkinTab::AddTabItem(UINT nBmpNormal, UINT nBmpHover, UINT nBmpHdown, UINT nIcon, void *pVoid)
  180. {
  181. //if(m_aryItem.GetSize()==0)
  182. // CBitmap bmpNormal,bmpHover,bmpHdown;
  183. // HICON icon;
  184. // // bmpNormal.LoadBitmap(nBmpNormal);
  185. // // bmpHover.LoadBitmap(nBmpHover);
  186. // // bmpHdown.LoadBitmap(nBmpHdown);
  187. // icon=AfxGetApp()->LoadIcon(nIcon);
  188. //
  189. // TABITEM* tabitm=new TABITEM;
  190. // // tabitm.rcItem=rc;
  191. // tabitm->bmpNormal.LoadBitmap(nBmpNormal);
  192. // tabitm->bmpHover.LoadBitmap(nBmpHover);
  193. // tabitm->bmpHdown.LoadBitmap(nBmpHdown);
  194. // tabitm->icon=icon;
  195. // tabitm->pVoid=NULL;
  196. //
  197. // m_aryItem.Add((void*)tabitm);
  198. }
  199. void CSkinTab::OnMouseMove(UINT nFlags, CPoint point)
  200. {
  201. // TODO: Add your message handler code here and/or call default
  202. //AfxMessageBox("dd");
  203. // m_dwState=HTHOVER;
  204. // CRect rc;
  205. // BOOL IsTrue=FALSE;
  206. // for(int i=0;i<m_aryItem.GetSize();i++)
  207. // {
  208. // GetTabItemRect(i,&rc);
  209. // if(rc.PtInRect(point))
  210. // {
  211. // m_iCurrentFouce=i;
  212. // IsTrue=TRUE;
  213. // }
  214. // }
  215. // if(!IsTrue)
  216. // m_iCurrentFouce=-1;
  217. CRect rcItem(0,0,Width(),Heighth());
  218. if(rcItem.PtInRect(point))
  219. {
  220. SetTimer(1,10,NULL);
  221. Invalidate();
  222. }
  223. CStatic::OnMouseMove(nFlags, point);
  224. }
  225. void CSkinTab::OnTimer(UINT nIDEvent)
  226. {
  227. // TODO: Add your message handler code here and/or call default
  228. CPoint pt(GetMessagePos());
  229. ScreenToClient(&pt);
  230. CRect rc;
  231. BOOL bIsOK=FALSE;
  232. for (int i=0;i<m_aryItem.GetSize();i++)
  233. {
  234. GetTabItemRect(i,&rc);
  235. if(rc.PtInRect(pt))
  236. {
  237. m_iCurrentFouce=i;
  238. bIsOK=TRUE;
  239. }
  240. }
  241. if (!bIsOK)
  242. {
  243. m_iCurrentFouce=-1;
  244. KillTimer(1);
  245. }
  246. Invalidate();
  247. // if(rc.PtInRect(pt))
  248. // {
  249. // m_dwState=HTHOVER;
  250. // }
  251. // else
  252. // {
  253. // m_dwState=HTNORMAL;
  254. //
  255. //
  256. // }
  257. //
  258. CStatic::OnTimer(nIDEvent);
  259. }
  260. BOOL CSkinTab::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  261. {
  262. // TODO: Add your message handler code here and/or call default
  263. CPoint pt(GetMessagePos());
  264. ScreenToClient(&pt);
  265. CRect rcItem(0,0,Width(),Heighth());
  266. if(rcItem.PtInRect(pt))
  267. {
  268. ::SetCursor(m_hIconHand);
  269. return TRUE;
  270. }
  271. return CStatic::OnSetCursor(pWnd, nHitTest, message);
  272. }
  273. void CSkinTab::GetTabItemRect(int nIndex, CRect *rc)
  274. {
  275. // if(m_bmpNormal.GetSafeHandle())
  276. // {
  277. BITMAP bm;
  278. m_bmpNormal.GetBitmap(&bm);
  279. rc->SetRect(0,nIndex*bm.bmHeight,bm.bmWidth,nIndex*bm.bmHeight+bm.bmHeight);
  280. // }
  281. // else
  282. // {
  283. // rc->SetRect(0,0,0,0);
  284. // }
  285. }