Thread: Printing: The Lazy Way

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Printing: The Lazy Way

    Is there some free SDK or library that I can download that has printing functions that get rid of the need of everything except a couple lines of code when I need to print?
    Last edited by face_master; 07-30-2002 at 04:15 AM.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: Printing: The Lazy Way

    Originally posted by face_master
    Is there some free SDK or library that I can download that has printing functions that get rid of the need of everything except a couple lines of code?
    This is something I posted on another thread....its only a little code...and half of it is to diplay that nice print dialog.........

    Your best bet is to spend an hour reading the actual functions in the SDK......IMHO, it will take just as long to grasp the usage of a 3rd party lib.....and I think its less hassle

    Code:
    #include <string>//I am lazy when it comes to char arrays
    using std::string;
    #include <windows.h>//The all important header
    #include <commdlg.h>//Dont forget comdlg32.lib!!!
    
    int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
    {
    PRINTDLG  pd;//To initialise dialog & accept results
    string str = "API rules!! :p";//catchy phrase
    DOCINFO di = {
    sizeof(DOCINFO),
    "Fordy's Doc",
    NULL
    };//This gives details on doc...like its name when spooled
    
    ZeroMemory(&pd,sizeof(PRINTDLG));//saves initiliasing to zero
    
    pd.lStructSize = sizeof(PRINTDLG);
    pd.hwndOwner = HWND_DESKTOP;
    pd.Flags = PD_RETURNDC;//This gives DC to printer selected
    pd.nCopies = 1;
    
    
    if(!PrintDlg(&pd))
    return 0;//If the user cancels....?
    
    if(StartDoc(pd.hDC,&di)>0 && StartPage(pd.hDC)>0){//new doc...new page
    TextOut(pd.hDC,10,10,str.c_str(),str.length()); //Write some text
    EndPage(pd.hDC);//end of page
    EndDoc(pd.hDC); //end of doc
    }
      DeleteDC(pd.hDC);//Clean up!
    
      return 0;
    }

  3. #3
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Thanks, I try that!

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    I just have on question, to avoid heaps of confusion, could you please tell me how to replace this call using a character array instead of a string please?
    Code:
    TextOut(pd.hDC,10,10,str.c_str(),str.length());

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by face_master
    I just have on question, to avoid heaps of confusion, could you please tell me how to replace this call using a character array instead of a string please?
    Code:
    TextOut(pd.hDC,10,10,str.c_str(),str.length());
    Code:
    char* buff = "Hello World";
    int nLen = strlen(buff);
    
    TextOut(pd.hDC,10,10,buff,nLen);

  6. #6
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. Printing Lines to .txt File
    By Programmer3922 in forum C Programming
    Replies: 2
    Last Post: 08-02-2008, 12:45 PM
  3. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 02:20 AM
  4. printing data to a file
    By coralreef in forum C Programming
    Replies: 3
    Last Post: 11-02-2006, 08:10 PM
  5. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 04:46 AM