ColorSelect.cpp
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:18k
源码类别:

绘图程序

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "ColorSelect.h"
  3. #include "GraphSoftView.h"
  4. #include "MainFrm.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. #define LPARAM_X(lp)                        ((int)(short)LOWORD(lp))
  11. #define LPARAM_Y(lp)                        ((int)(short)HIWORD(lp))
  12. #define WM_SETCOLOR WM_USER+1
  13. #define WM_COLORDLG WM_USER+2
  14. #define IDC_COLORDLG_BUTTON 100
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CColorSelect
  17. CColorSelect::CColorSelect()
  18. {
  19. int cxCursor = ::GetSystemMetrics(SM_CXCURSOR);
  20. int cyCursor = ::GetSystemMetrics(SM_CYCURSOR);
  21. m_hCursorStraw = NULL;
  22. m_CurrentColor = RGB(0,0,0);
  23. m_hPaletteWnd = NULL;
  24. m_bPaletteWndActive = FALSE;
  25. }
  26. CColorSelect::~CColorSelect()
  27. {
  28. ::DestroyCursor(m_hCursorStraw);
  29. }
  30. BEGIN_MESSAGE_MAP(CColorSelect, CButton)
  31. //{{AFX_MSG_MAP(CColorSelect)
  32. ON_WM_LBUTTONDOWN()
  33. ON_WM_LBUTTONUP()
  34. ON_WM_SETCURSOR()
  35. ON_WM_PAINT()
  36. ON_WM_MOUSEMOVE()
  37. ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
  38. ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
  39. ON_WM_LBUTTONDBLCLK()
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CColorSelect message handlers
  44. void CColorSelect::OnLButtonDown(UINT nFlags, CPoint point) 
  45. {
  46. // CButton::OnLButtonDown(nFlags, point);
  47.     if(m_rectSel.PtInRect(point))//如果点中的是右边箭头部分
  48. {
  49.      ::ClientToScreen(this->m_hWnd,&point);
  50.  if(CreatePaletteWindow())
  51.  {
  52. nFlags = (UINT)m_CurrentColor;
  53. ::PostMessage(m_hPaletteWnd,WM_LBUTTONDOWN,nFlags,MAKELPARAM(point.x,point.y));
  54.  }
  55.      HWND hwndParent = GetParent()->m_hWnd;
  56.     if(hwndParent)
  57.  {
  58. POINT p1,p2;
  59. RECT rect;
  60. ::GetWindowRect(m_hWnd,&rect);
  61. p1.x = rect.left;
  62. p1.y = rect.top;
  63. p2.x = rect.right;
  64. p2.y = rect.bottom;
  65. ::ScreenToClient(hwndParent,&p1);
  66. ::ScreenToClient(hwndParent,&p2);
  67. rect.left = p1.x;
  68. rect.top = p1.y;
  69. rect.right = p2.x;
  70. rect.bottom = p2.y;
  71. ::InvalidateRect(hwndParent,&rect,TRUE);
  72.  }
  73. }
  74. else
  75. {
  76.          
  77. //如果点中的是左边部分。。。
  78. CPaintDC dc(this); // device context for painting 
  79. dc.DrawEdge(&m_rectFill,BDR_SUNKENINNER,BF_RECT);
  80. }
  81. }
  82. void CColorSelect::OnLButtonUp(UINT nFlags, CPoint point) 
  83. {
  84.     if(NULL!=m_hPaletteWnd){
  85. if((COLORREF)nFlags != m_CurrentColor){
  86. SetColor((COLORREF)nFlags);
  87. }
  88. DestroyPaletteWindow();
  89.     }
  90. Invalidate();
  91. }
  92. LONG FAR PASCAL CColorSelect::PaletteWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
  93. {
  94. HDC hDC;
  95. PAINTSTRUCT ps;
  96. POINT point;
  97. CRect crtColorRect(5,87,50,103);
  98. static POINT oldPoint;
  99. static BOOL bMouseMoved = FALSE;
  100. static HWND hwndParent;
  101. static HWND hwndColorBtn;
  102. static HFONT hFont = NULL;
  103. static COLORREF crtColor,oldColor;
  104. static int iActiveRect = -1;
  105.     CPen             pen3DDKShadow(PS_SOLID,1,::GetSysColor(COLOR_3DDKSHADOW));
  106. CPen             penW(PS_SOLID,1,RGB(0xff,0xff,0xff));
  107. CPen             penB(PS_SOLID,1,RGB(0,0,0));
  108. CRect               rectColorBtn(135,90,151,106);
  109. static  int        nDrawColorBtnFlag; //1----sunken
  110.                                       //2----raised
  111. switch(nMsg)
  112. {
  113. case WM_CREATE:
  114. {
  115. hwndParent = ((LPCREATESTRUCT)lParam)->hwndParent;
  116. crtColor = ::GetSysColor(COLOR_3DFACE);
  117. LOGFONT logFont;
  118. ZeroMemory((void*)&logFont,sizeof(logFont));
  119. strcpy(logFont.lfFaceName,"宋体");
  120. logFont.lfHeight = -12;
  121. logFont.lfWeight = 400;
  122. logFont.lfCharSet = GB2312_CHARSET;
  123. logFont.lfOutPrecision = 3;
  124. logFont.lfClipPrecision = 2; 
  125. logFont.lfQuality = 1;
  126. logFont.lfPitchAndFamily = 2;
  127. hFont = ::CreateFontIndirect(&logFont);
  128. ////色彩对话框按钮
  129. hwndColorBtn = ::CreateWindow("BUTTON","",WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,rectColorBtn.left ,rectColorBtn.top,rectColorBtn.Width(),rectColorBtn.Height(),hWnd,HMENU(IDC_COLORDLG_BUTTON),::AfxGetInstanceHandle(),NULL);
  130. if(hwndColorBtn)
  131. ::ShowWindow(hwndColorBtn,SW_SHOW);
  132. nDrawColorBtnFlag=1;
  133. }
  134. break;
  135. case WM_DESTROY:
  136. ::DeleteObject(hFont);
  137. break;
  138. case WM_DRAWITEM:
  139. {
  140. LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam;
  141. if(lpDis->CtlID == IDC_COLORDLG_BUTTON)
  142. {
  143. CRect rect=lpDis->rcItem;
  144. ::FillRect(lpDis->hDC,&rect,(HBRUSH)::GetStockObject(BLACK_BRUSH));
  145. ::Rectangle(lpDis->hDC,rect.left+1,rect.top+1,rect.right-1,rect.bottom-1);
  146. ::SetBkColor(lpDis->hDC, RGB(0xff,0,0));
  147. ::ExtTextOut(lpDis->hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
  148. rect.left+=4;
  149. rect.top+=4;
  150. ::Rectangle(lpDis->hDC,rect.left+1,rect.top+1,rect.right-1,rect.bottom-1);
  151. ::SetBkColor(lpDis->hDC, RGB(0,0xff,0));
  152. ::ExtTextOut(lpDis->hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
  153. rect.left+=4;
  154. rect.top+=4;
  155. ::Rectangle(lpDis->hDC,rect.left+1,rect.top+1,rect.right-1,rect.bottom-1);
  156. ::SetBkColor(lpDis->hDC, RGB(0,0,0xff));
  157. ::ExtTextOut(lpDis->hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
  158. rect=lpDis->rcItem;
  159. //::DrawEdge(lpDis->hDC,&rect,BDR_RAISEDINNER,BF_RECT);
  160. }
  161. }
  162. break;
  163. case WM_SETCOLOR:
  164. crtColor = (COLORREF)wParam;
  165. oldColor = crtColor;
  166. break;
  167. case WM_COMMAND:
  168. ::PostMessage(hwndParent,WM_COLORDLG,NULL,NULL);
  169. break;
  170. case WM_MOUSEMOVE:
  171. {
  172. BOOL bInCtrlArea = FALSE;
  173. point.x = LPARAM_X(lParam);
  174. point.y = LPARAM_Y(lParam);
  175. ::ClientToScreen(hWnd,&point);
  176. HWND hwndPoint = ::WindowFromPoint(point);
  177. //::ScreenToClient(hWnd,&point);
  178. //{
  179. // if(hwndPoint==hwndColorBtn){// &&nDrawColorBtnFlag==2
  180. // HDC hDC;
  181. // hDC = ::GetWindowDC(hwndPoint);
  182. // CRect rect(0,0,16,16);
  183. // ::DrawEdge(hDC,&rect,BDR_SUNKENINNER,BF_RECT);
  184. // nDrawColorBtnFlag=1;
  185. // TRACE("hwndColorBtn:%dn",hwndColorBtn);
  186. // }else if(hwndPoint==hWnd&&nDrawColorBtnFlag!=1&&rectColorBtn.PtInRect(point)){
  187. // HDC hDC;
  188. // hDC = ::GetWindowDC(hwndPoint);
  189. // ::DrawEdge(hDC,&rectColorBtn,BDR_SUNKENINNER,BF_RECT);
  190. // nDrawColorBtnFlag=1;
  191. // TRACE("hwndColorBtn:%dn",hwndColorBtn);
  192. // }else if(hwndPoint==hWnd&&nDrawColorBtnFlag==1){
  193. // HDC hDC;
  194. // hDC = ::GetWindowDC(hwndPoint);
  195. // ::DrawEdge(hDC,&rectColorBtn,BDR_RAISEDINNER,BF_RECT);
  196. // nDrawColorBtnFlag=2;
  197. // }
  198. // TRACE("hwndpoind :%d, hwndParent:%d,hwndColorBtn:%dn",hwndPoint,hWnd,hwndColorBtn);
  199. //}
  200. //::ClientToScreen(hWnd,&point);
  201. if(point.x != oldPoint.x || point.y != oldPoint.y)
  202. {
  203. bMouseMoved = TRUE;
  204. if(hwndPoint)
  205. {
  206. COLORREF crtTMPColor;
  207. CRect rect;
  208. HDC hDC;
  209. hDC = ::GetWindowDC(hwndPoint);
  210. ::GetWindowRect(hwndPoint,&rect);
  211. int i=0,j=0;
  212. i=(point.x-rect.left)/20;
  213. j=(point.y-rect.top)/10;
  214. crtTMPColor = GetPixel(hDC,i*20 + 5,j*10+5);
  215. ::ReleaseDC(hWnd,hDC);
  216. RECT redrawRect;
  217. redrawRect.left = 0;
  218. redrawRect.right = 160;
  219. redrawRect.top = 80;
  220. redrawRect.bottom = 110;
  221. ::GetWindowRect(hWnd,&rect);
  222. rect.bottom = rect.top + 80;
  223. int iCurrentActiveRect;
  224. //
  225. if(rect.PtInRect(point))///判断鼠标是否在当前窗口的色彩区域
  226. {
  227. ////计算位于哪个方框内////
  228. point.x -= rect.left;
  229. point.y -= rect.top;
  230. if(point.x%20 != 0 && point.y%10 != 0)
  231. iCurrentActiveRect = point.y/10*8 + point.x/20;
  232. else
  233. iCurrentActiveRect = -1;
  234. }else{
  235. iCurrentActiveRect = -1;
  236. crtColor = oldColor;
  237. if(hwndColorBtn == hwndPoint)
  238. ::ReleaseCapture();
  239. else
  240. bInCtrlArea = TRUE;
  241. }
  242. if(iCurrentActiveRect != iActiveRect)
  243. {
  244. ///清除原焦点
  245. CRect ActiveRect;
  246. ActiveRect.left = iActiveRect%8*20;
  247. ActiveRect.top = iActiveRect/8*10;
  248. ActiveRect.right = ActiveRect.left + 20;
  249. ActiveRect.bottom = ActiveRect.top + 10;
  250. ::InvalidateRect(hWnd,&ActiveRect,TRUE);
  251. ///新焦点
  252. if(iCurrentActiveRect != -1)
  253. {
  254. crtColor = crtTMPColor;
  255. ActiveRect.left = iCurrentActiveRect%8*20;
  256. ActiveRect.top = iCurrentActiveRect/8*10;
  257. ActiveRect.right = ActiveRect.left + 20;
  258. ActiveRect.bottom = ActiveRect.top + 10;
  259. ::InvalidateRect(hWnd,&ActiveRect,TRUE);
  260. }
  261. ::InvalidateRect(hWnd,&redrawRect,TRUE);
  262. iActiveRect = iCurrentActiveRect;
  263. }
  264. }
  265. }
  266. if(bInCtrlArea)
  267. ::PostMessage(hwndParent,WM_SETCURSOR,NULL,MAKELPARAM(1,0));
  268. else
  269. ::PostMessage(hwndParent,WM_SETCURSOR,NULL,NULL);
  270. }
  271. break;
  272. case WM_ACTIVATE:
  273. if(LOWORD(wParam) != WA_INACTIVE)
  274. break;
  275. case WM_LBUTTONUP:
  276. point.x = LPARAM_X(lParam);
  277. point.y = LPARAM_Y(lParam);
  278. if(bMouseMoved || ( point.x == oldPoint.x && point.y == oldPoint.y ))
  279. ::PostMessage(hwndParent,WM_LBUTTONUP,(UINT)crtColor,lParam);
  280. break;
  281. case WM_LBUTTONDOWN:
  282. oldPoint.x = LPARAM_X(lParam);
  283. oldPoint.y = LPARAM_Y(lParam);
  284. bMouseMoved = FALSE;
  285. ::InvalidateRect(hWnd,&crtColorRect,TRUE);
  286. break;
  287. case WM_ERASEBKGND:
  288. {
  289. hDC = (HDC)wParam;
  290. HPEN oldPen = (HPEN)::SelectObject(hDC,penB);
  291. for(int i=0;i<=8;i++)
  292. {
  293. ::MoveToEx(hDC,i*20,0,NULL);
  294. ::LineTo(hDC,i*20,80);
  295. }
  296. for(i=0;i<=8;i++)
  297. {
  298. ::MoveToEx(hDC,0,i*10,NULL);
  299. ::LineTo(hDC,160,i*10);
  300. }
  301. CRect btmRect(0,80,160,110);
  302. ::FillRect(hDC,btmRect,(HBRUSH)::GetStockObject(LTGRAY_BRUSH));
  303. ::Rectangle(hDC,crtColorRect.left-1,crtColorRect.top-1,crtColorRect.right + 1,crtColorRect.bottom + 1);
  304. ::SelectObject(hDC,oldPen);
  305. }
  306. break;
  307. case WM_PAINT:
  308. {
  309. hDC = ::BeginPaint(hWnd,&ps);
  310. CDC dc;
  311. dc.Attach(hDC);
  312. CRect rect;
  313. int x1,y1,i,j,k;
  314. UCHAR R=0,G=0,B=0;
  315. //xgl 2004.3.11
  316. //初始颜色的配置:分R,G,B三块,4*4为基元,先行后列,B 增加;基元内:R按行增加,G按列增加
  317. for(j = 0;j < 8;j++)
  318. for(i = 0;i < 8;i++)
  319. {
  320. x1 = j*20;
  321. y1 = i*10;
  322. //85=256/3;
  323. R=85*(i%4);
  324. G=85*(j%4);
  325. B=((i/4)*2+j/4)*85;
  326. rect.SetRect(x1,y1,x1+20,y1+10);
  327. dc.FillSolidRect(rect,RGB(0,200,200));
  328. rect.SetRect(x1+2,y1+1,x1+18,y1+9);
  329. dc.FillSolidRect(rect,RGB(10,10,10));
  330. rect.SetRect(x1+3,y1+2,x1+17,y1+8);
  331. dc.FillSolidRect(rect,RGB(R,G,B));
  332. }
  333. if(iActiveRect != -1)
  334. {
  335. CRect ActiveRect;
  336. ActiveRect.left = iActiveRect%8*20;
  337. ActiveRect.top = iActiveRect/8*10;
  338. ActiveRect.right = ActiveRect.left + 20;
  339. ActiveRect.bottom = ActiveRect.top + 10;
  340. dc.DrawFocusRect(ActiveRect);
  341. }
  342. rect.SetRect(0,81,160,82);
  343. dc.FillSolidRect(rect,RGB(0,0,0));
  344. rect.SetRect(0,82,160,110);
  345. dc.FillSolidRect(rect,RGB(12,180,180));
  346. dc.FillSolidRect(crtColorRect.left-2,crtColorRect.top-2,crtColorRect.Width()+4,crtColorRect.Height()+4,RGB(0,0,0));
  347. dc.FillSolidRect(crtColorRect,crtColor);
  348. char strColor[8]="#";
  349. sprintf(strColor+1,"%02X%02X%02X",GetRValue(crtColor),GetGValue(crtColor),GetBValue(crtColor));
  350. HFONT hOldFont = (HFONT)dc.SelectObject(hFont);
  351. dc.SetBkMode(TRANSPARENT);
  352. dc.TextOut(80,90,strColor,7);
  353. dc.SelectObject(hOldFont);
  354. dc.Detach();
  355. ::EndPaint(hWnd,&ps);
  356. }
  357. break;
  358. default:
  359. return(::DefWindowProc(hWnd,nMsg,wParam,lParam));
  360. }
  361. return NULL;
  362. }
  363. BOOL CColorSelect::CreatePaletteWindow()
  364. {
  365. if(!m_bPaletteWndActive)
  366. {
  367. // 创建调色板子窗口
  368. WNDCLASS wndcls;
  369. wndcls.style = CS_HREDRAW | CS_VREDRAW;
  370. wndcls.lpfnWndProc = PaletteWndProc;
  371. wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
  372. wndcls.hInstance = ::AfxGetInstanceHandle();
  373. wndcls.hIcon = NULL;
  374. wndcls.hCursor = NULL;
  375. wndcls.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
  376. wndcls.lpszMenuName = NULL;
  377. wndcls.lpszClassName = "ColorPalette";
  378. if (!::RegisterClass(&wndcls))
  379. AfxThrowResourceException();
  380. HDC hDC = ::GetDC(m_hWnd);
  381. int scrWidth = ::GetDeviceCaps(hDC,HORZRES);
  382. int scrHeight = ::GetDeviceCaps(hDC,VERTRES);
  383. ::ReleaseDC(m_hWnd,hDC);
  384. CRect rect;
  385. GetWindowRect(rect);
  386. rect.top = rect.bottom - 1;
  387. if(rect.left > scrWidth-160)
  388. rect.left = scrWidth-160;
  389. else if(rect.left < 0)
  390. rect.left = 0;
  391. if(rect.top > scrHeight-110)
  392. rect.top = rect.top-110;
  393. rect.bottom = rect.top + 110;
  394. rect.right = rect.left + 160;
  395. if(!(m_hPaletteWnd = ::CreateWindowEx(WS_EX_TOPMOST,"ColorPalette","Palatte",WS_POPUP|WS_BORDER|WS_VISIBLE,rect.left,rect.top,rect.Width(),rect.Height(),m_hWnd,NULL,wndcls.hInstance,NULL)))
  396. return FALSE;
  397. }
  398. ::PostMessage(m_hPaletteWnd,WM_SETCOLOR,(WPARAM)m_CurrentColor,NULL);
  399. ::ShowWindow(m_hPaletteWnd,SW_SHOW);
  400. ::SetCapture(m_hPaletteWnd);
  401. m_bPaletteWndActive = TRUE;
  402. return TRUE;
  403. }
  404. void CColorSelect::DestroyPaletteWindow()
  405. {
  406. ::DestroyWindow(m_hPaletteWnd);
  407. ::UnregisterClass("ColorPalette",::AfxGetInstanceHandle());
  408. m_bPaletteWndActive = FALSE;
  409. m_hPaletteWnd = NULL;
  410. }
  411. BOOL CColorSelect::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
  412. {
  413. if(m_bPaletteWndActive && m_hCursorStraw && nHitTest != 1)
  414. ::SetCursor(m_hCursorStraw);
  415. else
  416. ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  417. return TRUE;
  418. }
  419. void CColorSelect::GetColor(CString& strColor)
  420. {
  421. char cColor[8]="#";
  422. sprintf(cColor+1,"%02X%02X%02X",GetRValue(m_CurrentColor),GetGValue(m_CurrentColor),GetBValue(m_CurrentColor));
  423. strColor = cColor;
  424. }
  425. COLORREF CColorSelect::GetColor()
  426. {
  427. return m_CurrentColor;
  428. }
  429. LRESULT CColorSelect::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  430. {
  431. if(message == WM_COLORDLG)
  432. {
  433. DestroyPaletteWindow();
  434. CColorDialog dlg;
  435. //dlg.m_cc.Flags |= CC_FULLOPEN;
  436. if(dlg.DoModal() == IDOK){
  437. SetColor(dlg.GetColor());
  438. }
  439. return TRUE;
  440. }
  441. else
  442. return CButton::DefWindowProc(message, wParam, lParam);
  443. }
  444. void CColorSelect::SetColor(COLORREF ref)
  445. {
  446. m_CurrentColor = ref;
  447. ((CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView())->m_clrCurrentColor=ref;
  448. Invalidate();
  449. }
  450. void CColorSelect::OnPaint() 
  451. {
  452. CPaintDC dc(this); // device context for painting
  453. // TODO: Add your message handler code here
  454.   //xiagl@fnst 2004.3.10(add_start)
  455.     //Draw the left half of ColorPicker
  456. dc.FillSolidRect(m_rectFill,RGB(((int)GetRValue(m_CurrentColor)+128)%256,((int)GetGValue(m_CurrentColor)+128)%256,((int)GetBValue(m_CurrentColor)+128)%256));
  457.     CPen pen1,*m_poldPen;
  458. LOGBRUSH m_logbr1;
  459. m_logbr1.lbStyle=BS_SOLID;
  460. m_logbr1.lbColor=m_CurrentColor;
  461. pen1.CreatePen(PS_GEOMETRIC, m_rectFill.Height()/8, &m_logbr1);  
  462. m_poldPen=dc.SelectObject(&pen1);
  463.     dc.MoveTo(m_rectFill.left+m_rectFill.Width()/8,m_rectFill.top+m_rectFill.Height()*7/8);
  464. dc.LineTo(m_rectFill.Width()/2,m_rectFill.top+m_rectFill.Height()/8);
  465. dc.LineTo(m_rectFill.left+m_rectFill.Width()*7/8,m_rectFill.top+m_rectFill.Height()*7/8);
  466. dc.LineTo(m_rectFill.left+m_rectFill.Width()*7/8-2,m_rectFill.top+m_rectFill.Height()*7/8-2);
  467. dc.MoveTo(m_rectFill.left+m_rectFill.Width()*5/16,m_rectFill.top+m_rectFill.Height()/2);
  468. dc.LineTo(m_rectFill.left+m_rectFill.Width()*11/16,m_rectFill.top+m_rectFill.Height()/2);
  469.     dc.SelectObject(m_poldPen);
  470. //Draw the right half of ColorPicker
  471. CPoint points[3];
  472. points[0].x=m_rectSel.left+m_rectSel.Width()*1.0/4;
  473. points[0].y=m_rectSel.Height()*0.5;
  474. points[1].x=m_rectSel.left+m_rectSel.Width()*1.0/2;
  475. points[1].y=m_rectSel.Height()*0.7;
  476. points[2].x=m_rectSel.left+m_rectSel.Width()*3.0/4+1;
  477. points[2].y=m_rectSel.Height()*0.5;
  478. CRgn rgn; 
  479. rgn.CreatePolygonRgn(points,3,1);   
  480. CBrush brush,*p_oldbr;
  481. brush.CreateSolidBrush(RGB(0,0,0));
  482. p_oldbr=dc.SelectObject(&brush);
  483. dc.FillRgn(&rgn,&brush);
  484. dc.SelectObject(p_oldbr); 
  485.   //xiagl@fnst 2004.3.10(add_start)
  486. // Do not call CButton::OnPaint() for painting messages
  487. }
  488. void  CColorSelect::SetFillRect(CRect rect)
  489. {
  490. this->m_rectFill.left=rect.left;
  491. this->m_rectFill.right=rect.right;
  492. this->m_rectFill.top=rect.top;
  493. this->m_rectFill.bottom=rect.bottom;
  494. }
  495. void  CColorSelect::SetFillRect(int left,int top,int right,int bottom)
  496. {
  497.   this->m_rectFill.left=left;
  498.   this->m_rectFill.right=right;
  499.   this->m_rectFill.top=top;
  500.   this->m_rectFill.bottom=bottom;
  501. }
  502. CRect CColorSelect::GetFillRect()
  503. {
  504. return this->m_rectFill;
  505. }
  506. void  CColorSelect::SetSelRect(CRect rect)
  507. {
  508. this->m_rectSel.left=rect.left;
  509. this->m_rectSel.right=rect.right;
  510. this->m_rectSel.top=rect.top;
  511. this->m_rectSel.bottom=rect.bottom;
  512. }
  513. void  CColorSelect::SetSelRect(int left,int top,int right,int bottom)
  514. {
  515. this->m_rectSel.left=left;
  516. this->m_rectSel.right=right;
  517. this->m_rectSel.top=top;
  518. this->m_rectSel.bottom=bottom; 
  519. }
  520. CRect CColorSelect::GetSelRect()
  521. {
  522. return this->m_rectSel;
  523. }
  524. void CColorSelect::OnMouseMove(UINT nFlags, CPoint point) 
  525. {
  526. // TODO: Add your message handler code here and/or call default
  527. TRACKMOUSEEVENT tme;
  528. tme.cbSize = sizeof(tme);
  529. tme.hwndTrack = m_hWnd;
  530. tme.dwFlags = TME_LEAVE | TME_HOVER;
  531. tme.dwHoverTime = 1;
  532.     _TrackMouseEvent(&tme);
  533. CClientDC dc(this);
  534. if(m_rectFill.PtInRect(point)){
  535. dc.DrawEdge(&m_rectFill,BDR_RAISEDINNER,BF_RECT);
  536. dc.DrawEdge(&m_rectSel,BDR_RAISEDINNER,BF_RECT);
  537. }else if(m_rectSel.PtInRect(point)){
  538. dc.DrawEdge(&m_rectFill,BDR_RAISEDINNER,BF_RECT);
  539. dc.DrawEdge(&m_rectSel,BDR_RAISEDINNER,BF_RECT);
  540. }
  541. CButton::OnMouseMove(nFlags, point);
  542. }
  543. LRESULT CColorSelect::OnMouseLeave(WPARAM wParam, LPARAM lParam)
  544. {
  545. HWND hwndParent = GetParent()->m_hWnd;
  546.     if(hwndParent)
  547.  {
  548.  POINT p1,p2;
  549.  RECT rect;
  550.  ::GetWindowRect(m_hWnd,&rect);
  551.  p1.x = rect.left;
  552.  p1.y = rect.top;
  553.  p2.x = rect.right;
  554.  p2.y = rect.bottom;
  555.  ::ScreenToClient(hwndParent,&p1);
  556.  ::ScreenToClient(hwndParent,&p2);
  557.  rect.left = p1.x;
  558.  rect.top = p1.y;
  559.  rect.right = p2.x;
  560.  rect.bottom = p2.y;
  561.  ::InvalidateRect(hwndParent,&rect,TRUE);
  562.  }
  563. return 0;
  564. }
  565. LRESULT CColorSelect::OnMouseHover(WPARAM wParam, LPARAM lParam)
  566. {
  567. return 0;
  568. }
  569. void CColorSelect::OnLButtonDblClk(UINT nFlags, CPoint point) 
  570. {
  571. // TODO: Add your message handler code here and/or call default
  572. //CButton::OnLButtonDblClk(nFlags, point);
  573. }