Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Printing to a dot-matrix printer
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
FlyGuy  
View profile  
 More options Jun 14 2006, 2:06 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "FlyGuy" <Manha...@mstarmetro.net>
Date: Wed, 14 Jun 2006 12:06:21 -0600
Local: Wed, Jun 14 2006 2:06 pm
Subject: Printing to a dot-matrix printer
Does anyone know of any information or examples of how to print to a
dot-matrix printer? Specifically, how to change the Printer page length to
print a non-standard page size.
Thanks!!

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vladimir Stefanovic  
View profile  
 More options Jun 14 2006, 2:46 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Vladimir Stefanovic" <antiv...@po.sbb.co.yu>
Date: Wed, 14 Jun 2006 20:46:53 +0200
Local: Wed, Jun 14 2006 2:46 pm
Subject: Re: Printing to a dot-matrix printer
There was once a topic:
"Sending Data Directly to the Printer", at:
http://www.bytamin-c.com/Tips%20&%20Tricks/directprint.htm

Unfortunately, Bytamin-C is no longer there. As a matter of fact,
I saved the page long time ago, but I haven't tested it.

So here is the /untested/ original:

<quote>

Below is a quick sample of how to send data directly to the
printer. Remember to include winspool.h to your file.

NB: If you printer is directly connected to your computer
(LPT1-LPT3) or is a mapped networkprinter in which case you can
use UNC paths to the printer (eg. "\\MainServer\MatrixPrinter"
which in C would be "\\\\MainServer\\MatrixPrinter") you can
just use simple file functions eg. fopen("lpt1", "wt") or
fopen("\\\\MainServer\\MatrixPrinter", "wt"). I hope this helps
those of you in despair ;)

Regards, Jeppe.

// szBuffer is the buffer which holds the data we wanna send to the printer
bool Print(char* szPrinterName, char* szBuffer)
{
   HANDLE hPrinter; // Printer handle
   int iLen = strlen( szBuffer );// Length of the data to be sent
   DWORD dwWritten; // How much was written to the printer

  // Open printer and get a handle to it (which is saved in hPrinter)
  if ( OpenPrinter( szPrinterName, &hPrinter, NULL ) )
  {
     // Doc info
     DOC_INFO_1 Info;
      memset( &Info, 0, sizeof( Info ) );
      Info.pDocName = "My PrintJob"; // Name of the Doc (which is shown in
the PrintManager)
      Info.pOutputFile = NULL; // We're not going to write to a file so we
set it to NULL
      Info.pDatatype = "RAW"; // Data are sent in RAW format (RAW and EMF
are supported by both
      // Win9x and Win NT). Win NT also supports TEXT.
      // Start doc
      if( !StartDocPrinter( hPrinter, 1, (LPBYTE)&Info ) )
         return false;
      // Tell the printer we're starting on a new page
      StartPagePrinter( hPrinter ); // Write data to the printer
      if( !WritePrinter( hPrinter, szBuffer, iLen, &dwWritten ) )
      {
         // An error happened while sending data to the printer.
         // Use LastError to figure out what went wrong.
      }
      // Tell the printer we're done writing this page
      EndPagePrinter( hPrinter );
      // End the document
      if( !EndDocPrinter( hPrinter ) )
         return false;
      // Close the printer
      ClosePrinter( hPrinter );
      return true;
   }
   else
   {
      return false;
   }

}

</quote>

--
Best Regards,
Vladimir Stefanovic

"FlyGuy" <Manha...@mstarmetro.net> wrote in message

news:4490501d$1@newsgroups.borland.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
FlyGuy  
View profile  
 More options Jun 15 2006, 2:16 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "FlyGuy" <Manha...@mstarmetro.net>
Date: Thu, 15 Jun 2006 12:16:30 -0600
Local: Thurs, Jun 15 2006 2:16 pm
Subject: Re: Printing to a dot-matrix printer
This is helpful, however what I would really like to do is print through C++
Builder's printer->canvas. I just can't seem to figure out how to make that
work with a 7" check form on a dot-matrix printer. Is there no way to change
the printer's page-height through the printer object? Or is the only
solution to go through the Windows API?  Thanks!!

"Rudy Velthuis [TeamB]" <newsgro...@rvelthuis.de> wrote in message
news:xn0enhpztupb5ji00d-velthuis@www.teamb.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
JD  
View profile  
 More options Jun 16 2006, 11:05 am
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "JD" <nos...@nospam.com>
Date: 16 Jun 2006 08:05:40 -0700
Local: Fri, Jun 16 2006 11:05 am
Subject: Re: Printing to a dot-matrix printer

"FlyGuy" <Manha...@mstarmetro.net> wrote:

> what I would really like to do is print through C++
> Builder's printer->canvas.

Search the archives:

    http://www.tamaracka.com/search.htm

You're looking for GetPrinter and SetPrinter.

~ JD


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
FlyGuy  
View profile  
 More options Jun 16 2006, 5:11 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "FlyGuy" <Manha...@mstarmetro.net>
Date: Fri, 16 Jun 2006 15:11:45 -0600
Local: Fri, Jun 16 2006 5:11 pm
Subject: Re: Printing to a dot-matrix printer
This helps a lot. I've added code to attempt to change some of the printer
parameters, but can't seem to get the correct results. If I use this code to
change the orientation of the page (commented out) the orientation changes,
but when I try to change the page height & width, nothing happens. I've also
tried changing the scaling factor, default source (input bin), and the paper
size, none had any effect. The code I'm using is as follows:

#include <winspool.h>
    char deviceName[128];
    char driverName[128];
    char portName[128];
    unsigned int hDeviceMode;   // handle to DEVMODE struct in memory
    DEVMODE* pDevMode;          // pointer to DEVMODE struct

    Prntr->GetPrinterA(deviceName, driverName, portName, hDeviceMode);
    pDevMode = (DEVMODE*)GlobalLock((void*)hDeviceMode);
    if (pDevMode != NULL)
    {
      pDevMode->dmFields = pDevMode->dmFields || DM_DEFAULTSOURCE;
      pDevMode->dmDefaultSource = DMBIN_MANUAL;

//      pDevMode->dmFields = pDevMode->dmFields || DM_ORIENTATION;
//      pDevMode->dmOrientation = DMORIENT_LANDSCAPE;

      pDevMode->dmFields = pDevMode->dmFields || DM_PAPERLENGTH ||
                  DM_PAPERWIDTH;
      pDevMode->dmPaperLength = 1778;   // 1778 = 7" in tenths of mm
      pDevMode->dmPaperWidth = 2159;    // 2159 = 8.5" in tenth of mm
    }
    GlobalUnlock((void*)hDeviceMode);

    Prntr->BeginDoc();                    // start printer doc

Can anyone tell me what I might be doing wrong? I'm testing on an HP
LaserJet 1200 printer. Is it possible that these other things can't be
changed for this type of printer? Thanks!!!

"JD" <nos...@nospam.com> wrote in message

news:4492c8c4@newsgroups.borland.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
JD  
View profile  
 More options Jun 16 2006, 6:38 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "JD" <nos...@nospam.com>
Date: 16 Jun 2006 15:38:27 -0700
Local: Fri, Jun 16 2006 6:38 pm
Subject: Re: Printing to a dot-matrix printer

"FlyGuy" <Manha...@mstarmetro.net> wrote:

> [...] I've added code to attempt to change some of the
> printer parameters, but can't seem to get the correct
> results. [...]

A couple of things:

>    char deviceName[128];
>    char driverName[128];
>    char portName[128];

These should be 256 in length and initialized:

    char deviceName[ 256 ] = { 0 };
    char driverName[ 256 ] = { 0 };
    char portName  [ 256 ] = { 0 };

>    unsigned int hDeviceMode;

While it most likely makes no difference, this is technically
a THandle:

    THandle hDeviceMode;

>    DEVMODE* pDevMode;          // pointer to DEVMODE struct

>    Prntr->GetPrinterA(deviceName, driverName, portName, hDeviceMode);

I'm uncertain about GetPrinterA so I would suggest that you
use GetPrinter. However, there is a known issue with TPrinter
in that it's Handle is not always valid so you need to insert
a line above the call to GetPrinter:

    Printer()->PrinterIndex = x;

where x is a valid printer index. It's been more than a year
since I tested this and my notes are no longer clear. It looks
like x can not be -1 which under other conditions is a valid
value to restore the default printer. I also suspect that you
may have to use a non-default printer. You can just install a
generic printer which won't require and disks and then use the
control panel to change the default to the generic.

>    pDevMode = (DEVMODE*)GlobalLock((void*)hDeviceMode);

I'm confident that this was the problem because the call to
GetPrinter was returning a bad hDeviceMode. Actually, not bad
but rather incorrect.

BTW : You really should be using C++ casting here.

>    GlobalUnlock((void*)hDeviceMode);

I'm reasonably sure that you need to call SetPrinter after you
unlock but in my sample, the ADeviceMode parameter is set to
NULL. This causes concern for me but you should be able to
figure it as long as you're aware of it.

> I'm testing on an HP LaserJet 1200 printer.

You said it was a dot matrix printer!!! Big difference!

> Is it possible that these other things can't be changed for
> this type of printer?

I know that you can accomplish what you want. I just don't
know for sure how to do it.

~ JD


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google