Hi All,

I posted this in the wrong thread. Sorry for the repost.

Eric den Doop suggested I take a look at TextControl.com's ActiveX control
for print previewing MS-Word or RTF documents. I downloaded the trial
version and I am having a problem with the code.

According to the Help File:

"Text Control's PrintPage method can not only be used with printers, but
also with any control that has a hDC property. For instance. a PictureBox
can be used as a print preview window. This is done by simply assigning its
hDC Property to Text Control's PrintDevice Property. When calling PrintPage,
Text Control will print to the Picture Box instead of to the printer.

This code snippet will print page 1 to a picture box named Picture1. You can
use the PrintZoom Property to scale down the printout if the picture box is
smaller than a full printer page:

TXTextControl1.PrintDevice = Picture1.hDC
TXTextControl1.PrintZoom = 25 ' scale down to 25%
TXTextControl1.PrintPage 1"

The MDIDemo sample program contains a sophisticated print preview form that
works like this. Its source code is contained in the Samples\VB6\MDI
folder."

Well I have adapted that example as best I could with the following code:

cDoc = "c:\pcenable\rtf\jdis2.doc"
thisform.oTxt.Load(cDoc,,9,)
thisform.oTxt.PrintDevice = Picture1.hDC
thisform.oTxt.PrintZoom = 25 && scale down to 25%
thisform.oTxt.PrintPage(1)

The code generates the following run time error "Alias 'Picture1' is not
found."

I have named the image control to "Picture1" but I realize that my problem
is that I have no idea what hDC is! Any help would be appreciated.

TIA,
Tom Clark

Bernhard Sander replied:

"If your "Picture1" is on the same form then the above line should read:
thisform.oTxt.PrintDevice = THISFORM.Picture1.hDC"

Which I tried and the new error is "Property hDC not found."

MSDN says the following in regards to Visual BASIC:

Syntax
object.hDC
The object placeholder represents an object expression that evaluates to an
object in the Applies To list.
Remarks
This property is a Windows operating environment device context handle. The
Windows operating environment manages the system display by assigning a
device context for the Printer object and for each form and PictureBox
control in your application. You can use the hDC property to refer to the
handle for an object's device context. This provides a value to pass to
Windows API calls.
With a CommonDialog control, this property returns a device context for the
printer selected in the Print dialog box when the cdlReturnDC flag is set or
an information context when the cdlReturnIC flag is set.
Note The value of the hDC property can change while a program is running,
so don't store the value in a variable; instead, use the hDC property each
time you need it.
The AutoRedraw property can cause the hDC property setting to change. If
AutoRedraw is set to True for a form or PictureBox container, hDC acts as a
handle to the device context of the persistent graphic (equivalent to the
Image property). When AutoRedraw is False, hDC is the actual hDC value of
the Form window or the PictureBox container. The hDC property setting may
change while the program is running regardless of the AutoRedraw setting.
If the HasDC property is set to False, a new device context will be created
by the system and the value of the hDC property will change each time it is
called.

Re: Help for hDC and textcontrol.com's ActiveX Control by Fred

Fred
Wed Feb 16 09:08:08 CST 2005

Fox Controls are not "real" Windows controls, in that they don't have a
Windows handle or anything like that. You're picturebox control would need
to be an ActiveX control and if it is, you may need to reference the
property as thisform.picture1.object.hDC.

--
Fred
Microsoft Visual FoxPro MVP


"Tom Clark" <tjclark@pc-enable.com> wrote in message
news:1116jlasqavki8d@corp.supernews.com...
> Hi All,
>
> I posted this in the wrong thread. Sorry for the repost.
>
> Eric den Doop suggested I take a look at TextControl.com's ActiveX control
> for print previewing MS-Word or RTF documents. I downloaded the trial
> version and I am having a problem with the code.
>
> According to the Help File:
>
> "Text Control's PrintPage method can not only be used with printers, but
> also with any control that has a hDC property. For instance. a PictureBox
> can be used as a print preview window. This is done by simply assigning
> its
> hDC Property to Text Control's PrintDevice Property. When calling
> PrintPage,
> Text Control will print to the Picture Box instead of to the printer.
>
> This code snippet will print page 1 to a picture box named Picture1. You
> can
> use the PrintZoom Property to scale down the printout if the picture box
> is
> smaller than a full printer page:
>
> TXTextControl1.PrintDevice = Picture1.hDC
> TXTextControl1.PrintZoom = 25 ' scale down to 25%
> TXTextControl1.PrintPage 1"
>
> The MDIDemo sample program contains a sophisticated print preview form
> that
> works like this. Its source code is contained in the Samples\VB6\MDI
> folder."
>
> Well I have adapted that example as best I could with the following code:
>
> cDoc = "c:\pcenable\rtf\jdis2.doc"
> thisform.oTxt.Load(cDoc,,9,)
> thisform.oTxt.PrintDevice = Picture1.hDC
> thisform.oTxt.PrintZoom = 25 && scale down to 25%
> thisform.oTxt.PrintPage(1)
>
> The code generates the following run time error "Alias 'Picture1' is not
> found."
>
> I have named the image control to "Picture1" but I realize that my problem
> is that I have no idea what hDC is! Any help would be appreciated.
>
> TIA,
> Tom Clark
>
> Bernhard Sander replied:
>
> "If your "Picture1" is on the same form then the above line should read:
> thisform.oTxt.PrintDevice = THISFORM.Picture1.hDC"
>
> Which I tried and the new error is "Property hDC not found."
>
> MSDN says the following in regards to Visual BASIC:
>
> Syntax
> object.hDC
> The object placeholder represents an object expression that evaluates to
> an object in the Applies To list.
> Remarks
> This property is a Windows operating environment device context handle.
> The Windows operating environment manages the system display by assigning
> a device context for the Printer object and for each form and PictureBox
> control in your application. You can use the hDC property to refer to the
> handle for an object's device context. This provides a value to pass to
> Windows API calls.
> With a CommonDialog control, this property returns a device context for
> the printer selected in the Print dialog box when the cdlReturnDC flag is
> set or an information context when the cdlReturnIC flag is set.
> Note The value of the hDC property can change while a program is
> running, so don't store the value in a variable; instead, use the hDC
> property each time you need it.
> The AutoRedraw property can cause the hDC property setting to change. If
> AutoRedraw is set to True for a form or PictureBox container, hDC acts as
> a handle to the device context of the persistent graphic (equivalent to
> the Image property). When AutoRedraw is False, hDC is the actual hDC value
> of the Form window or the PictureBox container. The hDC property setting
> may change while the program is running regardless of the AutoRedraw
> setting.
> If the HasDC property is set to False, a new device context will be
> created by the system and the value of the hDC property will change each
> time it is called.
>



Re: Help for hDC and textcontrol.com's ActiveX Control by Tom

Tom
Wed Feb 16 10:28:57 CST 2005

Hi Fred & All,

I have tried using adding Active X Microsoft Forms 2.0 Image (frm20.dll) and
Microsoft Picture Clip Control v6 (picclp32.ocx) and the new error in both
cases is "Ole Error Code... unknown name"

Tom Clark


"Fred Taylor" wrote:
> Fox Controls are not "real" Windows controls, in that they don't have a
> Windows handle or anything like that. You're picturebox control would
> need to be an ActiveX control and if it is, you may need to reference the
> property as thisform.picture1.object.hDC.
>
>
> "Tom Clark" <tjclark@pc-enable.com> wrote in message
> news:1116jlasqavki8d@corp.supernews.com...
>> Hi All,
>>
>> I posted this in the wrong thread. Sorry for the repost.
>>
>> Eric den Doop suggested I take a look at TextControl.com's ActiveX
>> control
>> for print previewing MS-Word or RTF documents. I downloaded the trial
>> version and I am having a problem with the code.
>>
>> According to the Help File:
>>
>> "Text Control's PrintPage method can not only be used with printers, but
>> also with any control that has a hDC property. For instance. a PictureBox
>> can be used as a print preview window. This is done by simply assigning
>> its
>> hDC Property to Text Control's PrintDevice Property. When calling
>> PrintPage,
>> Text Control will print to the Picture Box instead of to the printer.
>>
>> This code snippet will print page 1 to a picture box named Picture1. You
>> can
>> use the PrintZoom Property to scale down the printout if the picture box
>> is
>> smaller than a full printer page:
>>
>> TXTextControl1.PrintDevice = Picture1.hDC
>> TXTextControl1.PrintZoom = 25 ' scale down to 25%
>> TXTextControl1.PrintPage 1"
>>
>> The MDIDemo sample program contains a sophisticated print preview form
>> that
>> works like this. Its source code is contained in the Samples\VB6\MDI
>> folder."
>>
>> Well I have adapted that example as best I could with the following code:
>>
>> cDoc = "c:\pcenable\rtf\jdis2.doc"
>> thisform.oTxt.Load(cDoc,,9,)
>> thisform.oTxt.PrintDevice = Picture1.hDC
>> thisform.oTxt.PrintZoom = 25 && scale down to 25%
>> thisform.oTxt.PrintPage(1)
>>
>> The code generates the following run time error "Alias 'Picture1' is not
>> found."
>>
>> I have named the image control to "Picture1" but I realize that my
>> problem
>> is that I have no idea what hDC is! Any help would be appreciated.
>>
>> TIA,
>> Tom Clark
>>
>> Bernhard Sander replied:
>>
>> "If your "Picture1" is on the same form then the above line should read:
>> thisform.oTxt.PrintDevice = THISFORM.Picture1.hDC"
>>
>> Which I tried and the new error is "Property hDC not found."
>>
>> MSDN says the following in regards to Visual BASIC:
>>
>> Syntax
>> object.hDC
>> The object placeholder represents an object expression that evaluates to
>> an object in the Applies To list.
>> Remarks
>> This property is a Windows operating environment device context handle.
>> The Windows operating environment manages the system display by assigning
>> a device context for the Printer object and for each form and PictureBox
>> control in your application. You can use the hDC property to refer to the
>> handle for an object's device context. This provides a value to pass to
>> Windows API calls.
>> With a CommonDialog control, this property returns a device context for
>> the printer selected in the Print dialog box when the cdlReturnDC flag is
>> set or an information context when the cdlReturnIC flag is set.
>> Note The value of the hDC property can change while a program is
>> running, so don't store the value in a variable; instead, use the hDC
>> property each time you need it.
>> The AutoRedraw property can cause the hDC property setting to change. If
>> AutoRedraw is set to True for a form or PictureBox container, hDC acts as
>> a handle to the device context of the persistent graphic (equivalent to
>> the Image property). When AutoRedraw is False, hDC is the actual hDC
>> value of the Form window or the PictureBox container. The hDC property
>> setting may change while the program is running regardless of the
>> AutoRedraw setting.
>> If the HasDC property is set to False, a new device context will be
>> created by the system and the value of the hDC property will change each
>> time it is called.
>>
>
>