On Fri, 15 Jul 2005 18:08:35 -0400, Chris Lambacher <[EMAIL PROTECTED]> 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:

import win32ui
 from pywin.mfc import window, dialog

class WindowsPrintDialog(window.Wnd):

   # Numbers for various items in the dialog
   PRINTER_NAME    = 1139
   PRINT_TO_FILE   = 1040
   PRINT_ALL       = 1056
   PRINT_PAGES     = 1058
   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
     ## Activate all widgets
     for i in (WindowsPrintDialog.PRINT_ALL, WindowsPrintDialog.PRINT_PAGES,
               WindowsPrintDialog.FIRST_PAGE, WindowsPrintDialog.LAST_PAGE,
               WindowsPrintDialog.FROM_TEXT, WindowsPrintDialog.TO_TEXT,
       itm = self._obj_.GetDlgItem(i)
     ## Disable "Properties" button: it doesn't work...
     itm = self._obj_.GetDlgItem(WindowsPrintDialog.PROPERTIES_BTN)

   def OnOK(self):
     ## Call on dialog itself
     ## 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()
     ## And so on...

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

python -c "print ''.join([chr(154 - ord(c)) for c in 

Reply via email to