QR_Image.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. // QR_Image.cpp : 傾僾儕働乕僔儑儞梡僋儔僗偺婡擻掕媊
  2. // Date 2006/05/17 Ver. 1.22 Psytec Inc.
  3. #include "stdafx.h"
  4. #include "QR_Image.h"
  5. #include "QR_Encode.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CQR_ImageApp
  14. BEGIN_MESSAGE_MAP(CQR_ImageApp, CWinApp)
  15. //{{AFX_MSG_MAP(CQR_ImageApp)
  16. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  17. //}}AFX_MSG_MAP
  18. END_MESSAGE_MAP()
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CQR_ImageApp 级的初始化
  21. CQR_ImageApp::CQR_ImageApp()
  22. {
  23. }
  24. /////////////////////////////////////////////////////////////////////////////
  25. // 桞堦偺 CQR_ImageApp 僆僽僕僃僋僩
  26. CQR_ImageApp theApp;
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CQR_ImageApp 初始化
  29. BOOL CQR_ImageApp::InitInstance()
  30. {
  31. // OLE 初始化
  32. if (! AfxOleInit())
  33. return FALSE;
  34. // 内存泄漏查出用检查站设定(只调试时) //※ToolTip 关联的泄漏没有问题
  35. #ifdef _DEBUG
  36. mStart.Checkpoint();
  37. #endif //_DEBUG
  38. #if _MFC_VER <= 0x0600
  39. #ifdef _AFXDLL
  40. Enable3dControls();
  41. #else
  42. Enable3dControlsStatic();
  43. #endif
  44. #endif
  45. // 主要窗口作成
  46. CMainFrame* pFrame = new CMainFrame;
  47. m_pMainWnd = pFrame;
  48. // 由资源路框架
  49. pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW, NULL, NULL);
  50. // 应用图标组套
  51. HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  52. pFrame->SetIcon(hIcon, TRUE);
  53. // 主要窗表示,更新
  54. pFrame->ShowWindow(SW_SHOW);
  55. pFrame->UpdateWindow();
  56. return TRUE;
  57. }
  58. int CQR_ImageApp::ExitInstance()
  59. {
  60. // 内存泄漏信息表示(只调试时
  61. #ifdef _DEBUG
  62. mEnd.Checkpoint();
  63. if (mDiff.Difference(mStart, mEnd))
  64. {
  65. TRACE("\n-------- Detected memory leaks. DUMP(DumpStatistics) Start --------\n");
  66. mDiff.DumpStatistics();
  67. TRACE("-------- Detected memory leaks. DUMP(DumpStatistics) End --------\n");
  68. TRACE("\n-------- Detected memory leaks. DUMP(DumpAllObjectsSince) Start --------\n");
  69. mDiff.DumpAllObjectsSince();
  70. TRACE("-------- Detected memory leaks. DUMP(DumpAllObjectsSince) End --------\n\n");
  71. // AfxMessageBox("Detected memory leaks.", MB_OK | MB_ICONEXCLAMATION);
  72. }
  73. else
  74. {
  75. TRACE("\n-------- No detected memory leaks. OK !! --------\n\n");
  76. }
  77. #endif //_DEBUG
  78. return CWinApp::ExitInstance();
  79. }
  80. /////////////////////////////////////////////////////////////////////////////
  81. // 用应用的版本信息被使用的 CAboutDlg 对话框
  82. class CAboutDlg : public CDialog
  83. {
  84. public:
  85. CAboutDlg();
  86. HCURSOR m_hCurArrow, m_hCurWait, m_hCurHand;
  87. HFONT m_hFont; // URL/MailTo 表示字符串字体
  88. // 为了再绘画抑制的标志
  89. BOOL m_bPointOnUrl;
  90. BOOL m_bPointOnMailTo;
  91. // 为了对鼠标键押上时指令实行的标志
  92. BOOL m_bBtnDownUrl;
  93. BOOL m_bBtnDownMailTo;
  94. // 对话框数据
  95. //{{AFX_DATA(CAboutDlg)
  96. enum { IDD = IDD_ABOUTBOX };
  97. //}}AFX_DATA
  98. //{{AFX_VIRTUAL(CAboutDlg)
  99. protected:
  100. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 偺僒億乕僩
  101. //}}AFX_VIRTUAL
  102. // implementation
  103. protected:
  104. //{{AFX_MSG(CAboutDlg)
  105. virtual BOOL OnInitDialog();
  106. afx_msg void OnDestroy();
  107. afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
  108. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  109. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  110. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  111. //}}AFX_MSG
  112. DECLARE_MESSAGE_MAP()
  113. };
  114. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  115. {
  116. //{{AFX_DATA_INIT(CAboutDlg)
  117. //}}AFX_DATA_INIT
  118. }
  119. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  120. {
  121. CDialog::DoDataExchange(pDX);
  122. //{{AFX_DATA_MAP(CAboutDlg)
  123. //}}AFX_DATA_MAP
  124. }
  125. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  126. //{{AFX_MSG_MAP(CAboutDlg)
  127. ON_WM_DESTROY()
  128. ON_WM_CTLCOLOR()
  129. ON_WM_MOUSEMOVE()
  130. ON_WM_LBUTTONDOWN()
  131. ON_WM_LBUTTONUP()
  132. //}}AFX_MSG_MAP
  133. END_MESSAGE_MAP()
  134. //为了实行对话框的应用指令
  135. void CQR_ImageApp::OnAppAbout()
  136. {
  137. CAboutDlg aboutDlg;
  138. aboutDlg.DoModal();
  139. }
  140. BOOL CAboutDlg::OnInitDialog()
  141. {
  142. CDialog::OnInitDialog();
  143. m_hCurArrow = LoadCursor(NULL, IDC_ARROW);
  144. m_hCurWait = LoadCursor(NULL, IDC_WAIT);
  145. m_hCurHand = AfxGetApp()->LoadCursor(IDC_RHAND);
  146. m_bPointOnUrl = m_bPointOnMailTo = FALSE;
  147. m_bBtnDownUrl = m_bBtnDownMailTo = FALSE;
  148. // 字体作成(字下线补充)
  149. LOGFONT lf;
  150. lf.lfHeight = 12;
  151. lf.lfWidth = 0;
  152. lf.lfEscapement = 0;
  153. lf.lfOrientation = 0;
  154. lf.lfWeight = FW_DONTCARE;
  155. lf.lfItalic = FALSE;
  156. lf.lfUnderline = TRUE;
  157. lf.lfStrikeOut = FALSE;
  158. lf.lfCharSet = SHIFTJIS_CHARSET;
  159. lf.lfOutPrecision = CLIP_DEFAULT_PRECIS;
  160. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  161. lf.lfQuality = PROOF_QUALITY;
  162. lf.lfPitchAndFamily = DEFAULT_PITCH;
  163. lstrcpy(lf.lfFaceName, "宋体");
  164. m_hFont = CreateFontIndirect(&lf);
  165. GetDlgItem(IDC_STATICURL)->SendMessage(WM_SETFONT, (WPARAM)m_hFont, TRUE);
  166. GetDlgItem(IDC_STATICMAILTO)->SendMessage(WM_SETFONT, (WPARAM)m_hFont, TRUE);
  167. return TRUE;
  168. }
  169. void CAboutDlg::OnDestroy()
  170. {
  171. CDialog::OnDestroy();
  172. // 使用客观废弃
  173. DeleteObject(m_hFont);
  174. }
  175. HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  176. {
  177. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  178. int nID = pWnd->GetDlgCtrlID();
  179. if (nID == IDC_STATICURL)
  180. pDC->SetTextColor(m_bPointOnUrl ? RGB(255, 128, 0) : RGB(0, 0, 128));
  181. if (nID == IDC_STATICMAILTO)
  182. pDC->SetTextColor(m_bPointOnMailTo ? RGB(255, 128, 0) : RGB(0, 0, 128));
  183. return hbr;
  184. }
  185. void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point)
  186. {
  187. // 鼠标坐标位置检查
  188. ClientToScreen(&point);
  189. CRect rectUrl;
  190. GetDlgItem(IDC_STATICURL)->GetWindowRect(rectUrl);
  191. CRect rectMailTo;
  192. GetDlgItem(IDC_STATICMAILTO)->GetWindowRect(rectMailTo);
  193. // 光标变更
  194. SetCursor(rectUrl.PtInRect(point) || rectMailTo.PtInRect(point) ? m_hCurHand : m_hCurArrow);
  195. if (m_bPointOnUrl != rectUrl.PtInRect(point))
  196. {
  197. // URL 表示文本变色更
  198. GetDlgItem(IDC_STATICURL)->InvalidateRect(NULL);
  199. m_bPointOnUrl = rectUrl.PtInRect(point);
  200. if (m_bPointOnUrl)
  201. SetCapture();
  202. else
  203. ReleaseCapture();
  204. }
  205. if (m_bPointOnMailTo != rectMailTo.PtInRect(point))
  206. {
  207. // mailto 表示文本变色更
  208. GetDlgItem(IDC_STATICMAILTO)->InvalidateRect(NULL);
  209. m_bPointOnMailTo = rectMailTo.PtInRect(point);
  210. if (m_bPointOnMailTo)
  211. SetCapture();
  212. else
  213. ReleaseCapture();
  214. }
  215. CDialog::OnMouseMove(nFlags, point);
  216. }
  217. void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
  218. {
  219. // mailto 表示文书?颜色更
  220. ClientToScreen(&point);
  221. CRect rectUrl;
  222. GetDlgItem(IDC_STATICURL)->GetWindowRect(rectUrl);
  223. CRect rectMailTo;
  224. GetDlgItem(IDC_STATICMAILTO)->GetWindowRect(rectMailTo);
  225. // 光标变更
  226. SetCursor(rectUrl.PtInRect(point) || rectMailTo.PtInRect(point) ? m_hCurHand : m_hCurArrow);
  227. m_bBtnDownUrl = rectUrl.PtInRect(point);
  228. m_bBtnDownMailTo = rectMailTo.PtInRect(point);
  229. CDialog::OnLButtonDown(nFlags, point);
  230. }
  231. void CAboutDlg::OnLButtonUp(UINT nFlags, CPoint point)
  232. {
  233. if (m_bBtnDownUrl)
  234. {
  235. // 鼠标坐标位置检查
  236. ClientToScreen(&point);
  237. CRect rectUrl;
  238. GetDlgItem(IDC_STATICURL)->GetWindowRect(rectUrl);
  239. if (rectUrl.PtInRect(point))
  240. {
  241. SetCursor(m_hCurWait);
  242. // 浏览器启动
  243. ShellExecute(m_hWnd, "open", "http://www.lyfz.net", NULL, "", SW_SHOW);
  244. //考虑本对话框被遮住的情况绘画文本
  245. m_bPointOnUrl = FALSE;
  246. GetDlgItem(IDC_STATICURL)->InvalidateRect(NULL);
  247. SetCursor(m_hCurArrow);
  248. }
  249. m_bBtnDownUrl = FALSE;
  250. }
  251. else if (m_bBtnDownMailTo)
  252. {
  253. //鼠标坐标位置检查
  254. ClientToScreen(&point);
  255. CRect rectMailTo;
  256. GetDlgItem(IDC_STATICMAILTO)->GetWindowRect(rectMailTo);
  257. if (rectMailTo.PtInRect(point))
  258. {
  259. SetCursor(m_hCurWait);
  260. //mailer启动
  261. ShellExecute(m_hWnd, "open", "mailto:10000@qq.com", NULL, "", SW_SHOW);
  262. // 考虑本对话框被遮住的情况绘画文本
  263. m_bPointOnMailTo = FALSE;
  264. GetDlgItem(IDC_STATICMAILTO)->InvalidateRect(NULL);
  265. SetCursor(m_hCurArrow);
  266. }
  267. m_bBtnDownMailTo = FALSE;
  268. }
  269. CDialog::OnLButtonUp(nFlags, point);
  270. }