Thread: printing in 'C'

  1. #16
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Still anybody know the answer to my usb printer problem?

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Are you running real DOS, or a console inside some version or other of windows?

    If you're in windows, there's some configuration to make any printer appear as "LPT1" (say) to any program running in a console.

    You'd need to do some digging elsewhere - the specifics of such things are beyond me

  3. #18
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    I'm doing it in a console under windows.

  4. #19
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192

    Thumbs up

    HeyBuddies,

    I need to print to paper in landscape mode how is that done, also my file is a binary file not text. help!!!! (again).
    Well, U see now, he wants to print in different modes (landscape etc...) I feel you should know the printer driver for the same or atleast a generic set of printer commands.

    Regards,
    Sriharsha.

  5. #20
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You could always take the dive and go API!!

    I posted some API code a while ago that allowed the program to find the default printer and print ot it.....but if you want to select printer and have other features like amount of pages, page selection and it also gives you access to the printer config dialog that allows you to specify stuff like landscape printing ect.....

    Far easier than killing youself with drivers!

    Something like this (basic but hey it works!)

    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;
    }
    Again apologies for using a string on the C Board!

  6. #21
    Registered User
    Join Date
    Apr 2002
    Posts
    15
    Thanks for the reply unregistered, I pretty much know how to fseek, fread etc.

    Id like to know how to print (to paper), to a specific format.

    eg. if iwant to print a piece of data in the middle of a line then the next piece of data ten spaces further along the line.

    Ive never accessed a printer before so i dont know where to start, also i have to access my printer through the USB port.

    please help anyone.

    yours shin.

  7. #22
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Same here, usb. Thnx for that api code, it didn't work for me though , undeclared and stuff. There are no other ways are there?

    thnx

  8. #23
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Nutshell
    Same here, usb. Thnx for that api code, it didn't work for me though , undeclared and stuff. There are no other ways are there?

    thnx
    Get a Win32 compiler.......devc++ is free and codewarrior is available on the front of UK magazines this month!

  9. #24
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    I was always using DevC++.

  10. #25
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Works on my DevC++....do you have the libraries included?

    Cant find the default lib options on my IDE at the moment.......but I think you should make sure libwinspool.a & libcomctl32.a are in there

  11. #26
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192

    Thumbs up

    Hi guys,

    check this file out and tell me if it helps you in anyway...

    http://www.usb.org/developers/data/d...usbprint11.pdf

    Regards,
    Sriharsha
    Help everyone you can

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. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 02:20 AM
  3. printing data to a file
    By coralreef in forum C Programming
    Replies: 3
    Last Post: 11-02-2006, 08:10 PM
  4. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 04:46 AM
  5. Printing
    By Dual-Catfish in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 05-25-2002, 08:10 PM