Thread: How do you print stuff using the winapi in C

  1. #1
    Registered User HelpfulPerson's Avatar
    Join Date
    Jun 2013
    Location
    Over the rainbow
    Posts
    288

    How do you print stuff using the winapi in C

    It may not be supported, I'm not sure. All I found when I looked it up were pure C++ and C# samples.

  2. #2
    Registered User HelpfulPerson's Avatar
    Join Date
    Jun 2013
    Location
    Over the rainbow
    Posts
    288
    Oh and by printing I'm talking text documents.

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    Do you mean sending the edit control text to a printer for printing? If so, then wouldn't that fall under winapi GDI category? I know that writing a printer function in C can be a bit challenging sometimes.

  4. #4
    Registered User HelpfulPerson's Avatar
    Join Date
    Jun 2013
    Location
    Over the rainbow
    Posts
    288
    Quote Originally Posted by TAZIN View Post
    Do you mean sending the edit control text to a printer for printing? If so, then wouldn't that fall under winapi GDI category? I know that writing a printer function in C can be a bit challenging sometimes.

    Yea, I just want to make a function that can print a normal average text document in your default printer.

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    There are a few basic tutorials on line that illustrate the basics for winapi printing. Also check out the Multipad example program supplied with earlier Win32 SDK discs. I think Petzold also has an example in one of his text editor programs.

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    You can use print action of ShellExecute ShellExecute function (Windows)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #7
    Registered User HelpfulPerson's Avatar
    Join Date
    Jun 2013
    Location
    Over the rainbow
    Posts
    288
    Quote Originally Posted by vart View Post
    You can use print action of ShellExecute ShellExecute function (Windows)
    Oh, thanks Vart, I've used that function before.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Otherwise search here for more info.

    In WIN32 API is used to be;

    Get the printer/s with GetProfileString() or EnumPrinters() ect. Using the right PRINTER_INFO_# (1-5) depending on the OS ect.

    Use PageSetupDlg() with a PAGESETUPDLG struc to allow the user to change the settings of the printer in the common dlgs (ensure that you have included/init common dlgs)

    Get a HDC for the printer the user selected. (In the *DEVMODE struct.)

    Send the StartDoc()

    Send StartPage()

    Print the data to the HDC of the printer. (TextOut())

    Send the EndPage()

    Send EndDoc()

    Release the printer HDC.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game-related stuff with WinAPI
    By YuriKahn in forum C Programming
    Replies: 2
    Last Post: 05-23-2013, 04:17 AM
  2. Replies: 15
    Last Post: 06-13-2012, 12:34 PM
  3. Why does this print some stuff
    By kool_hamster in forum C Programming
    Replies: 1
    Last Post: 01-27-2010, 10:11 AM
  4. Replies: 2
    Last Post: 06-27-2003, 01:45 PM
  5. Tab key stuff. C+WinAPI is killing me. Please help.
    By Templario in forum Windows Programming
    Replies: 5
    Last Post: 11-21-2002, 03:35 PM