📄 code39.cpp
字号:
//YiCode.cpp
#include <afxwin.h>
//#include <io.h>
//bool LoadFile();
//int _stdcall WriteZPL();
char *lpszDriverName=new char;
char *lpszDeviceName=new char;
char *lpszPortName=new char;
HHOOK hhk;
char achBuffer[256];
CString m_buf;
char buf[256];
int length=0;
int i=0;
bool LoadDeviceInfo();
int __stdcall MakeCode(char *,char *);
char * __stdcall ReadCode();
bool WINAPI DllEntryPoint(HINSTANCE hDll,DWORD dwReason,LPVOID Reserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
bool LoadDeviceInfo()
{
int devLength=0;
int drvLength=0;
int portLength=0;
char lpBuffer[80];
char *lpTemp;
char *lpTemp1;
char *lpTemp2;
GetProfileString("windows","device","",lpBuffer,sizeof(lpBuffer));
lpTemp=lpBuffer;
//get the lpDeviceName parameter--printer Device name
while(*lpTemp==' ')
{
lpTemp=CharNext(lpTemp);
}
while(*lpTemp!=',')
{
lpTemp=CharNext(lpTemp);
devLength++;
}
for(int ii=0;ii<devLength;ii++)
{
*(lpszDeviceName+ii)=*(lpBuffer+ii);
}
*(lpszDeviceName+ii)='\0';
//get lpDriveName parameter--get drive program
lpTemp1=CharNext(lpTemp);
while(*lpTemp==' '|| *lpTemp==',')
{
lpTemp=CharNext(lpTemp);
}
while(*lpTemp!=',' && *lpTemp!=' ')
{
lpTemp=CharNext(lpTemp);
drvLength++;
}
for(int j=0;j<drvLength;j++)
{
*(lpszDriverName+j)=*(lpTemp1+j);
}
*(lpszDriverName+j)='\0';
// ::MessageBox(NULL,lpszDriverName,"text",MB_OK);
//get printer parameter lpszPortName
lpTemp2=CharNext(lpTemp);
while(*lpTemp==' '|| *lpTemp==',')
{
lpTemp=CharNext(lpTemp);
}
while(*lpTemp!=',' && *lpTemp!=' ' &&*lpTemp!='\n'&& *lpTemp!='\0')
{
lpTemp=CharNext(lpTemp);
portLength++;
}
for(int jj=0;jj<portLength;jj++)
{
*(lpszPortName+jj)=*(lpTemp2+jj);
}
*(lpszPortName+jj)='\0';
// delete lpTemp2;
/// delete lpTemp1;
// delete lpTemp;
return true;
}
LRESULT CALLBACK LevelProc(int code,WPARAM wParam,LPARAM lParam)
{
if(code==HC_ACTION)
{
// char str[80];
char szKeyName[256];
// ::GetKeyNameText(lParam,&szKeyName[0],sizeof(szKeyName)-1);
// i=i+1;
if(wParam!=13)
{
::GetKeyNameText(lParam,&szKeyName[0],sizeof(szKeyName)-1);
strcat(buf,szKeyName);
length++;
CallNextHookEx(hhk,code,wParam,lParam);
}
else
{
CString m_strbuf;
m_strbuf.Format("%s",buf);
while(i<length)
{
m_strbuf.Mid(i,1);
m_buf+=m_strbuf.Mid(i,1);
i+=2;
}
// ::MessageBox(NULL,m_buf,"caption",MB_OK);
}
}
return CallNextHookEx(hhk,code,wParam,lParam);
}
int __stdcall MakeCode(char *param1,char *param2) //param from application's param
{
// FILE *zplFile,*zplFile1;
//int fp;
DOCINFO DocInfo;
int sStatus;
if(!LoadDeviceInfo())
{
::MessageBox(NULL,"no find device infomation","Device Info",MB_OK);
}
CDC PrintDC;
if(!PrintDC.CreateDC(lpszDriverName,lpszDeviceName,lpszPortName,NULL))
{
::MessageBox(NULL,"create CDC Device Failed","Create CDC-Device",MB_OK);
}
else
{
DocInfo.cbSize=sizeof(DocInfo);
// DocInfo.lpszDocName="zplfile.zpl";
DocInfo.lpszOutput=NULL; //output to device
sStatus=PrintDC.StartDoc(&DocInfo);
if(sStatus<=0)
{
::MessageBox(NULL,"Start Printer Doc failed","Start Doc",NULL);
}
PrintDC.StartPage();
{
// PrintDC.TextOut(20,50,param2);
PrintDC.SetMapMode(MM_TEXT);
//PrintDC.SetMapMode(MM_LOENGLISH);
CFont *yFont=new CFont;
//PrintDC.TextOut(10,170,param3);
CFont *yFont1=new CFont;
CFont *pOldFont;
int falg=yFont1->CreateFont(110,0,GM_COMPATIBLE,
GM_COMPATIBLE,FW_LIGHT,false
,false,false, SYMBOL_CHARSET,OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,PROOF_QUALITY,DEFAULT_PITCH,
"Zebra-Code 3-of-9 (12mils)");
//Zebra-Code 3-of-9 (0.5mm)
pOldFont=PrintDC.SelectObject(yFont1);
PrintDC.TextOut(40,30,param1);
PrintDC.SelectObject(pOldFont);
delete yFont1;
// yFont->CreateFontIndirect(&myFont);
yFont->CreateFont(0,0,GM_COMPATIBLE,
GM_COMPATIBLE,FW_NORMAL,false
,false,false,ANSI_CHARSET,OUT_DEVICE_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,
"楷体_GB2312");
pOldFont=PrintDC.SelectObject(yFont1);
PrintDC.TextOut(45,145,param2);
PrintDC.SelectObject(pOldFont);
// delete yFont1;
// delete yFont;
/* int length=100;
fgets(lpOutBuf,length,zplFile1);
PrintDC.TextOut(rect.left,rect.top,lpOutBuf);*/
//GetDeviceCaps(
}
PrintDC.EndPage();
PrintDC.EndDoc();//if success return value>=0
PrintDC.DeleteDC();
// fclose(zplFile1);
//::OpenPrinter();
}
// CopyFile("zplfile.zpl","LPT1:",false);
return true;
}
char * __stdcall ReadCode()
{
char *string=new char;
/* HWND hwnd=CreateWindow("STATIC","GetBuffer",
WS_OVERLAPPED,
200,105,400,160,
NULL,NULL,NULL,NULL);
::ShowWindow(hwnd,SW_SHOW);
::UpdateWindow(hwnd);
CString buf1;
HWND hEdit=::CreateWindow("EDIT",buf1,WS_CHILD|WS_VISIBLE,
1,3,180,30,
hwnd,NULL,NULL,NULL);
::ShowWindow(hEdit,SW_SHOW);
::UpdateWindow(hEdit);
::SetFocus(hEdit);*/
::SetWindowsHookEx(WH_KEYBOARD,LevelProc,NULL,GetCurrentThreadId());
::UnhookWindowsHookEx(hhk);
strcpy(string,m_buf);
//::DestroyWindow(hEdit);
//::DestroyWindow(hwnd);
return string;
delete string;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -