Code 128 Mode C) print MFC

Source: Internet
Author: User

 

 

Header file code128c. h

/*************************************** ************************
* Name: code128c. h
* Function: print the C code in code128 mode.
* Programmed: ming_zhang
* Date (org): August 24 2011
* Project:
* OS: Windows XP
* History:
* ID --- date ----------- note -------------------------------
* 00
**************************************** ***********************/

# Ifndef _ code128c_h _
# DEFINE _ code128c_h _

/********************** Global variable declare ************* **/
// # Define-1;
//////////////////////////////////////// //////////////////////

/*********************** Include files ************* ************/
// # Pragma warning (Disable: 4786)
// # Include <iostream>
// # Include <string>
// # Include <map>
// Using namespace STD;
//////////////////////////////////////// ///////////////////////

/*************************************** ************************
* Name: code128c
* Base class name:
* Function: print the C code in code128 mode.
* Interface:
**************************************** ***********************/

Class code128c
{
Public:

// Constructors & destructor
Code128c ();
Virtual ~ Code128c ();
// Interface
Int printcodebar (const cstring & snum, const rect & rect, CDC & DC );

// Attributes
PRIVATE:
// Operations
Int getprintcode (const cstring & snum, cstring & sprintcode );
Int printcode (const cstring & snum, const cstring & sprintcode, const rect & rect, CDC & DC );
// Attributes
Int m_nhead;
Int m_ntail;
Char m_code128_c [128] [8];
};

# Endif;

 

// Implement the code128c. cpp File

 

/*************************************** ************************
* Name: code128c. cpp
* Function:
* Programmed: ming_zhang
* Date (org): August 24 2011
* Project:
* OS: Windows XP
* History:
* ID --- date ----------- note -------------------------------
* 00
**************************************** ***********************/

/*********************** Include files ************* ************/
# Include "stdafx. H"
# Include "code128c. H"
// # Include <string>
// Using namespace STD;
//////////////////////////////////////// ///////////////////////

Code128c: code128c ()
{
M_nhead = 105;
M_ntail = 106;
/* Initialize the encoding table code128 C */
Strcpy (m_code128_c [0], "212222 ");
Strcpy (m_code128_c [1], "222122 ");
Strcpy (m_code128_c [2], "222221 ");
Strcpy (m_code128_c [3], "121223 ");
Strcpy (m_code128_c [4], "121322 ");
Strcpy (m_code128_c [5], "131222 ");
Strcpy (m_code128_c [6], "122213 ");
Strcpy (m_code128_c [7], "122312 ");
Strcpy (m_code128_c [8], "132212 ");
Strcpy (m_code128_c [9], "221213 ");
Strcpy (m_code128_c [10], "221312 ");
Strcpy (m_code128_c [11], "231212 ");
Strcpy (m_code128_c [12], "112232 ");
Strcpy (m_code128_c [13], "122132 ");
Strcpy (m_code128_c [14], "122231 ");
Strcpy (m_code128_c [15], "113222 ");
Strcpy (m_code128_c [16], "123122 ");
Strcpy (m_code128_c [17], "123221 ");
Strcpy (m_code128_c [18], "223211 ");
Strcpy (m_code128_c [19], "221132 ");
Strcpy (m_code128_c [20], "221231 ");
Strcpy (m_code128_c [21], "213212 ");
Strcpy (m_code128_c [22], "223112 ");
Strcpy (m_code128_c [23], "312131 ");
Strcpy (m_code128_c [24], "311222 ");
Strcpy (m_code128_c [25], "321122 ");
Strcpy (m_code128_c [26], "321221 ");
Strcpy (m_code128_c [27], "312212 ");
Strcpy (m_code128_c [28], "322112 ");
Strcpy (m_code128_c [29], "322211 ");
Strcpy (m_code128_c [30], "212123 ");
Strcpy (m_code128_c [31], "212321 ");
Strcpy (m_code128_c [32], "232121 ");
Strcpy (m_code128_c [33], "111323 ");
Strcpy (m_code128_c [34], "131123 ");
Strcpy (m_code128_c [35], "131321 ");
Strcpy (m_code128_c [36], "112313 ");
Strcpy (m_code128_c [37], "132113 ");
Strcpy (m_code128_c [38], "132311 ");
Strcpy (m_code128_c [39], "211313 ");
Strcpy (m_code128_c [40], "231113 ");
Strcpy (m_code128_c [41], "231311 ");
Strcpy (m_code128_c [42], "112133 ");
Strcpy (m_code128_c [43], "112331 ");
Strcpy (m_code128_c [44], "132131 ");
Strcpy (m_code128_c [45], "113123 ");
Strcpy (m_code128_c [46], "113321 ");
Strcpy (m_code128_c [47], "133121 ");
Strcpy (m_code128_c [48], "313121 ");
Strcpy (m_code128_c [49], "211331 ");
Strcpy (m_code128_c [50], "231131 ");
Strcpy (m_code128_c [51], "213113 ");
Strcpy (m_code128_c [52], "213311 ");
Strcpy (m_code128_c [53], "213131 ");
Strcpy (m_code128_c [54], "311123 ");
Strcpy (m_code128_c [55], "311321 ");
Strcpy (m_code128_c [56], "331121 ");
Strcpy (m_code128_c [57], "312113 ");
Strcpy (m_code128_c [58], "312311 ");
Strcpy (m_code128_c [59], "332111 ");
Strcpy (m_code128_c [60], "314111 ");
Strcpy (m_code128_c [61], "221411 ");
Strcpy (m_code128_c [62], "431111 ");
Strcpy (m_code128_c [63], "111224 ");
Strcpy (m_code128_c [64], "111422 ");
Strcpy (m_code128_c [65], "121124 ");
Strcpy (m_code128_c [66], "121421 ");
Strcpy (m_code128_c [67], "141122 ");
Strcpy (m_code128_c [68], "141221 ");
Strcpy (m_code128_c [69], "112214 ");
Strcpy (m_code128_c [70], "112412 ");
Strcpy (m_code128_c [71], "122114 ");
Strcpy (m_code128_c [72], "122411 ");
Strcpy (m_code128_c [73], "142112 ");
Strcpy (m_code128_c [74], "142211 ");
Strcpy (m_code128_c [75], "241211 ");
Strcpy (m_code128_c [76], "221114 ");
Strcpy (m_code128_c [77], "413111 ");
Strcpy (m_code128_c [78], "241112 ");
Strcpy (m_code128_c [79], "134111 ");
Strcpy (m_code128_c [80], "111242 ");
Strcpy (m_code128_c [81], "121142 ");
Strcpy (m_code128_c [82], "121241 ");
Strcpy (m_code128_c [83], "114212 ");
Strcpy (m_code128_c [84], "124112 ");
Strcpy (m_code128_c [85], "124211 ");
Strcpy (m_code128_c [86], "411212 ");
Strcpy (m_code128_c [87], "421112 ");
Strcpy (m_code128_c [88], "421211 ");
Strcpy (m_code128_c [89], "212141 ");
Strcpy (m_code128_c [90], "214121 ");
Strcpy (m_code128_c [91], "412121 ");
Strcpy (m_code128_c [92], "111143 ");
Strcpy (m_code128_c [93], "111341 ");
Strcpy (m_code128_c [94], "131141 ");
Strcpy (m_code128_c [95], "114113 ");
Strcpy (m_code128_c [96], "114311 ");
Strcpy (m_code128_c [97], "411113 ");
Strcpy (m_code128_c [98], "411311 ");
Strcpy (m_code128_c [99], "113141 ");
Strcpy (m_code128_c [100], "114131 ");
Strcpy (m_code128_c [101], "311141 ");
Strcpy (m_code128_c [102], "411131 ");
Strcpy (m_code128_c [103], "211412 ");
Strcpy (m_code128_c [104], "211214 ");
Strcpy (m_code128_c [105], "211232 ");
Strcpy (m_code128_c [106], "2331112 ");
}

Code128c ::~ Code128c ()
{
}

/*************************************** *****************************
* Name: printcodebar
* Function: print the barcode of an external interface.
* Parameter:
* Return:
* Programmer: Ming Zhang
* Date (org): August 24 2011
* Update:
* Memo:
**************************************** ****************************/
Int code128c: printcodebar (const cstring & snum, const rect & rect, CDC & DC)
{
Cstring sprintcode;
Getprintcode (snum, sprintcode );
Printcode (snum, sprintcode, rect, DC );
 
Return 1;
}

/*************************************** *****************************
* Name: getprintcode
* Function: Print Code obtained based on the imported data.
* Parameter:
* Return:
* Programmer: Ming Zhang
* Date (org): August 24 2011
* Update:
* Memo:
**************************************** ****************************/
Int code128c: getprintcode (const cstring & snum, cstring & sprintcode)
{
/* Header */
Sprintcode = m_code128_c [m_nhead];
/* Data */
Int nlength = snum. getlength ();
Int NV;
Int J = 1;
Int nveryfy = m_nhead;
For (INT I = 0; I <nlength; I = I + 2)
{
NV = atoi (snum. mid (I, 2 ));
Sprintcode = sprintcode + m_code128_c [NV];
Nveryfy = nveryfy + J * NV;
++ J;
}

/* Calculate the Verification Code */
Nveryfy = nveryfy % 103;
Sprintcode = sprintcode + m_code128_c [nveryfy];
/* Tail */
Sprintcode = sprintcode + m_code128_c [m_ntail];
Return 1;
}

/*************************************** *****************************
* Name: printcode
* Function: print the barcode.
* Parameter:
* Return:
* Programmer: Ming Zhang
* Date (org): August 24 2011
* Update:
* Memo:
**************************************** ****************************/
Int code128c: printcode (const cstring & snum, const cstring & sprintcode, const rect & rect, CDC & DC)
{
Int I;
Int nlen = sprintcode. getlength ();
Int ntotalbar = 0;
For (I = 0; I <nlen; ++ I)
Ntotalbar = ntotalbar + (sprintcode [I]-'0 ');

Int nbarwidth = (rect. right-Rect.left)/ntotalbar;
Int nbarheight = (rect. bottom-Rect.top );
/* Font nbarheight = 1/4 Image Height */
Int nfontheight = nbarheight/2;
Nbarheight = nbarheight-nfontheight;


Int neachprintbarnum;
Int nvaluelength = sprintcode. getlength ();
Int nbegpos = rect. Left;/* calculate the start position of the print, in pixels */
Int nendpos;
Rect RT;

Cbrush brush_black (RGB (0, 0, 0 ));
Cbrush brush_white (RGB (255,255,255 ));
For (I = 0; I <nvaluelength; ++ I)
{
Neachprintbarnum = sprintcode [I]-'0 ';
/* Computation printing */
Nendpos = nbegpos + neachprintbarnum * nbarwidth;
Rt. Left = nbegpos;
Rt. Right = nendpos;
Rt. Top = rect. Top;
Rt. Bottom = rect. Top + nbarheight;

If (I % 2 = 0)
{/* Black */
DC. fillrect (& RT, & brush_black );
}
Else
{
DC. fillrect (& RT, & brush_white );
}
Nbegpos = nendpos;/* next start point */
}
Rt. Top = rect. Bottom-nfontheight;
Rt. Bottom = rect. bottom;
Rt. Left = rect. Left;
Rt. Right = rect. Left + nbarwidth * ntotalbar;

DC. drawtext (snum, & RT, dt_center | dt_singleline | dt_noprefix );

Return 1;
}

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.