Thread: My CPrint library... quality printing made easy

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    Lightbulb My CPrint library... quality printing made easy

    Hey all. I have written this very useful class called CPrint. It is derived from CPrintDialog and is a very simple solution to printing multi-formatted text documents with as little as three lines of code. Moreover, it is device independent and thus is consistent across all printers.

    A sample file is included, but is as simple as this:
    Code:
    #include "CPrint.h"
    
    ...
    CPrint dlg;
    if (dlg.InitPrintJob()) {
      dlg.PrintLine("Here's the title of my document!", PA_HSPACE);
      dlg.PrintLine("Blah blah blah... The quick brown fox, etc");
      dlg.ConcludePrintJob();
    }
    ...
    And that's it! I'm hoping someone else will find it useful as I remember how I struggled when I was first trying to send something useful and decent looking to a printer without a ton of code.

    Aside from just printing you can do most necessary tasks to make print jobs attractive, like changing fonts (face, size, italic, bold, underline, strikeout). In addition it was designed with inheritance in mind so you can design much more complex print classes.

    Let me know what you think... (even if you think it's a pile of crap)

    Thanks.

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Was ConcludePrintJob() a member of CPrintDialog? In my experience, it's better to use names like Finish() or End(). They're easier to spell, type, and remember.

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    No, that function is not a part of CPrintDialog.
    Thank you for your comment, Eibrow. That seems to be my primary predicament in programming: coming up with good, meaningful, short names for functions. I usually overdo it, as I did in this case. I'll take your suggestion.

  4. #4
    hargalaten
    Guest
    ----quote-----------
    Aside from just printing you can do most necessary tasks to make print jobs attractive, like changing fonts (face, size, italic, bold, underline, strikeout). In addition it was designed with inheritance in mind so you can design much more complex print classes
    --------------------

    could you show me quickly how to do all this - namely the underline?

  5. #5
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Code:
    // set font attributes (may be called in the middle of a print job)
      bool    SetFont(int size, LPCTSTR face, int weight, BOOL italic, BOOL under, BOOL strike);
    (I just copied this from the header file). I didn't add individual functions to alter different attributes mainly because I was being lazy.
    You can do something like this:
    Code:
    printDlg->SetFont(printDlg->GetFontSize(), 
      printDlg->GetFontFace(), 
      printDlg->GetFontWeight(), 
      printDlg->IsFontItalic(),
      printDlg->IsFontUnderline(), 
      printDlg->IsFontStrikeout());
    Just set that bold part to true if you want an underline or false if not... The better way to go would be to add functions into the header file to alter just the attribute you want. For example:
    Code:
    bool SetUnderline(BOOL underlineItYo) { 
      return SetFont(printDlg->GetFontSize(), 
        printDlg->GetFontFace(), 
        printDlg->GetFontWeight(), 
        printDlg->IsFontItalic(),
        underlineItYo, 
        printDlg->IsFontStrikeout());
    }
    And so on...
    Last edited by LuckY; 05-17-2003 at 02:19 AM.

  6. #6
    Cat
    Guest
    Doesn't work at all, I think because you've statically linked all the MFC libraries into the .lib that you provided; this causes multiple definition errors like:

    nafxcwd.lib(afxmem.obj) : error LNK2005: "public: static void * __stdcall CObject:perator new(unsigned int)" (??2CObject@@SGPAXI@Z) already defined in CPrintLib.lib(CPrint.obj)

  7. #7
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    I've cleaned up all the big blocks of comments and the major ugly stuff in the source that prevented me from posting it before. It's attached, so those errors should go byebye...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem aligning floating point numbers
    By esbo in forum C Programming
    Replies: 4
    Last Post: 01-05-2009, 08:09 PM
  2. Need help with audio library on DOS...
    By Marton79 in forum C Programming
    Replies: 10
    Last Post: 08-25-2006, 12:32 AM
  3. Printing to the screen without a library.
    By OSDever in forum Linux Programming
    Replies: 11
    Last Post: 04-26-2004, 02:37 PM
  4. better c string functions
    By samps005 in forum C Programming
    Replies: 8
    Last Post: 11-04-2003, 01:28 PM
  5. 2D arrays with functions made easy
    By goran in forum C Programming
    Replies: 1
    Last Post: 09-17-2001, 12:08 PM