Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SDI app: Wait for printer

SDI app: Wait for printer

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nobaq
    wrote on last edited by
    #1

    Hello, In my application, I send a print command to my view from a (modal) dialog:

    pView->OnCmdMsg(ID_FILE_PRINT, 0, 0, 0);

    How can I wait until the printing process has been finished? Background: In my dialog I want to be able to print other data than loaded into the current view. For this purpose, I save the state of the current view, load another document, print it and afterthe document has finished printing I reload the old document again and close the dialog. Thank you and regards, Niki

    N I L 3 Replies Last reply
    0
    • N nobaq

      Hello, In my application, I send a print command to my view from a (modal) dialog:

      pView->OnCmdMsg(ID_FILE_PRINT, 0, 0, 0);

      How can I wait until the printing process has been finished? Background: In my dialog I want to be able to print other data than loaded into the current view. For this purpose, I save the state of the current view, load another document, print it and afterthe document has finished printing I reload the old document again and close the dialog. Thank you and regards, Niki

      N Offline
      N Offline
      nobaq
      wrote on last edited by
      #2

      I have forgotten a very important issue: The view is a CHtmlView. So my view does not have an own printing mechanism

      1 Reply Last reply
      0
      • N nobaq

        Hello, In my application, I send a print command to my view from a (modal) dialog:

        pView->OnCmdMsg(ID_FILE_PRINT, 0, 0, 0);

        How can I wait until the printing process has been finished? Background: In my dialog I want to be able to print other data than loaded into the current view. For this purpose, I save the state of the current view, load another document, print it and afterthe document has finished printing I reload the old document again and close the dialog. Thank you and regards, Niki

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        Printing is heavily abstracted in windows - this is one of the main selling points they had waaaaaaay back when. But that means you shove data at the print spooler - and you know when that is finished. But that may then shove data at some remote machine which may or may not complete then. That may then go to a fancy print system which could batch your print for late at night, for its own convenience. None of this gets fed back to you. You could do this:

        while (1)
        {
        if (MessageBox (_T("Has the paper come out yet?"), MB_YESNO | MB_ICONQUESTION) == IDYES)
        break;
        }

        Being slightly serious, the OnCmdMsg (ID_FILE_PRINT, 0, 0, 0) shouldn't return until it's finished its bit of the printing process. Iain.

        N 1 Reply Last reply
        0
        • I Iain Clarke Warrior Programmer

          Printing is heavily abstracted in windows - this is one of the main selling points they had waaaaaaay back when. But that means you shove data at the print spooler - and you know when that is finished. But that may then shove data at some remote machine which may or may not complete then. That may then go to a fancy print system which could batch your print for late at night, for its own convenience. None of this gets fed back to you. You could do this:

          while (1)
          {
          if (MessageBox (_T("Has the paper come out yet?"), MB_YESNO | MB_ICONQUESTION) == IDYES)
          break;
          }

          Being slightly serious, the OnCmdMsg (ID_FILE_PRINT, 0, 0, 0) shouldn't return until it's finished its bit of the printing process. Iain.

          N Offline
          N Offline
          nobaq
          wrote on last edited by
          #4

          Hello and thank you for your answer! I do not want to check if the document has printed successfully but it should just be successfully appended to the queue (before the new document is loaded). I think I managed this (the following code is done in a modal dialog):

          // pView is a pointer to my current view (CHtmlView)

          // get currently loaded document
          CString currentUrl = pView->GetLocationURL();
          // load document to be printed
          pView->Pall();
          // wait until the document has loaded successfully
          while(pView->GetReadyState() != READYSTATE_COMPLETE)
          {
          ((CMyApp*)AfxGetApp())->Yeild();
          }
          // FIXXXME: IS THIS OPERATION REALLY BLOCKING?
          pView->OnCmdMsg(ID_FILE_PRINT, 0, 0, 0);
          // restore old document
          pView->Navigate(currentUrl);
          // return to my app
          EndDialog(FALSE);

          The OnCmdMsg(ID_FILE_PRINT) does nothing more than ExecWB(OLECMDID_PRINT,...) in the IWebBrowser2. And now my "backup question" is. You said: "Being slightly serious, the OnCmdMsg (ID_FILE_PRINT, 0, 0, 0) shouldn't return until it's finished its bit of the printing process." Are you sure that ExecWB(OLECMDID_PRINT,...) will block until the currently loaded document has been printed so that I can issue the next Navigate(...) call just afterwards? In my tests it works but I am not sure about this. Regards, Niki

          I 1 Reply Last reply
          0
          • N nobaq

            Hello, In my application, I send a print command to my view from a (modal) dialog:

            pView->OnCmdMsg(ID_FILE_PRINT, 0, 0, 0);

            How can I wait until the printing process has been finished? Background: In my dialog I want to be able to print other data than loaded into the current view. For this purpose, I save the state of the current view, load another document, print it and afterthe document has finished printing I reload the old document again and close the dialog. Thank you and regards, Niki

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            You could obtain a PRINTER_INFO_2[^] structure which contains the number of jobs in the printer que. The Status member should return PRINTER_STATUS_PRINTING while printing and PRINTER_STATUS_WAITING when finished. If you wanted to track individual print jobs you could use the JOB_INFO_1[^] or other associated print job structures to track the job. The Status member will return JOB_STATUS_PRINTED when the job has completed. It should be noted that older printers and/or port monitor drivers may always return JOB_STATUS_PRINTED information for job status. Your mileage may vary. Some documentation: http://support.microsoft.com/kb/158828[^] Some sample code:

            #include <winspool.h>
            /************************************************************************************
            	HANDLE OpenDefaultPrinter(ACCESS_MASK dwMask)
            	Returns a HANDLE to the Default system printer. The caller must Close the HANDLE.
            	-David Delaune 12-06-2006
            *************************************************************************************/
            HANDLE YourClass::OpenDefaultPrinter(ACCESS_MASK dwMask)
            {
            	HANDLE hPrinter = INVALID_HANDLE_VALUE;
            	PRINTER_DEFAULTS pDef;
            	DWORD dwSize;
            
            	ZeroMemory(&pDef, sizeof(pDef));
                GetDefaultPrinter(NULL, &dwSize);
                
            	TCHAR* szBuffer = new TCHAR[dwSize];
            
            	if(NULL != szBuffer)
            	{
            		if(GetDefaultPrinter(szBuffer, &dwSize))
            		{
            			pDef.DesiredAccess = dwMask;
            			OpenPrinter(szBuffer, &hPrinter, &pDef);
            		}
            		delete szBuffer;
            	}
            	return hPrinter;
            }
            
            /************************************************************************************
            	DWORD GetPrintQueCount()
            	Returns the number of waiting print jobs in the Default printer que.
            	-David Delaune 12-06-2006
            *************************************************************************************/
            DWORD YourClass::GetPrintQueCount()
            {
            	DWORD dwNeeded = NULL;
            	PRINTER_INFO_2 *pInfo = NULL;
            	DWORD dwRet = 0;
            
            	HANDLE hPrinter = OpenDefaultPrinter();
            
            	if(INVALID_HANDLE_VALUE !=
            
            1 Reply Last reply
            0
            • N nobaq

              Hello and thank you for your answer! I do not want to check if the document has printed successfully but it should just be successfully appended to the queue (before the new document is loaded). I think I managed this (the following code is done in a modal dialog):

              // pView is a pointer to my current view (CHtmlView)

              // get currently loaded document
              CString currentUrl = pView->GetLocationURL();
              // load document to be printed
              pView->Pall();
              // wait until the document has loaded successfully
              while(pView->GetReadyState() != READYSTATE_COMPLETE)
              {
              ((CMyApp*)AfxGetApp())->Yeild();
              }
              // FIXXXME: IS THIS OPERATION REALLY BLOCKING?
              pView->OnCmdMsg(ID_FILE_PRINT, 0, 0, 0);
              // restore old document
              pView->Navigate(currentUrl);
              // return to my app
              EndDialog(FALSE);

              The OnCmdMsg(ID_FILE_PRINT) does nothing more than ExecWB(OLECMDID_PRINT,...) in the IWebBrowser2. And now my "backup question" is. You said: "Being slightly serious, the OnCmdMsg (ID_FILE_PRINT, 0, 0, 0) shouldn't return until it's finished its bit of the printing process." Are you sure that ExecWB(OLECMDID_PRINT,...) will block until the currently loaded document has been printed so that I can issue the next Navigate(...) call just afterwards? In my tests it works but I am not sure about this. Regards, Niki

              I Offline
              I Offline
              Iain Clarke Warrior Programmer
              wrote on last edited by
              #6

              I confess I have not printed from an HtmlView, so take my logic with some skepticism. From the docs: Executes a command on an OLE object and returns the status of the command execution using the IOleCommandTarget interface. It does not say "queue up some thready thing". So S_OK, means the job is *done*. Iain.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups