Re: win32ui CreatePrintDialog

Discussion in 'Python' started by Chris Lambacher, Jul 18, 2005.

  1. On Mon, Jul 18, 2005 at 09:18:45AM +0200, Eric Brunel wrote:
    > On Fri, 15 Jul 2005 18:08:35 -0400, Chris Lambacher <> wrote:
    >
    > > Hi,
    > >
    > > This question has come up a few times on the list with no one giving a public
    > > answer. How do you use CreatePrintDialog from win32ui?
    > >
    > > About a year ago someone posted that:
    > > dlg = win32ui.CreatePrintDialog(1538)
    > > dlg.DoModal()
    > >
    > > will give you the window, but the ok button does not work.

    >
    > Here is what I did to make it work:
    >
    > <code>
    > import win32ui
    > from pywin.mfc import window, dialog
    >
    > class WindowsPrintDialog(window.Wnd):
    >
    > # Numbers for various items in the dialog
    > PROPERTIES_BTN = 1025
    > PRINTER_NAME = 1139
    > PRINT_TO_FILE = 1040
    > PRINT_ALL = 1056
    > PRINT_PAGES = 1058
    > PRINT_SELECTION = 1057
    > FIRST_PAGE = 1152
    > LAST_PAGE = 1153
    > FROM_TEXT = 1089
    > TO_TEXT = 1090
    > NB_COPIES = 1154
    >
    > def __init__(self):
    > dlg = = win32ui.CreatePrintDialog(1538)
    > window.Wnd.__init__(self, printDlg)
    >
    > def OnInitDialog(self):
    > ## Initialize dialog itself
    > self._obj_.OnInitDialog()
    > ## Activate all widgets
    > for i in (WindowsPrintDialog.PRINT_ALL, WindowsPrintDialog.PRINT_PAGES,
    > WindowsPrintDialog.FIRST_PAGE, WindowsPrintDialog.LAST_PAGE,
    > WindowsPrintDialog.FROM_TEXT, WindowsPrintDialog.TO_TEXT,
    > WindowsPrintDialog.PRINT_SELECTION):
    > itm = self._obj_.GetDlgItem(i)
    > itm.EnableWindow()
    > ## Disable "Properties" button: it doesn't work...
    > itm = self._obj_.GetDlgItem(WindowsPrintDialog.PROPERTIES_BTN)
    > itm.EnableWindow(0)
    >
    > def OnOK(self):
    > ## Call on dialog itself
    > self._obj_.OnOK()
    > self._obj_.UpdateData(1)
    > ## Now you can get values entered in dialog via:
    > ## - self.IsDlgButtonChecked(<id>) pour check-buttons
    > ## - self.GetDlgItemText(<id>) for textual fields
    > ## - self.GetDlgItemInt(<id>) for integer fields
    > ## Then use these info. to create your printer DC; for example:
    > printerName = self.GetDlgItemText(WindowsPrintDialog.PRINTER_NAME)
    > dc = win32ui.CreateDC()
    > dc.CreatePrinterDC(printerName)
    > ## And so on...
    > </code>
    >
    > Note that the printer properties button is explicitely disabled. If it's not, it seems to be working (it actually opens the printer properties dialog and all options can be modified without any error), but actually doesn't change a thing: the printing will be done with the printer default settings. If anybody has any idea on how this thing works, please let me know: I'm very interested.
    >

    In the MFC documentation, CPrintDialog has a GetPrinterDC method. This method
    AFAICT gives you a printer device contex which has all the settings set for you.

    > > Diging into the source shows that the 1538 is being loaded as a template
    > > resource. The MSDN documentation does not say anything about this being
    > > neccessary and in fact, other common dialogs provide this as an option, but
    > > not a requirement. Why is this made a requirement? If it was not made a
    > > requirement, would the dialog work?

    >
    > I guess it would just be a matter of giving the default value 1538 to the idRes parameter in win32ui.CreatePrintDialog; AFAICT, this is always the id for the default print dialog. Can't figure out why it was not done in the first place...
    >

    The problem is that 1538 is loaded as a template resource. I get exactly the
    same result from many resources all the way up to 20000 (I tried them in a
    loop). I suspect that this number just works because it is an ever present
    resource id, and does not actually do anything to help us. When used in
    conjuntion with the rest of the MFC printing framework, the dialog seems to
    work, but this does not help me because the rest of my application is in
    PyGTK, I would rather limit my MFC programming to the bare minimum. If I
    could get the PrintDlg function to work, I would use that instead.
    Unfortunately I can't figure out how to make that work either. I may just
    have to pull out MinGW and compile a module that uses the PrintDlg function.


    > > Unfortunately I can't play with this because I don't have Visual Studio. I
    > > guess the logical next step, if the above worked, would be to add the
    > > GetPrinterDC() method (and maybe some others) so that we can do something
    > > useful with the dialog.

    >
    > Yep. See above.
    >
    > > Thanks,
    > > Chris

    >
    > HTH
    > --
    > python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
    > --
    > http://mail.python.org/mailman/listinfo/python-list


    ----- End forwarded message -----
     
    Chris Lambacher, Jul 18, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Me Mine

    win32ui screen capture

    Me Mine, Jun 27, 2003, in forum: Python
    Replies:
    3
    Views:
    6,706
    Fredrik Lundh
    Jun 27, 2003
  2. Howard Lightstone

    win32ui.CreatePrintDialog argument question

    Howard Lightstone, Jun 28, 2003, in forum: Python
    Replies:
    0
    Views:
    750
    Howard Lightstone
    Jun 28, 2003
  3. EricP
    Replies:
    1
    Views:
    456
    Roger Upole
    Oct 28, 2003
  4. Chris Gonnerman

    win32ui.CreateFont() question

    Chris Gonnerman, Nov 21, 2003, in forum: Python
    Replies:
    0
    Views:
    458
    Chris Gonnerman
    Nov 21, 2003
  5. Chris Lambacher

    win32ui CreatePrintDialog

    Chris Lambacher, Jul 15, 2005, in forum: Python
    Replies:
    1
    Views:
    337
    Eric Brunel
    Jul 18, 2005
Loading...

Share This Page