MTecho
asked on
PageSetupDlg problem
I'm trying to get the current paper size dimensions (Height, Width and/or PaperSize) from the common dialog control, using the CommonDialog.ShowPrinter method. Most printer dialog panels have a combo box where the user can select a paper size, so the setting from that combo box should be available to the programmer. For some reason the CommonDialog object does not have properties for reading this result. Is PageSetupDlg the correct API function for getting this, and if so, what error have I made in the following code? (It only gives zeroes.)
Is 'Pr.hwndOwner = CommonDialog.hDC' the correct method of setting the context for the PageSetupDlg structure?
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type Rect
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type
Public Type PageSetupDlg
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTAPI
rtMinMargin As Rect
rtMargin As Rect
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As String
hPageSetupTemplate As Long
End Type
Declare Function PageSetupDlg Lib "comdlg32.dll" Alias "PageSetupDlgA" (pPagesetupdlg As PageSetupDlg) As Long
Public Function GetPaperSize(hDC As Long) As POINTAPI
Dim Pr As PageSetupDlg, Suc As Long
Pr.hwndOwner = hDC
Suc = PageSetupDlg(Pr)
Debug.Print Suc, Pr.ptPaperSize.X, Pr.ptPaperSize.Y
GetPaperSize = Pr.ptPaperSize
End Function
Which can be called by:
Private Sub Print()
Dim PrSz As POINTAPI
On Error GoTo PrintError
'
CommonDialog.CancelError = True
CommonDialog.flags = cdlPDHidePrintToFile + cdlPDSelection + cdlPDReturnDC
CommonDialog.ShowPrinter
Printer.Orientation = CommonDialog.Orientation
PrSz = GetPaperSize(CommonDialog. hDC)
Printer.Height = PrSz.Y
Printer.Width = PrSz.X
'
' Print statements
'
Printer.EndDoc
Exit Sub
'
PrintError:
Select Case Err.Number
Case 32755
'MsgBox "Print cancelled."
End Select
Exit Sub
End Sub
Can anyone help?
Is 'Pr.hwndOwner = CommonDialog.hDC' the correct method of setting the context for the PageSetupDlg structure?
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type Rect
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type
Public Type PageSetupDlg
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTAPI
rtMinMargin As Rect
rtMargin As Rect
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As String
hPageSetupTemplate As Long
End Type
Declare Function PageSetupDlg Lib "comdlg32.dll" Alias "PageSetupDlgA" (pPagesetupdlg As PageSetupDlg) As Long
Public Function GetPaperSize(hDC As Long) As POINTAPI
Dim Pr As PageSetupDlg, Suc As Long
Pr.hwndOwner = hDC
Suc = PageSetupDlg(Pr)
Debug.Print Suc, Pr.ptPaperSize.X, Pr.ptPaperSize.Y
GetPaperSize = Pr.ptPaperSize
End Function
Which can be called by:
Private Sub Print()
Dim PrSz As POINTAPI
On Error GoTo PrintError
'
CommonDialog.CancelError = True
CommonDialog.flags = cdlPDHidePrintToFile + cdlPDSelection + cdlPDReturnDC
CommonDialog.ShowPrinter
Printer.Orientation = CommonDialog.Orientation
PrSz = GetPaperSize(CommonDialog.
Printer.Height = PrSz.Y
Printer.Width = PrSz.X
'
' Print statements
'
Printer.EndDoc
Exit Sub
'
PrintError:
Select Case Err.Number
Case 32755
'MsgBox "Print cancelled."
End Select
Exit Sub
End Sub
Can anyone help?
Seems no text problem is resolved
Computer101
E-E Admin
Computer101
E-E Admin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Proposed answer rejected. Please refer to the bottom of the page
Computer101
E-E Admin
Computer101
E-E Admin
I do not understand you Computer101. My answer is a solution to the problem stated. Let the person who the answer is directed to comment on the worthiness of my answer. If this is the way people are treated when they provide answers then why should I continue to help out?
Courtesy to other experts who post comments. Are you sure you are correct in the solution. It is customary to post comments vs answers as stated below and that is my points. You have proposed answers in all the questions you have participated in. From here on out, we can deal with this via e-mail. No more in any of the questions, if so, I will deal with it. You can contact me at Computer101@experts-exchan ge.com
Thank you
Computer101
E-E Admin
Thank you
Computer101
E-E Admin
ASKER
This is basically the same as the other question. I reposted it to get rid of all the other comments which might have confused the issue.
I thought PageSetupDlg was not the way to go. That is probably what programs such as MS Word use when you select 'Page Setup...' on the 'File' menu.
I thought PageSetupDlg was not the way to go. That is probably what programs such as MS Word use when you select 'Page Setup...' on the 'File' menu.