Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to know which printer user selected in ComDlg?
Message
From
25/09/2006 14:58:22
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
25/09/2006 14:34:40
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP1
Miscellaneous
Thread ID:
01155181
Message ID:
01157060
Views:
29
>Sorry, there were few things went wrong there, I was too tired that day (looking for an excuses <*g*>). It's not too critical, except for the one I pointed before. But wrong is wrong, right? <*vbg*>

A bit of a perfectionist, are you? :)

>To make it a little more safety, first, I'll change the sample call to this:
>
>If (nResult != 0)
>   hDevMode  = CToBin( substr( sPrintDlg,  9, 4 ), '4rs' )
>   hDevNames = CToBin( substr( sPrintDlg, 13, 4 ), '4rs' )
>
>   ** Make sure we don't get a NULL handle to DEVMODE, otherwise do not process
>   If (hDevMode != 0)
>      pDevMode = GlobalLock( hDevMode )
>      cPrinterName = sys( 2600, pDevMode, 32 )
>      GlobalUnlock( hDevMode )
>
>      nLen = at( chr(0), cPrinterName ) - 1
>      If (nLen > 0)
>         cPrinterName = left( cPrinterName, nLen )
>      endif
>      ? 'Selected Printer:', cPrinterName
>
>      GlobalFree( hDevMode )
>   endif
>
>   ** Same thing for DEVNAMES
>   If (hDevNames != 0)
>      GlobalFree( hDevNames )
>   endif
>else
>   ** Check for the PrintDlg error by calling CommDlgExtendedError()
>endif
>
>
>Now, in the handle to DEVNAMES structure, there is one field (wDeviceOffset) that also pointed to the printer name. I haven't try this, but you may need to check from that offset, because the "printer name" return from the DEVMODE is limited to 32 chars. If the name is longer than 32 chars, it might be stored in the DEVNAMES. But, again, I haven't try this myself because I don't have any printer that has names longer than 32. So, please do some more checking.

I have one printer with quite a long name (office document writer), and I saw this 32 limit - no big deal, as the actual printer name can be retrieved from the array returned by aPrinters(). A little aScan() does it.

>For W9X, Although it is still doable from VFP, I'm sorry to say you better skip it <*g*>. It's not that I don't want to tell you, but it needs to do a subclassed (also a hook for more robust solution). And simply can't be done from VFP. Searching the "Combo List Box" using timer is not reliable. Because the listbox is not a direct child of the Printer Dialog. Having said that, it's not that we can not subclassed right from VFP, but I really don't want start it because it's highly dangerous!

And despite all our best efforts, this whole thing was for nothing. The customer just said "we don't care about anyone printing to PDF, drop the matter". So... at least we have a nice trick for anyone who may want to use it in the future.

Thanks all the same!

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform