SkinTab.cpp 7.0 KB

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