473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 3721
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Me Mine | last post by:
i, I have trying to code a small console app that will allow a user to select a window and then create a screen capture of the window. I haven't been able to figure out how to do the screen...
0
by: Howard Lightstone | last post by:
I am trying to use the CreatePrintDialog routine to initialize a device context for the (default) printer but ..... I can't figure out the arguments. win32ui.CreatePrintDialog The first...
1
by: EricP | last post by:
I get the following error when I run this script to open a file dialog. I've searched the web and news groups for this issue and have not found any references. I get the same behavior when I run...
0
by: Chris Gonnerman | last post by:
I am rewriting an antique BASIC program in Python for a customer. The main feature of the program is printing a work order for a particular assembly; the BASIC program uses IBM OEM line-drawing...
2
by: Darcy Kahle | last post by:
I am trying to do some advanced printing in python using the win32ui module, and have run into an issue. I need to print a page landscape. As I could not determine how to specify the orientation...
3
by: MsKitty | last post by:
My client is used to clicking on the script name on her PC and getting a windows command line box which it runs in. Not fancy but did the job until recently... Now it can take up to 4 minutes...
4
by: Joey C. | last post by:
Hello. I'm writing a program that creates a series of batch operations to convert movies to be used on iPodLinux. The programs that do the encoding and conversions are seperate from mine and all...
3
by: robert | last post by:
As soon as I install wxPython on a Py2.3.5, my win32ui / win32gui apps freak out. buttons in dialogs are magically pressed. backgrounds of dialogs are colored wrong... this is with current...
5
by: nobugus | last post by:
Just posting a solution to the problem of capturing the whole virtual screen area, including all monitors with python and pywin32. Because this doesn't work even with PIL's imagegrab module. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.