SlideBar.cpp
上传用户:oldpeter23
上传日期:2013-01-09
资源大小:1111k
文件大小:5k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. //NetTalk
  2. /*------------------------------------------------------------------------------*
  3.  =============================
  4.    模块名称: SlideBar.cpp
  5.  =============================
  6.  
  7.  [版权]
  8.  
  9.    2000-2002  115软件工厂  版权所有
  10.                                               
  11. *------------------------------------------------------------------------------*/
  12. #include "Wndx.h"
  13. #include "SlideBar.h"
  14. #include <Windowsx.h>
  15. /*------------------------------------------------------------------------------*/
  16. CSlideBar::CSlideBar()
  17. {
  18. m_hbmpFace1=0;
  19. m_hbmpFace2=0;
  20. m_iPos=0;
  21. }
  22. /*------------------------------------------------------------------------------*/
  23. CSlideBar::~CSlideBar()
  24. {
  25. }
  26. /*------------------------------------------------------------------------------*/
  27. void CSlideBar::SetPos(int iPos)
  28. {
  29. m_iPos=iPos;
  30. InvalidateRect(m_hWnd,0,FALSE);
  31. }
  32. /*------------------------------------------------------------------------------*/
  33. int CSlideBar::GetPos()
  34. {
  35. return m_iPos;
  36. }
  37. /*------------------------------------------------------------------------------*/
  38. void CSlideBar::MakeBmp(HDC hdc)
  39. {
  40. if(m_hbmpFace1)
  41. DeleteObject(m_hbmpFace1);
  42. if(m_hbmpFace2)
  43. DeleteObject(m_hbmpFace2);
  44. HDC hMemDC=CreateCompatibleDC(hdc);
  45. HPEN hp=CreatePen(PS_SOLID,1,0x00808080);
  46. HPEN hop=(HPEN)SelectObject(hMemDC,hp);
  47. CRectX rc;
  48. GetClientRect(m_hWnd,&rc);
  49. m_hbmpFace1=CreateCompatibleBitmap(hdc,rc.Width(),rc.Height());
  50. m_hbmpFace2=CreateCompatibleBitmap(hdc,rc.Width(),rc.Height());
  51. HBITMAP hob=(HBITMAP)SelectObject(hMemDC,m_hbmpFace1);
  52. FillSolidRectX(hMemDC,CRectX(0,0,rc.Width(),rc.Height()),0x00a2a2a2);
  53. for(int i=0;i<rc.Width()/2;i++)
  54. {
  55. MoveToEx(hMemDC,i*2,0,0);
  56. LineTo(hMemDC,i*2,rc.Height());
  57. }
  58. SelectObject(hMemDC,m_hbmpFace2);
  59. FillSolidRectX(hMemDC,CRectX(0,0,rc.Width(),rc.Height()),0x00a2a2a2);
  60. SelectObject(hMemDC,hop);
  61. DeleteObject(hp);
  62. hp=CreatePen(PS_SOLID,1,0x00ffeeee);
  63. SelectObject(hMemDC,hp);
  64. for(i=0;i<rc.Width()/2;i++)
  65. {
  66. MoveToEx(hMemDC,i*2,0,0);
  67. LineTo(hMemDC,i*2,rc.Height());
  68. }
  69. SelectObject(hMemDC,hop);
  70. DeleteObject(hp);
  71. SelectObject(hMemDC,hob);
  72. DeleteDC(hMemDC);
  73. }
  74. /*------------------------------------------------------------------------------*/
  75. BOOL CSlideBar::Create(RECT &rc,HWND hParent, UINT uID)
  76. {
  77. return CWndX::Create(0,0,0,WS_CHILD|WS_VISIBLE,rc,hParent,(HMENU)uID,0);
  78. }
  79. /*------------------------------------------------------------------------------*/
  80. LRESULT CSlideBar::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  81. {
  82. switch(uMsg)
  83. {
  84. case WM_PAINT:
  85. OnPaint();
  86. return TRUE;
  87. case WM_DESTROY:
  88. if(m_hbmpFace1)
  89. DeleteObject(m_hbmpFace1);
  90. if(m_hbmpFace2)
  91. DeleteObject(m_hbmpFace2);
  92. m_hbmpFace1=0;
  93. m_hbmpFace2=0;
  94. break;
  95. case WM_LBUTTONDOWN:
  96. {
  97. POINT point;
  98. point.x=GET_X_LPARAM(lParam); 
  99. point.y=GET_Y_LPARAM(lParam); 
  100. OnLButtonDown(wParam,point);
  101. }
  102. break;
  103. }
  104. return CWndX::WndProc(uMsg,wParam,lParam);
  105. }
  106. /*------------------------------------------------------------------------------*/
  107. void CSlideBar::OnPaint()
  108. {
  109. PAINTSTRUCT ps;
  110. HDC hdc=BeginPaint(m_hWnd,&ps);
  111. if(!m_hbmpFace1)
  112. {
  113. MakeBmp(hdc);
  114. }
  115. CRectX rc;
  116. GetClientRect(m_hWnd,&rc);
  117. HDC hMemDC=CreateCompatibleDC(hdc);
  118.     HBITMAP hob=(HBITMAP)SelectObject(hMemDC,m_hbmpFace2);
  119. int p=rc.Width()*m_iPos/100;
  120. BitBlt(hdc,rc.left,rc.top,p,rc.Height(),hMemDC,0,0,SRCCOPY);
  121. SelectObject(hMemDC,m_hbmpFace1);
  122. BitBlt(hdc,rc.left+p,rc.top,rc.Width()-p,rc.Height(),hMemDC,p,0,SRCCOPY);
  123. SelectObject(hMemDC,hob);
  124. DeleteDC(hMemDC);
  125. EndPaint(m_hWnd,&ps);
  126. }
  127. /*------------------------------------------------------------------------------*/
  128. void CSlideBar::OnLButtonDown(UINT nFlags, POINT &point)
  129. {
  130. SetCapture(m_hWnd);
  131. CRectX rc;
  132. GetClientRect(m_hWnd,&rc);
  133. SetPos(point.x*100/rc.Width());
  134. SendMessage(GetParent(m_hWnd),WM_SLD,m_iPos,(LPARAM)m_hWnd);
  135. MSG msg;
  136. while(GetMessage(&msg, NULL, 0, 0))
  137. {
  138. if (GetCapture()!=m_hWnd)
  139. {
  140. DispatchMessage(&msg);
  141. break;
  142. }
  143. switch (msg.message)
  144. {
  145. case WM_MOUSEMOVE:
  146. if(GET_X_LPARAM(msg.lParam)>rc.right)
  147. SetPos(100);
  148. else
  149. if(GET_X_LPARAM(msg.lParam)<rc.left)
  150. SetPos(0);
  151. else
  152. SetPos(GET_X_LPARAM(msg.lParam)*100/rc.Width());
  153. SendMessage(GetParent(m_hWnd),WM_SLD,m_iPos,(LPARAM)m_hWnd);
  154. break;
  155. case WM_LBUTTONUP:
  156. goto EXITLOOP;
  157. default:
  158. DispatchMessage(&msg);
  159. break;
  160. }
  161. }
  162. EXITLOOP:
  163. ReleaseCapture();
  164. }