forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Printer selection dialog

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
jwfv
Valued Contributor
Valued Contributor


Joined: 19 Mar 2002
Posts: 422
Location: Beaufort, SC

PostPosted: Tue Mar 11, 2003 2:54 pm    Post subject: Printer selection dialog Reply with quote

I need to be able to allow a user to choose a printer to set a code in a parameter to pass to an outside program. I looked through descriptions of some .dll's and couldn't find a printer selection dialog.

Does anyone know of a way to do this in VDS?

Thanks.
Back to top
View user's profile Send private message
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Tue Mar 11, 2003 10:30 pm    Post subject: Reply with quote

Hi jwfv,
Here is some code that you can call the Printer common dialog with. It uses my Gadget.dll... If you have any questions and I am sure you will please send me a PM I will be glad to help you with it.

Code:
#-----------------------------------------------------------------------------#
#                                                                             #
# Demo of how to show the Print Dialog and how to capture user changes        #
#                                                                             #
# Author:  Johnny Kinsey                                                      #
#                                                                             #
# Copyright: Copyright © 2007 DragonSphere Software                           #
#                                                                             #
#-----------------------------------------------------------------------------#

Title The Print Dialog
External gadgetx.dll,5.0
#DEFINE COMMAND,SET,CALL,MEM,FREEDLL,DEFINE,STRUCTURE
#DEFINE FUNCTION,GET,CALL,MEM,LOADDLL,AND,OR,ADDROF,SIZEOF

#DEFINE COMMAND,ShowPrintDlg

:BeginInit
Define Variable,Handle,comdlg32
Define Variable,Handle,gdi32
Define Variable,Handle,kernel32
Set comdlg32,@LoadDLL(comdlg32.dll)
Set gdi32,@LoadDLL(gdi32.dll)
Set kernel32,@LoadDLL(kernel32.dll)
:CONST
Define Constant,TRUE,1
Define Constant,FALSE,0

Define Constant,PD_ALLPAGES,0
Define Constant,PD_SELECTION,1
Define Constant,PD_PAGENUMS,2
Define Constant,PD_NOSELECTION,4
Define Constant,PD_NOPAGENUMS,8
Define Constant,PD_COLLATE,$10
Define Constant,PD_PRINTTOFILE,$20
Define Constant,PD_PRINTSETUP,$40
Define Constant,PD_NOWARNING,$80
Define Constant,PD_RETURNDC,$100
Define Constant,PD_RETURNIC,$200
Define Constant,PD_RETURNDEFAULT,$400
Define Constant,PD_SHOWHELP,$800
Define Constant,PD_ENABLEPRINTHOOK,$1000
Define Constant,PD_ENABLESETUPHOOK,$2000
Define Constant,PD_ENABLEPRINTTEMPLATE,$4000
Define Constant,PD_ENABLESETUPTEMPLATE,$8000
Define Constant,PD_ENABLEPRINTTEMPLATEHANDLE,$10000
Define Constant,PD_ENABLESETUPTEMPLATEHANDLE,$20000
Define Constant,PD_USEDEVMODECOPIES,$40000
Define Constant,PD_USEDEVMODECOPIESANDCOLLATE,$40000
Define Constant,PD_DISABLEPRINTTOFILE,$80000
Define Constant,PD_HIDEPRINTTOFILE,$100000
Define Constant,PD_NONETWORKBUTTON,$200000

Define Constant,DN_DEFAULTPRN,1
rem   size of a device name string
Define Constant,CCHDEVICENAME,32

rem   size of a form name string
Define Constant,CCHFORMNAME,32
Define Constant,GMEM_FIXED,$0
Define Constant,GMEM_MOVEABLE,$2
Define Constant,GMEM_NOCOMPACT,$10
Define Constant,GMEM_NODISCARD,$20
Define Constant,GMEM_ZEROINIT,$40
Define Constant,GMEM_MODIFY,$80
Define Constant,GMEM_DISCARDABLE,$100
Define Constant,GMEM_NOT_BANKED,$1000
Define Constant,GMEM_SHARE,$2000
Define Constant,GMEM_DDESHARE,$2000
Define Constant,GMEM_NOTIFY,$4000
Define Constant,GMEM_LOWER,@Get(GMEM_NOT_BANKED)
Define Constant,GMEM_VALID_FLAGS,$7F72
Define Constant,GMEM_INVALID_HANDLE,$8000

Define Constant,GHND,@Or(GMEM_MOVEABLE,GMEM_ZEROINIT)
Define Constant,GPTR,@Or(GMEM_FIXED,GMEM_ZEROINIT)

rem  Flags returned by GlobalFlags (in addition to GMEM_DISCARDABLE)
Define Constant,GMEM_DISCARDED,$4000
Define Constant,GMEM_LOCKCOUNT,$FF

:STRUCTURES
Rem PRINTDLG structure
Define Structure,pd,Long|lStructSize
   Structure Add,pd,Handle|hwndOwner
   Structure Add,pd,HANDLE|hDevMode
   Structure Add,pd,HANDLE|hDevNames
   Structure Add,pd,HANDLE|hdc
   Structure Add,pd,DWORD|flags
   Structure Add,pd,Word|nFromPage
   Structure Add,pd,Word|nToPage
   Structure Add,pd,Word|nMinPage
   Structure Add,pd,Word|nMaxPage
   Structure Add,pd,Word|nCopies
   Structure Add,pd,Long|hInstance
   Structure Add,pd,Long|lCustData
   Structure Add,pd,Long|lpfnPrintHook
   Structure Add,pd,Long|lpfnSetupHook
   Structure Add,pd,Pointer|lpPrintTemplateName
   Structure Add,pd,Pointer|lpSetupTemplateName
   Structure Add,pd,Long|hPrintTemplate
   Structure Add,pd,Long|hSetupTemplate

Define Structure,pdex,Long|lStructSize
   Structure Add,pdex,Handle|hwndOwner
   Structure Add,pdex,HANDLE|hDevMode
   Structure Add,pdex,HANDLE|hDevNames
   Structure Add,pdex,HANDLE|hdc
   Structure Add,pdex,DWORD|flags
   Structure Add,pdex,DWORD|Flags2
   Structure Add,pdex,DWORD|ExclusionFlags
   Structure Add,pdex,DWORD|nPageRanges
   Structure Add,pdex,DWORD|nMaxPageRanges
   Structure Add,pdex,Pointer|lpPageRanges
   Structure Add,pdex,DWORD|nMinPage
   Structure Add,pdex,DWORD|nMaxPage
   Structure Add,pdex,DWORD|nCopies
   Structure Add,pdex,HANDLE|hInstance
   Structure Add,pdex,String|lpPrintTemplateName
   Structure Add,pdex,Pointer|lpCallback
   Structure Add,pdex,DWORD|nPropertyPages
   Structure Add,pdex,Pointer|lphPropertyPages
   Structure Add,pdex,DWORD|nStartPage
   Structure Add,pdex,DWORD|dwResultAction
   
Define Structure,DEVMODE,BYTE|dmDeviceName[@Get(CCHDEVICENAME)]
   Structure Add,DEVMODE,BYTE|dmDeviceName[@Get(CCHDEVICENAME)]
   Structure Add,DEVMODE,Word|dmSpecVersion
   Structure Add,DEVMODE,Word|dmDriverVersion
   Structure Add,DEVMODE,Word|dmSize
   Structure Add,DEVMODE,Word|dmDriverExtra
   Structure Add,DEVMODE,DWORD|dmFields
   Structure Add,DEVMODE,Short|dmOrientation
   Structure Add,DEVMODE,Short|dmPaperSize
   Structure Add,DEVMODE,Short|dmPaperLength
   Structure Add,DEVMODE,Short|dmPaperWidth
   Structure Add,DEVMODE,Short|dmScale
   Structure Add,DEVMODE,Short|dmCopies
   Structure Add,DEVMODE,Short|dmDefaultSource
   Structure Add,DEVMODE,Short|dmPrintQuality
   Structure Add,DEVMODE,Short|dmColor
   Structure Add,DEVMODE,Short|dmDuplex
   Structure Add,DEVMODE,Short|dmYResolution
   Structure Add,DEVMODE,Short|dmTTOption
   Structure Add,DEVMODE,Short|dmCollate
   Structure Add,DEVMODE,BYTE|dmFormName[@Get(CCHFORMNAME)]
   Structure Add,DEVMODE,Word|dmUnusedPadding
   Structure Add,DEVMODE,DWORD|dmBitsPerPel
   Structure Add,DEVMODE,DWORD|dmPelsWidth
   Structure Add,DEVMODE,DWORD|dmPelsHeight
   Structure Add,DEVMODE,DWORD|dmDisplayFlags
   Structure Add,DEVMODE,DWORD|dmDisplayFrequency
   Structure Add,DEVMODE,DWORD|dmICMMethod
   Structure Add,DEVMODE,DWORD|dmICMIntent
   Structure Add,DEVMODE,DWORD|dmMediaType
   Structure Add,DEVMODE,DWORD|dmDitherType
   Structure Add,DEVMODE,DWORD|dmReserved1
   Structure Add,DEVMODE,DWORD|dmReserved2
   
Define Structure,DEVNAMES,Word|wDriverOffset
   Structure Add,DEVNAMES,Word|wDriverOffset
   Structure Add,DEVNAMES,Word|wDeviceOffset
   Structure Add,DEVNAMES,Word|wOutputOffset
   Structure Add,DEVNAMES,Word|wDefault

:DECLARES
Define Function,BOOL,comdlg32,PrintDlg,PrintDlg,Pointer|pPrintdlg
Define Function,DWORD,gdi32,DeleteDC,DeleteDC,DWORD|hdc
Define Function,HANDLE,kernel32,GlobalAlloc,GlobalAlloc,DWORD|wFlags,DWORD|dwBytes
Define Function,DWORD,kernel32,GlobalFree,GlobalFree,HANDLE|hMem
Define Function,Pointer,kernel32,GlobalLock,GlobalLock,HANDLE|hMem
Define Function,DWORD,kernel32,GlobalUnlock,GlobalUnlock,HANDLE|hMem

:EndInit

:MAIN
  DIALOG CREATE,Show Print Dialog,-1,0,304,160
  DIALOG ADD,BUTTON,BUTTON1,72,124,64,24,Print
  DIALOG ADD,BUTTON,BUTTON2,112,124,64,24,Quit
  DIALOG ADD,TEXT,TEXT1,8,12,276,52,Printer DC:
  DIALOG SHOW
  %%hwnd = @winexists(Show Print Dialog)
:evloop
  wait event,0.003
  %E = @event()
  if %E
   goto %E
  End
goto evloop
:TIMER
goto evloop
:BUTTON1BUTTON
  ShowPrintDlg
Goto evloop
:BUTTON2BUTTON
:CLOSE
  FreeDLL comdlg32
  FreeDLL gdi32
Stop 
:ShowPrintDlg
  Rem After you insert the code between :BeginInit and :EndInit at the begining of your source
  Rem the just drop this sub-routine at the bottom of your source somewhere to call the Printer
  Rem common dialog box.

  Rem Set the pd structure to all zero's
  Mem Set,@AddrOf(pd),NULL,@SizeOf(pd)
  Rem Initialize the pd structure with some default settings
  Set pd.lStructSize,@SizeOf(pd)
  Set pd.hwndOwner,%%hwnd

  Set pd.hDevMode,@Call(GlobalAlloc,GHND,@SizeOf(DEVMODE))
  %%PMODE = @Call(GlobalLock,pd.hDevMode)
  Mem Copy,%%PMODE,@AddrOf(DEVMODE),@SizeOf(DEVMODE)
  %%PMODE = @Call(GlobalUnlock,pd.hDevMode)
 
  Set pd.hDevNames,@Call(GlobalAlloc,GHND,@SizeOf(DEVNAMES))
  %%PNAMES = @Call(GlobalLock,pd.hDevNames)
  Mem Copy,%%PNAMES,@AddrOf(DEVNAMES),@SizeOf(DEVNAMES)
  %%PNAMES = @Call(GlobalUnlock,pd.hDevNames)

  Rem I added the PD_RETURNDC so you can render bitmaps to this device context with GDI functions if you want to
  Set pd.flags,@Or(PD_ALLPAGES,PD_RETURNDC)
  Set pd.nCopies,1
  Set pd.nFromPage,1
  Set pd.nToPage,$FFFF
  Set pd.nMinPage,1
  Set pd.nMaxPage,$FFFF
  %%prntdlg = @Call(PrintDlg,pd)
  if @Equal(%%prntdlg,@Get(TRUE))
    Rem If the user choose a printer or clicked the print button then we can
    Rem inspect things about the printer before we actually print anything
    %%pMode = @Call(GlobalLock,pd.hDevMode)
    Mem Copy,@AddrOf(DEVMODE),%%pMode,@SizeOf(DEVMODE)
    %%pMode = @Call(GlobalUnlock,pd.hDevMode)
    %%pNames = @Call(GlobalLock,pd.hDevNames)
    Mem Copy,@AddrOf(DEVNAMES),%%pNames,@SizeOf(DEVNAMES)
    %%pNames = @Call(GlobalUnlock,pd.hDevNames)
    rem GDI calls to render output.

    rem Delete Device Context when done.
    Dialog set,TEXT1,Printer DC: @Get(pd.hdc)@CHR(13)@CHR(10)Printer Name: @Get(DEVMODE.dmDeviceName)@CHR(13)@CHR(10)Num Copies: @Get(DEVMODE.dmCopies)@CHR(13)@CHR(10)From Page @Get(pd.nFromPage) to @Get(pd.nToPage)
    %%Ret = @Call(DeleteDC,pd.hdc)
    %%pMode = @Call(GlobalFree,pd.hDevMode)
    %%pNames = @Call(GlobalFree,pd.hDevNames)
  End
Exit


This code has been updated to work with GadgetX.dll 05/08/2007

Have fun Wink

_________________
Home of

Give VDS a new purpose!


Last edited by vdsalchemist on Tue May 08, 2007 3:36 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Tue Mar 11, 2003 10:58 pm    Post subject: Reply with quote

Not sure if this will help, but LIST PRINT opens
a printer dialog...

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
jwfv
Valued Contributor
Valued Contributor


Joined: 19 Mar 2002
Posts: 422
Location: Beaufort, SC

PostPosted: Wed Mar 12, 2003 4:18 am    Post subject: Thanks much. Reply with quote

Hey - thanks for the replies. I'll check out the gadget.dll option.

By the way, the more little utility programs I write with VDS, the more I like this language. I have written a program with VDS that generates 3-page contracts for a finance company. It was to replace a DOS Clipper app that had been running for years, with increasing problems with each new version of Windows.

I have distributed the VDS app to about 10 offices, with a total of around 30 users on a daily basis. It runs on every form of Windows practically flawlessly. I have had to tweak the code as I've learned more, but the program looks very professional and best of all does exactly what it is supposed to do, simply and straightforwardly.

Making my life easier .... Cool
Back to top
View user's profile Send private message
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Wed Mar 12, 2003 10:20 am    Post subject: Reply with quote

i too love vds - it's simplicity and ease of use + its power thanks to the many free dll's that generous folks have put together for us Smile

Serge

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Wed Mar 12, 2003 1:35 pm    Post subject: Reply with quote

Mac wrote:
Not sure if this will help, but LIST PRINT opens
a printer dialog...

Cheers, Mac Smile


Yep your right Mac but I was not sure if he needed to get information back about what printer and settings that the user choose Question So that is why I posted the script above. If all he wants to do is print something then List Print will work but if he needs information about the printer to pass to another program or allign something then he will need to use Gadget. Unless someone uses my code above again to make a VDS DLL...

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Tue May 08, 2007 3:42 pm    Post subject: Print Dialog code updated Reply with quote

Hi All,
I have updated my code above to work with GadgetX and VDS 5. Have fun...

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group