CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> Miscellaneous >> Miscellaneous


Adding Barcode 3 of 9 to Your Applications
Rating:

David Hillard (view profile)
January 22, 2003



(continued)




Click here for a larger image.

Environment: VC6 Win32

There are barcode TrueType fonts available for printing 3 of 9 barcodes, but those fonts must be distributed with your final application to be sure they're available on the end-user's PC. They also require calculating and creating the proper size font for your barcode use. This code allows you to print any size and virtually any density 3 of 9 barcode from within your own code.

This code uses the bare Win32 API. MFC is NOT REQUIRED!

If you find you need to add barcode print functionality to your application, I offer this small C++ source code and header file consisting of three functions:

  • int BC39_Decode(char);
  • void BC39_Expand(int,char*);
  • int BC39_Draw(HDC,RECT*,char*,double,BOOL);

The first two functions, BC39_Decode() and BC39_Expand(), are used internally by BC39_Draw(); therefore, you only need to concern yourself with BC39_Draw().

In your source code, you only need to supply BC39_Draw() with five parameters to place a 3 of 9 barcode on your device context.

Parameter #1 is a handle to your device code context. This will normally be a printer DC because it doesn't make a whole lot of sense to print barcodes to the screen except for print preview functionality.

Parameter #2 is a pointer to a RECT defining the area on the DC where the barcode will be placed.

Parameter #3 is character string of the data that will be barcoded. Barcode 3 of 9 uses the start and stop characters of '*'; these characters are automatically inserted as the first and last character of your supplied character string. If the supplied character string is greater than 30 characters, the barcode will not print.

Parameter #4 is a double value indicating the characters per inch of the barcode; for example, density. This is accurate when printing to a high DPI device such as a laser printer, but will not be accurate when displayed on the screen due to the relatively low DPI of the screen device.

Parameter #5 is a BOOLEAN value meaning the Horizontal (left to right) barcode is TRUE and the Vertical (top to bottom) barcode is FALSE.

BC39_Draw() will return 0 if the barcode could be fully displayed in the supplied rectangle (RECT) dimensions. If it wouldn't fit, the rectangle is elongated to hold the barcode and the function will return a value of 1.

If there is ample room in the supplied rectangle to fully display the barcode, the barcode is horizontally centered in the rectangle for a horizontal printing barcode, and vertically centered in the rectangle for a vertical barcode.

Example usage:

  #include "barcode39.h"
    .
    .
    .

    case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    RECT rt;

    //define the rectangle on the dc where the barcode will
    //be displayed
    rt.top=60;
    rt.left=20;
    rt.right=500;
    rt.bottom=100;

    if(BC39_Draw(ps.hdc,&rt,"Test123",10,TRUE))
        {
          //barcode didn't fit in supplied rect dimensions;
          //rect was sized to fit
          MessageBeep(0);
        }


    EndPaint(hWnd, &ps);
    break;

Downloads

Download source - 3 Kb

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
Adding Barcode 3 of 9 to Your Applications - Legacy CodeGuru (12/11/2003)
Bar Code Reader status - Legacy CodeGuru (08/02/2003)
We need a component - Legacy CodeGuru (06/05/2003)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES