/*-----------------------------------------
SINEWAVE.C -- Sine Wave Using Polyline
(c) Charles Petzold, 1998
-----------------------------------------*/
#include <windows.h>
#include <math.h>
/*****************Code128A******************/
/*ASCII码从32开始*/
unsigned char Code128[] =
{
"11011001100"
"11001101100"
"11001100110"
"10010011000"
"10010001100"
"10001001100"
"10011001000"
"10011000100"
"10001100100"
"11001001000"
"11001000100"
"11000100100"
"10110011100"
"10011011100"
"10011001110"
"10111001100"
"10011101100"
"10011100110"
"11001110010"
"11001011100"
"11001001110"
"11011100100"
"11001110100"
"11101101110"
"11101001100"
"11100101100"
"11100100110"
"11101100100"
"11100110100"
"11100110010"
"11011011000"
"11011000110"
"11000110110"
"10100011000"
"10001011000"
"10001000110"
"10110001000"
"10001101000"
"10001100010"
"11010001000"
"11000101000"
"11000100010"
"10110111000"
"10110001110"
"10001101110"
"10111011000"
"10111000110"
"10001110110"
"11101110110"
"11010001110"
"11000101110"
"11011101000"
"11011100010"
"11011101110"
"11101011000"
"11101000110"
"11100010110"
"11101101000"
"11101100010"
"11100011010"
"11101111010"
"11001000010"
"11110001010"
"10100110000"
"10100001100"
"10010110000"
"10010000110"
"10000101100"
"10000100110"
"10110010000"
"10110000100"
"10011010000"
"10011000010"
"10000110100"
"10000110010"
"11000010010"
"11001010000"
"11110111010"
"11000010100"
"10001111010"
"10100111100"
"10010111100"
"10010011110"
"10111100100"
"10011110100"
"10011110010"
"11110100100"
"11110010100"
"11110010010"
"11011011110"
"11011110110"
"11110110110"
"10101111000"
"10100011110"
"10001011110"
"10111101000"
"10111100010"
"11110101000"
"11110100010"
"10111011110"
"10111101110"
"11101011110"
"11110101110"
"11010000100"
"11010010000"
"11010011100"
"1100011101011"
};
#define NUM 30000
#define TWOPI (2 * 3.14159)
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SineWave") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Sine Wave Using Polyline"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
unsigned char GetBarCode128ID(unsigned char ASCIICode)
{
return ASCIICode-32;
}
void GetBarCode(unsigned char DataID,unsigned char *Decode)
{
int i;
if(DataID==106)
{
for(i=0;i<13;i++)
Decode[i]=Code128[11*DataID+i];
}
else
{
for(i=0;i<11;i++)
Decode[i]=Code128[11*DataID+i];
}
}
void BarCodeFillBuffer(HDC hdc ,int X,int Y,int Length,unsigned char *Buffer)
{
long i,k,z;
unsigned char Temp,j;
unsigned char BUF[20];
long SUM;
int CountSum;
int CheckID;
unsigned char n;
long CountTest=0;
long WritePP=0;
int XLocation=0;
int GAP=4;
XLocation=X/6;
//for(j=0;j<20;j++)
{
SUM=0;
SUM=SUM+103;
CountSum=1;
/*StartB*/
GetBarCode(103,BUF);
WritePP=0;
for(n=0;n<11;n++)
{
if(BUF[n]=='1')
{
CountTest++;
for(k=XLocation;k<XLocation+GAP;k++)
{
MoveToEx (hdc, k,Y / 4, NULL) ;
LineTo (hdc, k, Y *3/ 4) ;
}
}
XLocation+=GAP;
}
/*填入条码数据*/
for(i=0;i<Length;i++)
{
Temp=GetBarCode128ID(Buffer[i]);
SUM+=Temp*CountSum++;
GetBarCode(Temp,BUF);
WritePP=0;
for(n=0;n<11;n++)
{
if(BUF[n]=='1')
{
CountTest++;
Temp=0xff;
for(k=XLocation;k<XLocation+GAP;k++)
{
MoveToEx (hdc, k,Y / 4, NULL) ;
LineTo (hdc, k, Y *3/ 4) ;
}
}
else
{
Temp=0;
}
XLocation+=GAP;
}
}
/*填入校验位*/
CheckID=(SUM%103);
GetBarCode((unsigned char)CheckID,BUF);
WritePP=0;
for(n=0;n<11;n++)
{
if(BUF[n]=='1')
{
CountTest++;
Temp=0xff;
for(k=XLocation;k<XLocation+GAP;k++)
{
MoveToEx (hdc, k,Y / 4, NULL) ;
LineTo (hdc, k, Y *3/ 4) ;
}
}
else
{
Temp=0;
}
XLocation+=GAP;
}
/*填入结束字符*/
WritePP=0;
GetBarCode(106,BUF);
for(n=0;n<13;n++)
{
if(BUF[n]=='1')
{
CountTest++;
Temp=0xff;
for(k=XLocation;k<XLocation+GAP;k++)
{
MoveToEx (hdc, k,Y / 4, NULL);
LineTo (hdc, k, Y *3/ 4);
}
}
else
{
Temp=0;
}
XLocation+=GAP;
}
}
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient ;
HDC hdc ;
PAINTSTRUCT ps ;
POINT apt [NUM] ;
unsigned char TiaoMa[]="ABCDE";
switch (message)
{
case WM_SIZE:
/*你的代码是获取宽和高并保存起来*/
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
BarCodeFillBuffer(hdc,cxClient,cyClient,strlen(TiaoMa),TiaoMa);
/*
MoveToEx (hdc, 0,cyClient / 2, NULL) ;
LineTo (hdc, cxClient, cyClient / 2) ;
MoveToEx (hdc, cxClient/2,0, NULL) ;
LineTo (hdc, cxClient/2, cyClient ) ;
{
for (i = 0 ; i < NUM ; i++)
{
apt[i].x = i * cxClient / NUM ;
apt[i].y = (int) (cyClient / 2 - pow((cxClient/2- i * cxClient / NUM),2)/100) ;
}
Polyline (hdc, apt, NUM) ;
}
for(j=1;j<3;j++)
{
for (i = 0 ; i < NUM ; i++)
{
apt[i].x = i * cxClient / NUM ;
apt[i].y = (int) (cyClient / 2 * (1 - cos(TWOPI * i *j/ NUM))) ;
}
Polyline (hdc, apt, NUM) ;
}
*/
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
- 1
- 2
- 3
前往页