Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > win32ui CreatePrintDialog

Reply
Thread Tools

win32ui CreatePrintDialog

 
 
Chris Lambacher
Guest
Posts: n/a
 
      07-15-2005
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(153
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
 
Reply With Quote
 
 
 
 
Eric Brunel
Guest
Posts: n/a
 
      07-18-2005
On Fri, 15 Jul 2005 18:08:35 -0400, Chris Lambacher <(E-Mail Removed)> 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(153
> 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(153
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.PROPERTIE S_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_NAM E)
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+-'])"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: win32ui CreatePrintDialog Chris Lambacher Python 0 07-18-2005 01:35 PM
win32ui.CreateFont() question Chris Gonnerman Python 0 11-21-2003 01:48 PM
win32ui CreateFileDialog Can't Set Dir EricP Python 1 10-28-2003 06:37 AM
win32ui.CreatePrintDialog argument question Howard Lightstone Python 0 06-28-2003 10:08 PM
win32ui screen capture Me Mine Python 3 06-27-2003 08:10 AM



Advertisments