DLL clientDlg.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. // DLL clientDlg.cpp : implementation file
  2. //
  3. // Copyright 2002 Neil Van Eps
  4. //
  5. #include "stdafx.h"
  6. #include "DLL client.h"
  7. #include "DLL clientDlg.h"
  8. #include "exports.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16. class CAboutDlg : public CDialog
  17. {
  18. public:
  19. CAboutDlg();
  20. // Dialog Data
  21. //{{AFX_DATA(CAboutDlg)
  22. enum { IDD = IDD_ABOUTBOX };
  23. //}}AFX_DATA
  24. // ClassWizard generated virtual function overrides
  25. //{{AFX_VIRTUAL(CAboutDlg)
  26. protected:
  27. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  28. //}}AFX_VIRTUAL
  29. // Implementation
  30. protected:
  31. //{{AFX_MSG(CAboutDlg)
  32. //}}AFX_MSG
  33. DECLARE_MESSAGE_MAP()
  34. };
  35. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  36. {
  37. //{{AFX_DATA_INIT(CAboutDlg)
  38. //}}AFX_DATA_INIT
  39. }
  40. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CAboutDlg)
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  47. //{{AFX_MSG_MAP(CAboutDlg)
  48. // No message handlers
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CDLLclientDlg dialog
  53. CDLLclientDlg::CDLLclientDlg(CWnd* pParent /*=NULL*/)
  54. : CDialog(CDLLclientDlg::IDD, pParent)
  55. {
  56. //{{AFX_DATA_INIT(CDLLclientDlg)
  57. // NOTE: the ClassWizard will add member initialization here
  58. //}}AFX_DATA_INIT
  59. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  60. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  61. }
  62. void CDLLclientDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CDialog::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(CDLLclientDlg)
  66. DDX_Control(pDX, IDC_EDIT1, m_edtMessage);
  67. DDX_Control(pDX, IDC_COMBO1, m_cmbSymbology);
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(CDLLclientDlg, CDialog)
  71. //{{AFX_MSG_MAP(CDLLclientDlg)
  72. ON_WM_SYSCOMMAND()
  73. ON_WM_PAINT()
  74. ON_WM_QUERYDRAGICON()
  75. ON_BN_CLICKED(IDC_DRAW, OnDraw)
  76. ON_BN_CLICKED(IDC_CLIPBOARD, OnClipboard)
  77. ON_BN_CLICKED(IDC_PRINT, OnPrintButton)
  78. //}}AFX_MSG_MAP
  79. END_MESSAGE_MAP()
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CDLLclientDlg message handlers
  82. BOOL CDLLclientDlg::OnInitDialog()
  83. {
  84. CDialog::OnInitDialog();
  85. // Add "About..." menu item to system menu.
  86. // IDM_ABOUTBOX must be in the system command range.
  87. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  88. ASSERT(IDM_ABOUTBOX < 0xF000);
  89. CMenu* pSysMenu = GetSystemMenu(FALSE);
  90. if (pSysMenu != NULL)
  91. {
  92. CString strAboutMenu;
  93. strAboutMenu.LoadString(IDS_ABOUTBOX);
  94. if (!strAboutMenu.IsEmpty())
  95. {
  96. pSysMenu->AppendMenu(MF_SEPARATOR);
  97. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  98. }
  99. }
  100. // Set the icon for this dialog. The framework does this automatically
  101. // when the application's main window is not a dialog
  102. SetIcon(m_hIcon, TRUE); // Set big icon
  103. SetIcon(m_hIcon, FALSE); // Set small icon
  104. // TODO: Add extra initialization here
  105. // select the first symbology as a default
  106. m_cmbSymbology.SetCurSel(0);
  107. m_nStartingXPixel = 20;
  108. m_nStartingYPixel = 320;
  109. m_dHeight = 0.5;
  110. m_dNarrowBar = 0.012;
  111. m_dRatio = 3.0;
  112. return TRUE; // return TRUE unless you set the focus to a control
  113. }
  114. void CDLLclientDlg::OnSysCommand(UINT nID, LPARAM lParam)
  115. {
  116. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  117. {
  118. CAboutDlg dlgAbout;
  119. dlgAbout.DoModal();
  120. }
  121. else
  122. {
  123. CDialog::OnSysCommand(nID, lParam);
  124. }
  125. }
  126. // If you add a minimize button to your dialog, you will need the code below
  127. // to draw the icon. For MFC applications using the document/view model,
  128. // this is automatically done for you by the framework.
  129. void CDLLclientDlg::OnPaint()
  130. {
  131. if (IsIconic())
  132. {
  133. CPaintDC dc(this); // device context for painting
  134. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  135. // Center icon in client rectangle
  136. int cxIcon = GetSystemMetrics(SM_CXICON);
  137. int cyIcon = GetSystemMetrics(SM_CYICON);
  138. CRect rect;
  139. GetClientRect(&rect);
  140. int x = (rect.Width() - cxIcon + 1) / 2;
  141. int y = (rect.Height() - cyIcon + 1) / 2;
  142. // Draw the icon
  143. dc.DrawIcon(x, y, m_hIcon);
  144. }
  145. else
  146. {
  147. CDialog::OnPaint();
  148. }
  149. }
  150. // The system calls this to obtain the cursor to display while the user drags
  151. // the minimized window.
  152. HCURSOR CDLLclientDlg::OnQueryDragIcon()
  153. {
  154. return (HCURSOR) m_hIcon;
  155. }
  156. ////////////////////////////////////////////////////////////////////////////////////
  157. //
  158. // Name:
  159. //
  160. //
  161. // Description:
  162. //
  163. //
  164. // Arguments:
  165. //
  166. //
  167. // Return:
  168. //
  169. //
  170. // Called by:
  171. //
  172. //
  173. ////////////////////////////////////////////////////////////////////////////////////
  174. void CDLLclientDlg::OnDraw()
  175. {
  176. CString csMessage;
  177. long nSymbology;
  178. nSymbology = GetSymbology();
  179. m_edtMessage.GetWindowText(csMessage);
  180. ClearOldBarcode();
  181. switch (nSymbology)
  182. {
  183. case COD128:
  184. DrawCode128Barcode(csMessage,m_dHeight,m_dNarrowBar,::GetWindowDC(this->GetSafeHwnd()),m_nStartingXPixel,m_nStartingYPixel,0);
  185. break;
  186. case CODE39:
  187. DrawCode39Barcode(csMessage,m_dHeight,m_dNarrowBar,::GetWindowDC(this->GetSafeHwnd()),m_nStartingXPixel,m_nStartingYPixel,m_dRatio);
  188. break;
  189. case CODE93:
  190. DrawCode93Barcode(csMessage,m_dHeight,m_dNarrowBar,::GetWindowDC(this->GetSafeHwnd()),m_nStartingXPixel,m_nStartingYPixel);
  191. break;
  192. case I2OF5:
  193. DrawI2of5Barcode(csMessage,m_dHeight,m_dNarrowBar,::GetWindowDC(this->GetSafeHwnd()),m_nStartingXPixel,m_nStartingYPixel,m_dRatio);
  194. break;
  195. case RATIONALCODABAR:
  196. DrawRationalCodabarBarcode(csMessage,m_dHeight,m_dNarrowBar,::GetWindowDC(this->GetSafeHwnd()),m_nStartingXPixel,m_nStartingYPixel,m_dRatio);
  197. break;
  198. }
  199. return;
  200. }
  201. ////////////////////////////////////////////////////////////////////////////////////
  202. //
  203. // Name:
  204. //
  205. //
  206. // Description:
  207. //
  208. //
  209. // Arguments:
  210. //
  211. //
  212. // Return:
  213. //
  214. //
  215. // Called by:
  216. //
  217. //
  218. ////////////////////////////////////////////////////////////////////////////////////
  219. void CDLLclientDlg::OnClipboard()
  220. {
  221. CString csMessage;
  222. long nSymbology;
  223. nSymbology = GetSymbology();
  224. m_edtMessage.GetWindowText(csMessage);
  225. ClearOldBarcode();
  226. switch (nSymbology)
  227. {
  228. case COD128:
  229. Code128BarcodeToClipboard(csMessage,m_dHeight,m_dNarrowBar,0);
  230. break;
  231. case CODE39:
  232. Code39BarcodeToClipboard(csMessage,m_dHeight,m_dNarrowBar,m_dRatio);
  233. break;
  234. case CODE93:
  235. Code93BarcodeToClipboard(csMessage,m_dHeight,m_dNarrowBar);
  236. break;
  237. case I2OF5:
  238. I2of5BarcodeToClipboard(csMessage,m_dHeight,m_dNarrowBar,m_dRatio);
  239. break;
  240. case RATIONALCODABAR:
  241. RationalCodabarBarcodeToClipboard(csMessage,m_dHeight,m_dNarrowBar,m_dRatio);
  242. break;
  243. }
  244. return;
  245. }
  246. ////////////////////////////////////////////////////////////////////////////////////
  247. //
  248. // Name:
  249. //
  250. //
  251. // Description:
  252. //
  253. //
  254. // Arguments:
  255. //
  256. //
  257. // Return:
  258. //
  259. //
  260. // Called by:
  261. //
  262. //
  263. ////////////////////////////////////////////////////////////////////////////////////
  264. void CDLLclientDlg::ClearOldBarcode()
  265. {
  266. CDC oDC;
  267. CBrush oBrush,oOldBrush;
  268. CBrush *pBrush = NULL;
  269. int nEndingXPixel,nEndingYPixel;
  270. // create rect to fill
  271. nEndingXPixel = m_nStartingXPixel + 230;
  272. nEndingYPixel = m_nStartingYPixel + 48;
  273. CRect oRect(m_nStartingXPixel,m_nStartingYPixel,nEndingXPixel,nEndingYPixel);
  274. // attach the DC object to this window's DC
  275. oDC.Attach(::GetWindowDC(this->GetSafeHwnd()));
  276. // create our brush
  277. pBrush = (CBrush *)oDC.SelectStockObject(LTGRAY_BRUSH);
  278. oBrush.FromHandle((HBRUSH)pBrush);
  279. // select our brush, saving handle to old brush
  280. pBrush = oDC.SelectObject(&oBrush);
  281. // save the old brush
  282. oOldBrush.FromHandle((HBRUSH)pBrush);
  283. // fill our rect
  284. oDC.FillRect((LPCRECT)&oRect,&oBrush);
  285. // reselect saved brush
  286. oDC.SelectObject(&oOldBrush);
  287. // detach object from window DC
  288. oDC.Detach();
  289. return;
  290. }
  291. ////////////////////////////////////////////////////////////////////////////////////
  292. //
  293. // Name:
  294. //
  295. //
  296. // Description:
  297. //
  298. //
  299. // Arguments:
  300. //
  301. //
  302. // Return:
  303. //
  304. //
  305. // Called by:
  306. //
  307. //
  308. ////////////////////////////////////////////////////////////////////////////////////
  309. long CDLLclientDlg::GetSymbology()
  310. {
  311. CString csControlText;
  312. long nReturnSymbology=0;
  313. m_cmbSymbology.GetWindowText(csControlText);
  314. if (csControlText=="Code 39")
  315. nReturnSymbology = CODE39;
  316. else if (csControlText=="Rational Codabar")
  317. nReturnSymbology = RATIONALCODABAR;
  318. else if (csControlText=="I2of5")
  319. nReturnSymbology = I2OF5;
  320. else if (csControlText=="Code 128")
  321. nReturnSymbology = COD128;
  322. else if (csControlText=="Code 93")
  323. nReturnSymbology = CODE93;
  324. return nReturnSymbology;
  325. }
  326. ////////////////////////////////////////////////////////////////////////////////////
  327. //
  328. // Name:
  329. //
  330. //
  331. // Description:
  332. //
  333. //
  334. // Arguments:
  335. //
  336. //
  337. // Return:
  338. //
  339. //
  340. // Called by:
  341. //
  342. //
  343. ////////////////////////////////////////////////////////////////////////////////////
  344. void CDLLclientDlg::OnPrintButton()
  345. {
  346. AfxMessageBox("Printing not implemented!");
  347. return;
  348. }