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

IP电话/视频会议

开发平台:

Visual C++

  1. #include "WndX.h"
  2. #include <WindowsX.h>
  3. #include "MsgBox.h"
  4. #include "resource.h"
  5. CMsgBox::CMsgBox()
  6. {
  7. m_hbmpClose=LoadBitmap(hInstX,LPCTSTR(IDB_CLOSE));
  8. m_hbmpFace=LoadBitmap(hInstX,LPCTSTR(IDB_MSGBOX));
  9. m_hbmpT1=LoadBitmap(hInstX,LPCTSTR(IDB_MSGTITLE1));
  10. m_hbmpT2=LoadBitmap(hInstX,LPCTSTR(IDB_MSGTITLE2));
  11. //HRGN hrgnTitle=
  12. }
  13. CMsgBox::~CMsgBox()
  14. {
  15. if(m_hbmpClose)
  16. DeleteObject(m_hbmpClose);
  17. if(m_hbmpFace)
  18. DeleteObject(m_hbmpFace);
  19. if(m_hbmpT1)
  20. DeleteObject(m_hbmpT1);
  21. if(m_hbmpT2)
  22. DeleteObject(m_hbmpT2);
  23. }
  24. LRESULT CMsgBox::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  25. {
  26. switch(uMsg)
  27. {
  28. case WM_INITDIALOG:
  29. {
  30. POINT pt[5]={{0,11},{11,0},{238,0},{238,102},{0,102}};
  31. HRGN h=CreatePolygonRgn(pt,5,ALTERNATE);
  32. SetWindowRgn(m_hWnd,h,0);
  33. m_btnClose.SetType(CCoolBtn::tFlat|CCoolBtn::tBitmap);
  34. m_btnClose.SetColor(CCoolBtn::fFace,0x00b9b4b3);
  35. m_btnClose.SetBitmap(m_hbmpClose,0x00ffffff);
  36. m_btnClose.SetRect((RECT)CRectX(60,3,72,15));
  37. m_btn1.SetType(CCoolBtn::tText);
  38. m_btn2.SetType(CCoolBtn::tText);
  39. m_btn1.SetColor(CCoolBtn::fFace,0x00b9b4b3);
  40. m_btn2.SetColor(CCoolBtn::fFace,0x00b9b4b3);
  41. if(m_type==MBX_OK)
  42. m_btn1.SetText("确定");
  43. if(m_type==MBX_YESNO)
  44. {
  45. m_btn1.SetText("是");
  46. m_btn2.SetText("否");
  47. }
  48. m_btn1.SetRect((RECT)CRectX(165,57,180,70));
  49. m_btn2.SetRect((RECT)CRectX(140,57,160,70));
  50. }
  51. break;
  52. case WM_ERASEBKGND:
  53. return OnEraseBkgnd((HDC)wParam);
  54. break;
  55. case WM_MOUSEMOVE:
  56. {
  57. POINT point;
  58. point.x=GET_X_LPARAM(lParam); 
  59. point.y=GET_Y_LPARAM(lParam); 
  60. OnMouseMove(wParam,point);
  61. }
  62. break;
  63. case WM_LBUTTONDOWN:
  64. {
  65. POINT point;
  66. point.x=GET_X_LPARAM(lParam); 
  67. point.y=GET_Y_LPARAM(lParam); 
  68. OnLButtonDown(wParam,point);
  69. }
  70. break;
  71. case WM_SETCURSOR:
  72. {
  73. DWORD dw=GetMessagePos();
  74. POINT pt;
  75. pt.x=GET_X_LPARAM(dw);
  76. pt.y=GET_Y_LPARAM(dw);
  77. ScreenToClient(m_hWnd,&pt);
  78. if(PtInRegion(m_hrgnTitle,pt.x,pt.y))
  79. {
  80. SetCursor(LoadCursor(hInstX,LPCTSTR(IDC_DRAG)));
  81. return TRUE;
  82. }
  83. return FALSE;
  84. }
  85. break;
  86. default:
  87. return CDialogX::WndProc(uMsg,wParam,lParam);
  88. }
  89. return TRUE;
  90. }
  91. UINT CMsgBox::ShowMsg(char *caption, char *msg, UINT type, HWND hwnd)
  92. {
  93. if(caption)
  94. strncpy(m_caption,caption,127);
  95. if(msg)
  96. strncpy(m_msg,msg,255);
  97. m_type=type;
  98. return (UINT)DoModal((LPCTSTR)IDD_MSG_DLG,hwnd);
  99. }
  100. int CMsgBox::DoModal(LPCTSTR lpszTemplateName, HWND hWndParent)
  101. {
  102. CDialogX::DoModal(lpszTemplateName,hWndParent);
  103. return m_uResult;
  104. }
  105. BOOL CMsgBox::OnEraseBkgnd(HDC hdc)
  106. {
  107. HDC hMemDC;
  108. hMemDC=CreateCompatibleDC(hdc);
  109. HBITMAP hob=(HBITMAP)SelectObject(hMemDC,m_hbmpFace);
  110. if(m_bHilight)
  111. {
  112. DrawTransBmpX(hMemDC,m_rcTitle,m_hbmpT2,0,0,0);
  113. }
  114. else
  115. {
  116. DrawTransBmpX(hMemDC,m_rcTitle,m_hbmpT1,0,0,0);
  117. }
  118. m_btnClose.Paint(hMemDC);
  119. HFONT hf=GetWindowFont(m_hWnd);
  120. TxtBlt(hMemDC,m_msg,m_rcMsg,0,0x00b9b4b3,hf,FALSE);
  121. BitBlt(hdc,0,0,m_rc.Width(),m_rc.Height(),hMemDC,0,0,SRCCOPY);
  122. SelectObject(hMemDC,hob);
  123. DeleteObject(m_hbmpFace);
  124. DeleteDC(hMemDC);
  125. return TRUE;
  126. }
  127. void CMsgBox::OnMouseMove(UINT nFlags, POINT point)
  128. {
  129. if(PtInRegion(m_hrgnTitle,point.x,point.y))
  130. {
  131. if(!m_bHilight)
  132. {
  133. m_bHilight=TRUE;
  134. HDC hdc=GetDC(m_hWnd);
  135. DrawTransBmpX(hdc,m_rcTitle,m_hbmpT2,0,0,0);
  136. ReleaseDC(m_hWnd,hdc);
  137. SetTimer(m_hWnd,1,100,0);
  138. }
  139. }
  140. else
  141. if(m_btnClose.IsMouseOn(point))
  142. {
  143. HDC hdc=GetDC(m_hWnd);
  144. m_btnZoom.Paint(hdc);
  145. m_btnClose.Paint(hdc,CCoolBtn::sHover);
  146. ReleaseDC(m_hWnd,hdc);
  147. SetTimer(m_hWnd,1,100,0);
  148. }
  149. else
  150. if(m_btnZoom.IsMouseOn(point))
  151. {
  152. HDC hdc=GetDC(m_hWnd);
  153. m_btnClose.Paint(hdc);
  154. m_btnZoom.Paint(hdc,CCoolBtn::sHover);
  155. ReleaseDC(m_hWnd,hdc);
  156. SetTimer(m_hWnd,1,100,0);
  157. }
  158. else
  159. if(m_bHilight)
  160. {
  161. m_bHilight=FALSE;
  162. HDC hdc=GetDC(m_hWnd);
  163. DrawTransBmpX(hdc,m_rcTitle,m_hbmpT1,0,0,0);
  164. ReleaseDC(m_hWnd,hdc);
  165. KillTimer(m_hWnd,1);
  166. }
  167. else
  168. {
  169. HDC hdc=GetDC(m_hWnd);
  170. m_btnZoom.Paint(hdc);
  171. m_btnClose.Paint(hdc);
  172. ReleaseDC(m_hWnd,hdc);
  173. }
  174. }
  175. void CMsgBox::OnLButtonDown(UINT nFlags, POINT &point)
  176. {
  177. if(PtInRegion(m_hrgnTitle,point.x,point.y))
  178. {
  179. SetCapture(m_hWnd);
  180. RECT rc;
  181. GetWindowRect(m_hWnd,&rc);
  182. MSG msg;
  183. while(GetMessage(&msg, NULL, 0, 0))
  184. {
  185. if (GetCapture()!=m_hWnd)
  186. {
  187. DispatchMessage(&msg);
  188. break;
  189. }
  190. switch(msg.message)
  191. {
  192. case WM_MOUSEMOVE:
  193. {
  194. POINT pt;
  195. pt.x=GET_X_LPARAM(msg.lParam);
  196. pt.y=GET_Y_LPARAM(msg.lParam);
  197. rc.left+=pt.x-point.x;
  198. rc.top+=pt.y-point.y;
  199. SetWindowPos(m_hWnd,0,rc.left,
  200. rc.top,0,0,SWP_NOSIZE);
  201. }
  202. break;
  203. case WM_LBUTTONUP:
  204. goto EXITLOOP1;
  205. default:
  206. DispatchMessage(&msg);
  207. break;
  208. }
  209. }
  210. EXITLOOP1:
  211. ReleaseCapture();
  212. }
  213. if(m_btnClose.IsMouseOn(point))
  214. {
  215. KillTimer(m_hWnd,1);
  216. SetCapture(m_hWnd);
  217. HDC hdc=GetDC(m_hWnd);
  218. m_btnClose.Paint(hdc,CCoolBtn::sDown);
  219. ReleaseDC(m_hWnd,hdc);
  220. MSG msg;
  221. while(GetMessage(&msg, NULL, 0, 0))
  222. {
  223. if (GetCapture()!=m_hWnd)
  224. {
  225. DispatchMessage(&msg);
  226. break;
  227. }
  228. switch (msg.message)
  229. {
  230. case WM_MOUSEMOVE:
  231. break;
  232. case WM_LBUTTONUP:
  233. {
  234. POINT pt;
  235. pt.x=GET_X_LPARAM(msg.lParam);
  236. pt.y=GET_Y_LPARAM(msg.lParam);
  237. if(m_btnClose.IsMouseOn(pt))
  238. {
  239. SendMessage(m_hWnd,WM_CLOSE,0,0);
  240. }
  241. }
  242. goto EXITLOOP2;
  243. case WM_KEYDOWN:
  244. if (msg.wParam != VK_ESCAPE) 
  245. break;
  246. default:
  247. DispatchMessage(&msg);
  248. break;
  249. }
  250. }
  251. EXITLOOP2:
  252. if(m_hWnd)
  253. {
  254. hdc=GetDC(m_hWnd);
  255. m_btnClose.Paint(hdc);
  256. ReleaseDC(m_hWnd,hdc);
  257. }
  258. ReleaseCapture();
  259. }
  260. }
  261. void CMsgBox::OnTimer(UINT nIDEvent)
  262. {
  263. DWORD dw=GetMessagePos();
  264. POINT pt;
  265. pt.x=GET_X_LPARAM(dw);
  266. pt.y=GET_Y_LPARAM(dw);
  267. ScreenToClient(m_hWnd,&pt);
  268. if(m_bHilight)
  269. {
  270. if(!PtInRegion(m_hrgnTitle,pt.x,pt.y))
  271. {
  272. RECT rc;
  273. SetRect(&rc,2,2,119,16);
  274. m_bHilight=FALSE;
  275. HDC hdc=GetDC(m_hWnd);
  276. DrawTransBmpX(hdc,rc,m_hbmpT1,0,0,0);
  277. ReleaseDC(m_hWnd,hdc);
  278. KillTimer(m_hWnd,1);
  279. }
  280. }
  281. if(!m_btnClose.IsMouseOn(pt))
  282. {
  283. HDC hdc=GetDC(m_hWnd);
  284. m_btnClose.Paint(hdc);
  285. ReleaseDC(m_hWnd,hdc);
  286. }
  287. }