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

IP电话/视频会议

开发平台:

Visual C++

  1. //NetTalk
  2. /*------------------------------------------------------------------------------*
  3.  =============================
  4.    模块名称: GraphDlg.cpp
  5.  =============================
  6.  
  7.  [版权]
  8.  
  9.    2000-2002  115软件工厂  版权所有
  10.                                               
  11. *------------------------------------------------------------------------------*/
  12. #include "wndx.h"
  13. #include "GraphDlg.h"
  14. #include <Windowsx.h>
  15. #include "resource.h"
  16. #define BORDER_WIDTH 1
  17. #define TITLE_HEIGHT 18
  18. /*------------------------------------------------------------------------------*/
  19. CGraphDlg::CGraphDlg()
  20. {
  21. m_bHilight=0;
  22. m_hbBkS=CreateSolidBrush(0x00b9b4b3);//Static ctrl's bg color
  23. m_hbBkE=CreateSolidBrush(0x00ffffff);//Edit ctrl's bg color
  24. }
  25. /*------------------------------------------------------------------------------*/
  26. CGraphDlg::~CGraphDlg()
  27. {
  28. if(m_hbBkS)
  29. DeleteObject(m_hbBkS);
  30. if(m_hbBkE)
  31. DeleteObject(m_hbBkE);
  32. }
  33. /*------------------------------------------------------------------------------*/
  34. LRESULT CGraphDlg::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  35. {
  36. switch(uMsg)
  37. {
  38. case WM_CTLCOLORSTATIC:
  39. {
  40. SetBkMode((HDC)wParam,TRANSPARENT);
  41. return (LRESULT)m_hbBkS;
  42. }
  43. break;
  44. case WM_CTLCOLOREDIT:
  45. {
  46. SetTextColor((HDC)wParam,0x00632201);
  47. return (LRESULT)m_hbBkE;
  48. }
  49. break;
  50. case WM_DESTROY:
  51. OnDestroy();
  52. break;
  53. case WM_INITDIALOG:
  54. return OnInitDialog();
  55. break;
  56. case WM_COMMAND:
  57. return OnCommand(wParam,lParam);
  58. break;
  59. case WM_ERASEBKGND:
  60. OnEraseBkgnd((HDC)wParam);
  61. return TRUE;
  62. case WM_MOUSEMOVE:
  63. {
  64. POINT point;
  65. point.x=GET_X_LPARAM(lParam); 
  66. point.y=GET_Y_LPARAM(lParam); 
  67. OnMouseMove(wParam,point);
  68. }
  69. break;
  70. case WM_LBUTTONDOWN:
  71. {
  72. POINT point;
  73. point.x=GET_X_LPARAM(lParam); 
  74. point.y=GET_Y_LPARAM(lParam); 
  75. OnLButtonDown(wParam,point);
  76. }
  77. break;
  78. case WM_TIMER:
  79. OnTimer(wParam);
  80. break;
  81. default:
  82. return CDialogX::WndProc(uMsg,wParam,lParam);
  83. }
  84. return TRUE;
  85. }
  86. /*------------------------------------------------------------------------------*/
  87. void CGraphDlg::OnEraseBkgnd(HDC hdc)
  88. {
  89. CRectX rc;
  90. GetClientRect(m_hWnd,&rc);
  91. HDC hMemDC=CreateCompatibleDC(hdc);
  92. HBITMAP hb=CreateCompatibleBitmap(hdc,rc.Width(),rc.Height());
  93. HBITMAP hob=(HBITMAP)SelectObject(hMemDC,hb);
  94. //画客户区
  95. FillSolidRectX(hMemDC,CRectX(rc.left+2,BORDER_WIDTH,rc.right-2,rc.bottom-2),0x00b9b4b3);
  96. //画标题栏
  97. DrawTitleBar(hMemDC);
  98. //画框架
  99. DrawRectX(hMemDC,rc,0);
  100. CRectX rc2;
  101. rc2=rc;
  102. InflateRect(&rc2,-1,-1);
  103. Draw3dRectX(hMemDC,rc2,0x00e8e8e8,0x009c9c9c,1);
  104. BitBlt(hdc,0,0,rc.Width(),rc.Height(),hMemDC,0,0,SRCCOPY);
  105. SelectObject(hMemDC,hob);
  106. DeleteObject(hb);
  107. DeleteDC(hMemDC);
  108. }
  109. /*------------------------------------------------------------------------------*/
  110. //make the title bar dragable
  111. void CGraphDlg::OnLButtonDown(UINT nFlags, POINT &point)
  112. {
  113. if(PtInRegion(m_hTRgn,point.x,point.y))
  114. {
  115. SetCapture(m_hWnd);
  116. RECT rc;
  117. GetWindowRect(m_hWnd,&rc);
  118. MSG msg;
  119. while(GetMessage(&msg, NULL, 0, 0))
  120. {
  121. if (GetCapture()!=m_hWnd)
  122. {
  123. DispatchMessage(&msg);
  124. break;
  125. }
  126. switch(msg.message)
  127. {
  128. case WM_MOUSEMOVE:
  129. {
  130. POINT pt;
  131. pt.x=GET_X_LPARAM(msg.lParam);
  132. pt.y=GET_Y_LPARAM(msg.lParam);
  133. rc.left+=pt.x-point.x;
  134. rc.top+=pt.y-point.y;
  135. SetWindowPos(m_hWnd,0,rc.left,
  136. rc.top,0,0,SWP_NOSIZE);
  137. }
  138. break;
  139. case WM_LBUTTONUP:
  140. goto EXITLOOP1;
  141. default:
  142. DispatchMessage(&msg);
  143. break;
  144. }
  145. }
  146. EXITLOOP1:
  147. ReleaseCapture();
  148. }
  149. }
  150. /*------------------------------------------------------------------------------*/
  151. //Hilight the title bar when mouse hover the title bar
  152. void CGraphDlg::OnMouseMove(UINT nFlags, POINT &point)
  153. {
  154. if(PtInRegion(m_hTRgn,point.x,point.y))
  155. {
  156. if(!m_bHilight)
  157. {
  158. m_bHilight=TRUE;
  159. HDC hdc=GetDC(m_hWnd);
  160. DrawTitleBar(hdc);
  161. ReleaseDC(m_hWnd,hdc);
  162. SetTimer(m_hWnd,101,50,0);
  163. }
  164. }
  165. }
  166. /*------------------------------------------------------------------------------*/
  167. //
  168. BOOL CGraphDlg::OnInitDialog()
  169. {
  170. RECT rc;
  171. //
  172. GetClientRect(m_hWnd,&rc);
  173. //make the title bar region
  174. POINT pt[4];
  175. pt[0].x=2;
  176. pt[0].y=2;
  177. pt[1].x=rc.right-30;
  178. pt[1].y=2;
  179. pt[2].x=rc.right-30-TITLE_HEIGHT;
  180. pt[2].y=TITLE_HEIGHT+BORDER_WIDTH;
  181. pt[3].x=2;
  182. pt[3].y=TITLE_HEIGHT+BORDER_WIDTH;
  183. m_hTRgn=CreatePolygonRgn(pt,4,ALTERNATE);
  184. //create the close button
  185. rc.left=rc.right-20;
  186. rc.right-=8;
  187. rc.top=5;
  188. rc.bottom=17;
  189. m_btnClose.LoadBitmaps(IDB_CLOSE1,IDB_CLOSE2,IDB_CLOSE3);
  190. m_btnClose.Create(rc,m_hWnd,IDC_CLOSE);
  191. return FALSE;
  192. }
  193. /*------------------------------------------------------------------------------*/
  194. BOOL CGraphDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  195. {
  196. CDialogX::OnCommand(wParam,lParam);
  197. switch(LOWORD(wParam))
  198. {
  199. case IDC_CLOSE:
  200. SendMessage(m_hWnd,WM_CLOSE,0,0);
  201. break;
  202. }
  203. return TRUE;
  204. }
  205. /*------------------------------------------------------------------------------*/
  206. void CGraphDlg::DrawTitleBar(HDC hdc)
  207. {
  208. //file the title bar region,and make it 3d look
  209. RECT rc;
  210. GetClientRect(m_hWnd,&rc);
  211. HBRUSH hbr;
  212. if(m_bHilight)
  213. hbr=CreateSolidBrush(0x00886655);
  214. else
  215. hbr=CreateSolidBrush(0x00553322);
  216. FillRgn(hdc,m_hTRgn,hbr);
  217. DeleteObject(hbr);
  218. HPEN hp=CreatePen(PS_SOLID,1,0);
  219. HPEN hop=(HPEN)SelectObject(hdc,hp);
  220. MoveToEx(hdc,2,TITLE_HEIGHT+BORDER_WIDTH,0);
  221. LineTo(hdc,2,2);
  222. LineTo(hdc,rc.right-30,2);
  223. SelectObject(hdc,hop);
  224. DeleteObject(hp);
  225. hp=CreatePen(PS_SOLID,1,0x00eeeeee);
  226. hop=(HPEN)SelectObject(hdc,hp);
  227. LineTo(hdc,rc.right-30-TITLE_HEIGHT+1,TITLE_HEIGHT+BORDER_WIDTH);
  228. LineTo(hdc,1,TITLE_HEIGHT+BORDER_WIDTH);
  229. SelectObject(hdc,hop);
  230. DeleteObject(hp);
  231. //画标题栏caption
  232. char szTitle[64]="";
  233. NONCLIENTMETRICS ncm;
  234. ncm.cbSize = sizeof(ncm);
  235. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  236. HFONT hf=CreateFontIndirect(&ncm.lfCaptionFont);
  237. HFONT hof=(HFONT)SelectObject(hdc,hf);
  238. SetBkMode(hdc,TRANSPARENT);
  239. SetTextColor(hdc,0x00ffffff);
  240. GetWindowText(m_hWnd,szTitle,63);
  241. DrawText(hdc,szTitle,strlen(szTitle),&CRectX(6,4,rc.right-30,30),DT_LEFT);
  242. SelectObject(hdc,hof);
  243. DeleteObject(hf);
  244. }
  245. /*------------------------------------------------------------------------------*/
  246. //when the mouse leave the region of title bar ,recover the title bar
  247. void CGraphDlg::OnTimer(UINT nIDEvent)
  248. {
  249. if(nIDEvent==101)
  250. {
  251. DWORD dw=GetMessagePos();
  252. POINT pt;
  253. pt.x=GET_X_LPARAM(dw);
  254. pt.y=GET_Y_LPARAM(dw);
  255. ScreenToClient(m_hWnd,&pt);
  256. if(m_bHilight)
  257. {
  258. if(!PtInRegion(m_hTRgn,pt.x,pt.y))
  259. {
  260. RECT rc;
  261. SetRect(&rc,2,2,119,16);
  262. m_bHilight=FALSE;
  263. HDC hdc=GetDC(m_hWnd);
  264. DrawTitleBar(hdc);
  265. ReleaseDC(m_hWnd,hdc);
  266. KillTimer(m_hWnd,nIDEvent);
  267. }
  268. }
  269. }
  270. }
  271. /*------------------------------------------------------------------------------*/
  272. //
  273. void CGraphDlg::OnDestroy()
  274. {
  275. DeleteObject(m_hTRgn);
  276. }