EANDlg.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // EANDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "EAN.h"
  5. #include "EANDlg.h"
  6. #include "EAN13.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CEANDlg dialog
  51. CEANDlg::CEANDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CEANDlg::IDD, pParent)
  53. {
  54. //{{AFX_DATA_INIT(CEANDlg)
  55. //}}AFX_DATA_INIT
  56. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  57. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  58. }
  59. void CEANDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CEANDlg)
  63. DDX_Control(pDX, IDC_COMBO_RATIO, m_cbRatio);
  64. DDX_Control(pDX, IDC_EDIT_CHECKDIGIT, m_editCheckDigit);
  65. DDX_Control(pDX, IDC_EDIT_PRODUCT, m_editProduct);
  66. DDX_Control(pDX, IDC_EDIT_MANUFACTURER, m_editManufacturer);
  67. DDX_Control(pDX, IDC_EDIT_HEIGHT, m_editHeight);
  68. DDX_Control(pDX, IDC_EDIT_GUARDBAR, m_editGuardbarHeight);
  69. DDX_Control(pDX, IDC_EDIT_COUNTRYCODE, m_editCountryCode);
  70. DDX_Control(pDX, IDC_COMBO_SYMBOLOGY, m_cbSymbology);
  71. DDX_Control(pDX, IDC_BITMAPBARCODE, m_staticBitmapBarcode);
  72. //}}AFX_DATA_MAP
  73. }
  74. BEGIN_MESSAGE_MAP(CEANDlg, CDialog)
  75. //{{AFX_MSG_MAP(CEANDlg)
  76. ON_WM_SYSCOMMAND()
  77. ON_WM_PAINT()
  78. ON_WM_QUERYDRAGICON()
  79. ON_BN_CLICKED(IDC_BUTTON_DRAW, OnButtonDraw)
  80. //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CEANDlg message handlers
  84. BOOL CEANDlg::OnInitDialog()
  85. {
  86. CDialog::OnInitDialog();
  87. // Add "About..." menu item to system menu.
  88. // IDM_ABOUTBOX must be in the system command range.
  89. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  90. ASSERT(IDM_ABOUTBOX < 0xF000);
  91. CMenu* pSysMenu = GetSystemMenu(FALSE);
  92. if (pSysMenu != NULL)
  93. {
  94. CString strAboutMenu;
  95. strAboutMenu.LoadString(IDS_ABOUTBOX);
  96. if (!strAboutMenu.IsEmpty())
  97. {
  98. pSysMenu->AppendMenu(MF_SEPARATOR);
  99. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  100. }
  101. }
  102. // Set the icon for this dialog. The framework does this automatically
  103. // when the application's main window is not a dialog
  104. SetIcon(m_hIcon, TRUE); // Set big icon
  105. SetIcon(m_hIcon, FALSE); // Set small icon
  106. // TODO: Add extra initialization here
  107. m_cbSymbology.SetCurSel(0);
  108. m_cbRatio.SetCurSel(m_cbRatio.GetCurSel());
  109. m_editCountryCode.SetWindowText("75");
  110. m_editManufacturer.SetWindowText("12345");
  111. m_editProduct.SetWindowText("67890");
  112. m_editHeight.SetWindowText("1.5");
  113. m_editGuardbarHeight.SetWindowText("20");
  114. return TRUE; // return TRUE unless you set the focus to a control
  115. }
  116. void CEANDlg::OnSysCommand(UINT nID, LPARAM lParam)
  117. {
  118. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  119. {
  120. CAboutDlg dlgAbout;
  121. dlgAbout.DoModal();
  122. }
  123. else
  124. {
  125. CDialog::OnSysCommand(nID, lParam);
  126. }
  127. }
  128. // If you add a minimize button to your dialog, you will need the code below
  129. // to draw the icon. For MFC applications using the document/view model,
  130. // this is automatically done for you by the framework.
  131. void CEANDlg::OnPaint()
  132. {
  133. if (IsIconic())
  134. {
  135. CPaintDC dc(this); // device context for painting
  136. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  137. // Center icon in client rectangle
  138. int cxIcon = GetSystemMetrics(SM_CXICON);
  139. int cyIcon = GetSystemMetrics(SM_CYICON);
  140. CRect rect;
  141. GetClientRect(&rect);
  142. int x = (rect.Width() - cxIcon + 1) / 2;
  143. int y = (rect.Height() - cyIcon + 1) / 2;
  144. // Draw the icon
  145. dc.DrawIcon(x, y, m_hIcon);
  146. }
  147. else
  148. {
  149. CDialog::OnPaint();
  150. }
  151. }
  152. // The system calls this to obtain the cursor to display while the user drags
  153. // the minimized window.
  154. HCURSOR CEANDlg::OnQueryDragIcon()
  155. {
  156. return (HCURSOR) m_hIcon;
  157. }
  158. void CEANDlg::OnButtonDraw()
  159. {
  160. // TODO: Add your control notification handler code here
  161. CEAN13 CodeEAN13;
  162. CString strMessage, strTemp;
  163. strMessage.Empty();
  164. m_editCountryCode.GetWindowText(strTemp);
  165. strMessage += strTemp;
  166. m_editManufacturer.GetWindowText(strTemp);
  167. strMessage += strTemp;
  168. m_editProduct.GetWindowText(strTemp);
  169. strMessage += strTemp;
  170. m_editHeight.GetWindowText(strTemp);
  171. double dHeight = atof(strTemp);
  172. m_editGuardbarHeight.GetWindowText(strTemp);
  173. long nGuardbarHeight = atol(strTemp);
  174. m_cbRatio.GetWindowText(strTemp);
  175. double dRatio = atof(strTemp);
  176. HDC hDC = m_staticBitmapBarcode.GetDC()->m_hDC;
  177. CodeEAN13.LoadData(strMessage,0.02,dHeight,nGuardbarHeight,hDC,0,0,dRatio);
  178. CodeEAN13.DrawBitmap();
  179. strTemp.Format("%d",CodeEAN13.CalculateCheckSumDigit());
  180. m_editCheckDigit.SetWindowText(strTemp);
  181. }