Advertisement

07.16.2008 at 07:29AM PDT, ID: 23569805
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Selecting a non-default printer in the printer dialog box using common dialog control

Asked by j22karuloom in Windows Programming, PowerBuilder Programming Language

Tags: , , ,

Hi!

I call printer window from code, which works fine. If the user selects a printer, I take the printer name and put into a global variable. When the user opens the dialog again, I would like the previously selected printer to be selected as well (but not to be made as a system default printer!).

I read an article http://msdn.microsoft.com/en-us/vcsharp/ms646843(VS.85).aspx, and it says: "..If both hDevMode and hDevNames are NULL, PrintDlg initializes the dialog box using the current default printer. To initialize the dialog box for a different printer, use the wDeviceOffset member of the DEVNAMES structure to specify the name of the printer."

I would like to make it work like it is suggested, but I don't know how.

I have added my code there: http://www.experts-exchange.com/Programming/Editors_IDEs/PowerBuilder/Q_23565856.html

I have modified the printdialog function, so I attached the snippet with the new snippet:Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
/*
 
Shows the print dialog box...
 
Members:
 
integer FromPage        // Print from page
integer ToPage          // Print to page
integer MinPage // Min page (smaller page)
integer MaxPage // Max page (higher page)
PROTECTEDWRITE integer Copies = 1 // Nº of copies to
print...
 
*/
 
PRINTDLG PrintDlg
DEVMODE DevMode
DEVNAMES DevNames
long pDevNames, pDevMode
blob lb_blob
string lst_prnlist, lst_prnname,  ls_temp, ls_fullstring
long ll_pos1, ll_pos2, ll_place
 
 
PrintDlg.lStructSize    = 66
PrintDlg.hWndOwner              = Handle(w_hidden)//hWndParent 
PrintDlg.hDevMode                       = 0
PrintDlg.hDevNames              = 0
PrintDlg.hDC                            = 0
PrintDlg.Flags                          = Flags
PrintDlg.nFromPage              = FromPage
PrintDlg.nToPage                        = ToPage
PrintDlg.nMinPage                       = MinPage
PrintDlg.nMaxPage                       = MaxPage
PrintDlg.nCopies                        = 0
PrintDlg.hInstance              = 0
PrintDlg.lCustData              = 0
PrintDlg.lpfnPrintHook  = 0
PrintDlg.lpfnSetupHook  = 0
PrintDlg.lpPrintTemplateName = "0"
PrintDlg.lpSetupTemplateName = "0"
PrintDlg.hPrintTemplate = 0
PrintDlg.hSetupTemplate = 0
 
 
if gst_userPrinterName = "" then
	ls_fullstring=PrintGetPrinter()
	
	ll_place=pos (ls_fullstring, "~t")
	gst_userPrinterName=left(ls_fullstring, ll_place -1)
	ls_temp=mid(ls_fullstring, ll_place +1)
	ll_place=pos (ls_temp, "~t")
	gst_userPrinterDriver=left(ls_temp, ll_place -1)
	gst_userPrinterPort=mid(ls_temp, ll_place +1)
end if
 
lst_prnlist  = PrintGetPrinters ( )
ll_pos1 = pos( lst_prnlist , "~n" )    
do while ll_pos1 > 0 
	ll_pos2 = pos( lst_prnlist , "~t" )
	lst_prnname = left( lst_prnlist, ll_pos2 -1 )
		  If lst_prnname = gst_userPrinterName Then
//					
		  End If							
	lst_prnlist = right( lst_prnlist, len( lst_prnlist ) - ll_pos1 )
	ll_pos1 = pos( lst_prnlist , "~n" )
loop
 
 
 
int ll_test
ll_test = PrintDlgA(PrintDlg)
 
if ll_test = 1 Then
	
		pDevMode = LocalLock(PrintDlg.hDevMode)
		GetDevMode(DevMode,pDevMode,148) // Lock dynamic memory handle
		LocalUnlock(pDevMode) // Unlock dynamic memory handle
		
		pDevNames = LocalLock(PrintDlg.hDevNames)
		GetDevNames(DevNames,pDevNames,8) // Lock dynamic memory handle
		LocalUnlock(pDevNames) // Unlock dynamic memory handle
 
        FromPage        = PrintDlg.nFromPage
        ToPage  = PrintDlg.nToPage
        MinPage         = PrintDlg.nMinPage
        MaxPage         = PrintDlg.nMaxPage
        Copies  = PrintDlg.nCopies
 
        If Copies = 1 Then // Copies are provided by devmode..
                Copies = DevMode.dmCopies
        End If
		
		int test
		test  = DevNames.wDeviceOffset
		test = test + pDevNames		
	
		ls_temp = String(pDevNames + DevNames.wDeviceOffset, "address" ) // format string
		lb_blob = blob(ls_temp, EncodingUTF16LE!)
		gst_userPrinterName = string(lb_blob, EncodingANSI!) // convert
		
		ls_temp =  String(pDevNames + DevNames.wDriverOffset,"address") // format string
		lb_blob = blob(ls_temp, EncodingUTF16LE!)
		gst_userPrinterDriver = string(lb_blob, EncodingANSI!) // convert
		
		ls_temp =String(pDevNames + DevNames.wOutPutOffset,"address") // format string
		lb_blob = blob(ls_temp, EncodingUTF16LE!)
		gst_userPrinterPort = string(lb_blob, EncodingANSI!) // convert		  
 
        //SetPrinter(gst_userPrinterName,gst_userPrinterDriver, //gst_userPrinterPort)
        Return(True)
End If  
 
Return(False)
[+][-]07.16.2008 at 11:30AM PDT, ID: 22018755

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Windows Programming, PowerBuilder Programming Language
Tags: sybase, powerbuilder, 11, powerscript
Sign Up Now!
Solution Provided By: sandeep_patel
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.17.2008 at 01:58AM PDT, ID: 22023479

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628