Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using the Selprint Method of a RichText Control
Message
From
16/09/1999 12:17:31
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
16/09/1999 11:49:10
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
00199808
Message ID:
00265515
Views:
16
>>>I am sure this has been answered before but I missed it.
>>>
>>>I need to use the selprint function of a RichText Control.
>>>Unfortunately it requires the following
>>>
>>>hdc -- Thedevice context of the device you plan to use to print the
>>>contents of the control.
>>>
>>>and
>>>
>>>Note If you use the Printer object as the destination of the text
>>>from the RichTextBox control, you must first initialize the device
>>>context of the Printer object by printing something like a zero-length
>>>string.
>>>
>>>Assuming I have the name of the printer or I just want to print to the
>>>default printer.
>
>>
declare integer CreateDC in Win32API ;
>>    string @ lpszDriver,	;
>>    string @ lpszDevice,	;
>>    string @ lpszOutput,	;
>>    string @ lpInitData
>>declare integer DeleteDC in Win32API ;
>>    integer hDc
>>declare integer GetDeviceCaps in Win32API ;
>>    integer  hdc, integer  nIndex
>>
>>#define DRIVERVERSION 0
>>#define TECHNOLOGY    2
>>
>>lpszDriver="WINSPOOL"
>>lpszDevice=getprinter()
>>hDC = CreateDC(lpszDriver, lpszDevice, 0, 0)
>>? hDc                        && If succesfull not NULL
>>? GetDeviceCaps(hDC, DRIVERVERSION)
>>? GetDeviceCaps(hDC, TECHNOLOGY) && 2 Rasterprinter 0 Vectorplotter
>>=DeleteDC(hDC)
This works and gets hDC but still I can't use selprint. MS KB says you cannot print under Win95 but WinNT and under investigation. June 18, 1997 Article ID: Q170126 (I don't have newer). Feedback me if you succeed :)
>>Cetin
>
>I'm sort of late-jumping into this thread, but now I need it, so I'd like to know if anything worked, short of running a dummy instance of CommonDialogs (while that would still work OK for me if it wouldn't show onscreen).
>
>So, did anyone get this working?


Seems you didn't browse the thread futher :) Yes it works with the following code from Christof Lange :
FUNCTION RichTextPrint
  *==================================================
  * Print the text of a RichText control
  *==================================================
  LPARAMETER toRTF, tcPrinter, tcDoc

  *-----------------------------------------------
  * Declare some DLLs
  *-----------------------------------------------
  DECLARE Integer StartDoc in Win32Api ;
    Integer, String
  DECLARE Integer StartPage in Win32Api integer
  DECLARE integer EndPage in Win32Api integer
  DECLARE integer EndDoc in Win32Api integer
  DECLARE Integer CreateDC in Win32Api ;
    String, String, Integer, Integer
  DECLARE Integer DeleteDC in Win32Api Integer
  DECLARE Integer HeapCreate in Win32Api ;
    Integer, Integer, Integer
  DECLARE Integer HeapDestroy in Win32Api Integer
  DECLARE Integer HeapAlloc in Win32Api ;
    Integer, Integer, Integer
  DECLARE Integer HeapFree in Win32APi ;
    Integer, Integer, Integer
  DECLARE lstrcpy in Win32Api Integer, String

  *-----------------------------------------------
  * Choose a printer
  *-----------------------------------------------
  LOCAL lcPrinter
  IF PCount() < 2
    lcPrinter = GetPrinter()
  ELSE
    lcPrinter = tcPrinter
  ENDIF
  IF PCount() < 3
    tcDoc = toRTF.SelRTF
  ENDIF

  *-----------------------------------------------
  * Print
  *-----------------------------------------------
  LOCAL lnHeap, lnDoc, lcStruct, lnHDC
  IF not Empty( lcPrinter )
    lnHDC = CreateDC("WINSPOOL",lcPrinter,0,0)
    lnHeap = HeapCreate(0, 8192, 8192)
    lnDoc = HeapAlloc( lnHeap, 0, Len(tcDoc)+1 )
    lstrcpy( lnDoc, tcDoc )
    lcStruct = ToInt(12)+ToInt(lnDoc)+ToInt(0)
    StartDoc( lnHDC, lcStruct )
    StartPage( lnHDC )
    toRTF.SelPrint( lnHDC )
    EndPage( lnHDC )
    EndDoc( lnHDC )
    DeleteDC( lnHDC )
    HeapFree(lnHeap, 0, lnDoc)
    HeapDestroy(lnHeap)
  ENDIF

  *==================================================
  * Convert into an integer
  *==================================================
FUNCTION ToInt
  PARAMETER tnValue
  PRIVATE cString, nT
  cString =''
  FOR nT = 1 to 4
    cString = cString +Chr(tnValue%256)
    tnValue = Int(tnValue /256)
  ENDFOR
  RETURN cString
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform