// ZDlg.cpp : implementation file // #include "stdafx.h" #include "BarCode.h" #include "ZDlg.h" #include "Printkernel.h" #include "Help.h" #include #pragma comment(lib, "Imm32.lib") #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// ZDlg::ZDlg(CWnd* pParent /*=NULL*/) : CDialog(ZDlg::IDD, pParent) { //{{AFX_DATA_INIT(ZDlg) //}}AFX_DATA_INIT } ZDlg::~ZDlg() { } void ZDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ZDlg) DDX_Control(pDX, BTN_PRINT, btn_Menu); DDX_Control(pDX, ED_MOVE, ed_Move); DDX_Control(pDX, ED_PRINTY, ed_PrintY); DDX_Control(pDX, ED_PRINTX, ed_PrintX); DDX_Control(pDX, ED_PRINTH, ed_PrintH); DDX_Control(pDX, ED_PENW, ed_PenW); DDX_Control(pDX, CMB_STYLE, cmb_Style); DDX_Control(pDX, BTN_ONTOP, btn_OnTop); DDX_Control(pDX, CMB_MAPMODE, cmb_MapMode); DDX_Control(pDX, ED_CODE, ed_Code); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(ZDlg, CDialog) //{{AFX_MSG_MAP(ZDlg) ON_WM_PAINT() ON_BN_CLICKED(IDOK, On_IDOK) ON_BN_CLICKED(BTN_HELP, On_BtnHelp) ON_WM_DESTROY() ON_BN_CLICKED(BTN_CLOSE, On_BtnClose) ON_WM_LBUTTONDOWN() ON_BN_CLICKED(BTN_ONTOP, On_BtnOnTop) ON_CBN_SELCHANGE(CMB_STYLE, On_CmbStyleSelChange) ON_CBN_SELCHANGE(CMB_MAPMODE, On_CmbMapModeSelChange) ON_BN_CLICKED(BTN_PRINT, On_BtnPrint) ON_EN_CHANGE(ED_CODE, On_EdCodeChange) ON_EN_CHANGE(ED_PENW, On_EdPenWidthChange) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ZDlg message handlers void ZDlg::On_IDOK() { } void ZDlg::On_BtnClose() { OnCancel(); } void ZDlg::OnLButtonDown(UINT nFlags, CPoint point) { CDialog::OnLButtonDown(nFlags, point); SendMessage(WM_NCLBUTTONDOWN,HTCAPTION); } void ZDlg::On_BtnOnTop() { CString cs; btn_OnTop.GetWindowText(cs); if(cs.CompareNoCase("OnTop")==0) btn_OnTop.SetWindowText("OnNormal"); else btn_OnTop.SetWindowText("OnTop"); P_SetOnTop(); } void ZDlg::P_SetOnTop() { CString cs; btn_OnTop.GetWindowText(cs); HWND hWnd=HWND_NOTOPMOST; if(cs.CompareNoCase("OnTop")!=0) hWnd=HWND_TOPMOST; ::SetWindowPos(m_hWnd,hWnd,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); } void ZDlg::OnDestroy() { CDialog::OnDestroy(); } int ZDlg::P_AddOrGet(CComboBox &box, BOOL bAdd) { struct IntString { int iV; char*psz; }; IntString ps[]= { {MM_TEXT, "MM_TEXT"}, {MM_LOENGLISH, "MM_LOENGLISH"}, {MM_HIENGLISH, "MM_HIENGLISH"}, {MM_LOMETRIC, "MM_LOMETRIC"}, {MM_TWIPS, "MM_TWIPS"}, }; int i,iNum=sizeof(ps)/sizeof(ps[0]); if(bAdd==0) { i=box.GetCurSel(); if((i<0)||(i>=iNum)) return ps[0].iV; return ps[i].iV; } for(i=0;iSetMapMode(P_AddOrGet(cmb_MapMode,0)); { CRect rcT; if(bPrint) { rcT.left =Help::GetValue(ed_PrintX); rcT.top =Help::GetValue(ed_PrintY); rcT.bottom =rcT.top+Help::GetValue(ed_PrintH); //temp, useless value rcT.right=rcT.left+100; } else { GetWindowRect(&rcT); ::MapWindowPoints(0,m_hWnd,(POINT*)&rcT,2); rcT.left+=4; rcT.bottom+=30; } pDC->DPtoLP(&rcT); iL=rcT.left + 20; iT=rcT.top - 80; iB=rcT.bottom + 80; } //-------------------------------------------- int iPenW=Help::GetValue(ed_PenW); if(iPenW==0) iPenW=1; CString csStyle; cmb_Style.GetWindowText(csStyle); CString csCode; ed_Code.GetWindowText(csCode); COLORREF clrBar =RGB(0,0,0); COLORREF clrSpace =RGB(255,255,255); if(bPrint) { pDC->StartDoc("Hello"); pDC->StartPage(); } if(csStyle.CompareNoCase("Code39")==0) { Barcode39 code; code.Encode39(csCode); P_DrawBarcode(pDC,iL,iT,iB-10,iB,clrBar,clrSpace,iPenW,&code); } else if(csStyle.CompareNoCase("Code93")==0) { Barcode93 code; code.Encode93(csCode); P_DrawBarcode(pDC,iL,iT,iB-10,iB,clrBar,clrSpace,iPenW,&code); } else if(csStyle.CompareNoCase("CodeI2of5")==0) { BarcodeI2of5 code; code.EncodeI2of5(csCode); P_DrawBarcode(pDC,iL,iT,iB-10,iB,clrBar,clrSpace,iPenW,&code); } else if(csStyle.CompareNoCase("Code128A")==0) { Barcode128 code; code.Encode128A(csCode); P_DrawBarcode(pDC,iL,iT,iB-10,iB,clrBar,clrSpace,iPenW,&code); } else if(csStyle.CompareNoCase("Code128B")==0) { Barcode128 code; code.Encode128B(csCode); P_DrawBarcode(pDC,iL,iT,iB-10,iB,clrBar,clrSpace,iPenW,&code); } else if(csStyle.CompareNoCase("Code128C")==0) { Barcode128 code; code.Encode128C(csCode); P_DrawBarcode(pDC,iL,iT,iB-10,iB,clrBar,clrSpace,iPenW,&code); } else if(csStyle.CompareNoCase("CodeEan13")==0) { BarcodeEan13 code; code.EncodeEan13(csCode); P_DrawBarcode(pDC,iL,iT,iB-10,iB,clrBar,clrSpace,iPenW,&code); } if(bPrint) { pDC->EndPage(); pDC->EndDoc(); } pDC->SetMapMode(iMapMode); } void ZDlg::P_DrawBarcode(CDC*pDC,int iX,int iY0,int iY10,int iY11,COLORREF clrBar,COLORREF clrSpace,int iPenW,BarcodeBase*pBc) { pBc->DrawBarcode(pDC->m_hDC,iX,iY0,iY10,iY11,clrBar,clrSpace,iPenW); } LRESULT ZDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { CRect rc; if(message==WM_USER) { GetWindowRect(&rc); rc.left+=wParam; rc.right+=wParam; MoveWindow(&rc); } else if(message==WM_USER+1) { GetWindowRect(&rc); rc.top+=wParam; rc.bottom+=wParam; MoveWindow(&rc); } return CDialog::WindowProc(message, wParam, lParam); }