Output to printer.

This is a discussion on Output to printer. within the Windows Programming forums, part of the Platform Specific Boards category; Code: case MENU_PRINT: memset(&prntdlg, 0, sizeof(PRINTDLG)); prntdlg.hwndOwner = mainwnd; prntdlg.Flags = PD_DISABLEPRINTTOFILE | PD_HIDEPRINTTOFILE | PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC; ...

  1. #1
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065

    Output to printer.

    Code:
    				case MENU_PRINT:
    					memset(&prntdlg, 0, sizeof(PRINTDLG));
    					prntdlg.hwndOwner = mainwnd;
    					prntdlg.Flags = PD_DISABLEPRINTTOFILE | PD_HIDEPRINTTOFILE
    								 | PD_NOPAGENUMS | PD_NOSELECTION
    								 | PD_RETURNDC;
    					prntdlg.nFromPage = 1;
    					prntdlg.nToPage = 1;
    					prntdlg.nMinPage = 1;
    					prntdlg.nMaxPage = 1;
    					prntdlg.nCopies = 1;
    					prntdlg.lStructSize = sizeof(PRINTDLG);
    					if (!PrintDlg(&prntdlg))
    						break;
    					dinfo.cbSize = sizeof(DOCINFO);
    					dinfo.lpszDocName = "ADACS Viewer Page";
    					i = StartDoc(prntdlg.hDC, &dinfo);
    					if (StartPage(prntdlg.hDC) < 0){
    						MessageBox(mainwnd, "Print Job Failed.", 
    								     "Could not start page!", MB_OK |
    								     MB_ICONEXCLAMATION);
    						EndDoc(prntdlg.hDC);
    					} else {
    						send2printer(wnds, prntdlg.hDC);
    						EndPage(prntdlg.hDC);
    						EndDoc(prntdlg.hDC);
    					}
    					DeleteDC(prntdlg.hDC);
    					break;
    The code is in my main window callback procedure. In this code, I'm answering the call to a File -> Print. Something isn't right, though. What I think is happening is that I'm not destroying all the data that comes out of the PrintDlg() and/or maybe I'm not releasing my DC correctly. I've looked around on MSDN, however, the only thing I could come up with was to DeleteDC() after the EndDoc().

    What am I missing here?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> Something isn't right, though. <<

    Details?

  3. #3
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Bummer, thought that I had enough so that no one would notice that. . . Didn't feal like editing .

    I can print one "page". If, however, I choose a new selection then I cannot print again for a time. To be honest, I haven't found the pattern, yet. It works sometimes, sometimes not. I can print the same selection over and over again, even from the same file . . . hmmm, which makes me think that I may not be setting something else right. . . may be totaly unrelated to the above code. . .

    Something isn't right. =)

    EDIT: Nevermind. . . the above code is apparently sound. . . the problem was elsewhere where I was subscripting an array, just the wrong array.
    Last edited by Kennedy; 10-25-2006 at 01:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 05:41 PM
  2. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 09:08 PM
  3. Having trouble making a function do what I want.
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2007, 10:20 AM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 10:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21