Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #5024

Re: How can I send a print to a different printer than the default printer?

From "Francesco F." <francescangeli.f.remove@remove.gmail.com>
Newsgroups comp.lang.clipper.visual-objects
Subject Re: How can I send a print to a different printer than the default printer?
Date 2013-04-07 10:22 +0200
Organization albasani.net
Message-ID <kjrad2$97o$1@news.albasani.net> (permalink)
References <7a681a35-d25f-435c-a7bd-7e5e218fadb8@googlegroups.com> <kjgi0g$tdl$1@news.albasani.net> <ebe627df-6afb-40cf-a640-10f671b8b1ad@googlegroups.com>

Show all headers | View raw


George,
no idea why...
Anyway, digging in the past, I found an interesting thread opened by 
Andy Rintoul in 2002 with a couple of functions, SetPrinter and 
GetPrinter, that seem to be what you're looking for; here they are:
--------------------------------------------------------------------------------
FUNCTION SetW2KDefPrinter(cPrinter AS STRING) AS LOGIC
// Set the given printer to be the default printer
// cPrinter: name of printer to be made default
// returns whether successful

LOCAL done AS LOGIC
LOCAL hModule AS PTR
LOCAL pSet AS PSZ PTR 	
LOCAL pszPrinter AS PSZ PTR
LOCAL pszError AS PSZ

done := FALSE

hModule := _VOLoadLibrary(String2Psz("winspool.drv"))//.drv NOT .dll
IF hModule == NULL_PTR
	done := FALSE
     // Show error msg
ELSE	
     pSet := GetProcAddress(hModule, PSZ("SetDefaultPrinterA"))
     // "SetDefaultPrinterW" for UNICODE
     IF pSet == NULL_PTR
       	done := FALSE
       	// Show error msg
     ELSE
       	pszPrinter := PSZ(cPrinter)
       	IF PCALL(pSet, pszPrinter) = NULL_PTR
			done := FALSE
         	FormatMessage(  ;
	  					FORMAT_MESSAGE_ALLOCATE_BUFFER + FORMAT_MESSAGE_FROM_SYSTEM,;
			      	  	NULL,;
     	  				GetLastError(),;
     	 				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),; // Default language
     	  				@pszError,;
     	  				0,;
     	  				NULL)
			// Show error msg including pszError
		  	LocalFree(pszError)
       	ELSE
			Done := TRUE	
       	ENDIF	
       	// Tell all open programs about the change	
       	SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0L, 0L,;
                            SMTO_NORMAL, 1000, NULL)
	ENDIF	
ENDIF

RETURN done
--------------------------------------------------------------------------------
FUNCTION GetW2KDefPrinter() AS STRING
LOCAL hModule AS PTR
LOCAL pGet AS PSZ PTR  		
LOCAL cPrinter AS STRING
LOCAL dwNeeded AS DWORD
LOCAL PrintBuff AS PSZ PTR

dwNeeded := 0	//geoff's suggest

hModule := _VOLoadLibrary(String2Psz("winspool.drv"))	//.drv NOT .dll
IF hModule == NULL_PTR
     // Show error msg
ELSE	
     pGet := GetProcAddress(hModule, PSZ("GetDefaultPrinterA"))
     // "GetDefaultPrinterW" for UNICODE
     IF pGet == NULL_PTR
       	// Show error msg
     ELSE
       	PCALL(pGet, NULL_PSZ, @dwNeeded)
       	IF dwNeeded > 0
         	PrintBuff := PSZ(Space(dwNeeded))
         	PCALL(pGet, PrintBuff, @dwNeeded)
         	IF PrintBuff == NULL_PTR
           		// Show error msg
         	ELSE
	  			cPrinter := Psz2String(PrintBuff)
         	ENDIF	
       	ELSE
         	// Show error msg
       	ENDIF
     ENDIF
ENDIF	

RETURN cPrinter
--------------------------------------------------------------------------------
(not well indented, but...)
It compiles without errors in 2.7.
The functions were written for W2K, but I suppose they'll work on Win7 
too; I've no time to make a try, so let me know.
HTH,
Francesco


Il 06/04/2013 20:22, BGeorge ha scritto:
> Francesco,
> I put in cPrinter the oPrinter:Device and always return done=FALSE.
> I don't know why. Any ideas?
>
> Regards,
> George
>

Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How can I send a print to a different printer than the default printer? BGeorge <bgeorge21@in.gr> - 2013-04-02 13:53 -0700
  Re: How can I send a print to a different printer than the default printer? "Francesco F." <francescangeli.f.remove@remove.gmail.com> - 2013-04-03 08:25 +0200
    Re: How can I send a print to a different printer than the default printer? BGeorge <bgeorge21@in.gr> - 2013-04-06 11:22 -0700
      Re: How can I send a print to a different printer than the default printer? "Francesco F." <francescangeli.f.remove@remove.gmail.com> - 2013-04-07 10:22 +0200
  Re: How can I send a print to a different printer than the default printer? marc3l0 <mmarloch@gmail.com> - 2013-05-09 06:59 -0700

csiph-web