win32ui CreatePrintDialog

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

  1. 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.

    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?

    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.

    Thanks,
    Chris
     
    Chris Lambacher, Jul 15, 2005
    #1
    1. Advertising

  2. Chris Lambacher

    Eric Brunel Guest

    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.

    > 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...

    > 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+-'])"
     
    Eric Brunel, Jul 18, 2005
    #2
    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,622
    Fredrik Lundh
    Jun 27, 2003
  2. Howard Lightstone

    win32ui.CreatePrintDialog argument question

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

    win32ui.CreateFont() question

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

    Re: win32ui CreatePrintDialog

    Chris Lambacher, Jul 18, 2005, in forum: Python
    Replies:
    0
    Views:
    403
    Chris Lambacher
    Jul 18, 2005
Loading...

Share This Page