469,920 Members | 2,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,920 developers. It's quick & easy.

win32ui CreatePrintDialog

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
Jul 21 '05 #1
1 3167
On Fri, 15 Jul 2005 18:08:35 -0400, Chris Lambacher <la******@computer.org> 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.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+-'])"
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Me Mine | last post: by
reply views Thread by Howard Lightstone | last post: by
1 post views Thread by EricP | last post: by
reply views Thread by Chris Gonnerman | last post: by
2 posts views Thread by Darcy Kahle | last post: by
reply views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.