Board index » cppbuilder » graphics library usage

graphics library usage


2005-11-16 11:03:53 AM
cppbuilder6
Hi.
I'm trying to use a graphics library.. it is pretty old, but it is the
one at my disposal.
It is a c library, and takes hdc's and window handles to work with.
I would like to draw to a tabbed page, but notice there is no canvas.
I tried to use a TCanvas *tempCanvas = new TCanvas;
but I noticed I have problems getting a good xresolution out of it
using:
GetDeviceCaps(tempCanvas,LOGPIXELSX)
Can someone tell me what I should do to get around this? do I need to
put a image control or something there to get good devicecaps?
Thanks
 
 

Re:graphics library usage

Jeff Kish < XXXX@XXXXX.COM >wrote:
Quote

[...] It is a c library, and takes hdc's and window handles
to work with.
So it's win32 and not DOS - no problem. However, I doubt that
you need the lib at all because TCanvas has it's own methods
that are simple to use.
Quote
I would like to draw to a tabbed page, but notice there is
no canvas.
I don't know what you mean by 'tabbed page'. If it's a VCL
object, you can use a TControlCanvas but that won't give you
access to the non-client area so I prefer to use a TCanvas but
then you need the object's HWND. For example:
HWND hWnd = get the handle of the object
TCanvas *pCanvas = new TCanvas;
pCanvas->Handle = ::GetWindowDC( hWnd );
// do your drawing on pCanvas
::ReleaseDC( Handle, pCanvas->Handle );
pCanvas->Handle = NULL;
delete pCanvas;
Note that the win32 API GetWindowDC get's a HDC for the entire
object - including the non-client area. If all you want is the
client area, use GetDC instead.
Quote
I tried to use a TCanvas *tempCanvas = new TCanvas; but I
noticed I have problems getting a good xresolution out of it
using: GetDeviceCaps(tempCanvas,LOGPIXELSX)
LOGPIXELSX is for getting the PPI. If that's what you really
want, the resolution won't be any different from TForm's
PixelsPerInch property. However, I suspect that what you're
trying to do is determine the dimensions of the object. If
that's correct, you should use the win32 API GetWindowRect
to include the non-client area and GetClientRect for just the
client area. Just remember that TCanvas is zero based so
you'll have to do some math. For example:
TRect R;
::GetWindowRect( hWnd, &R );
int width = R.right - R.left;
int height = R.bottom - R.top;
~ JD
 

Re:graphics library usage

On 15 Nov 2005 22:12:44 -0700, "JD" < XXXX@XXXXX.COM >wrote:
Quote

Jeff Kish < XXXX@XXXXX.COM >wrote:
>
>[...] It is a c library, and takes hdc's and window handles
>to work with.

So it's win32 and not DOS - no problem. However, I doubt that
you need the lib at all because TCanvas has it's own methods
that are simple to use.

Well it displays a number of different raster file types that I need
to display. I don't think I can do all the formats without some extra
'vendor muscle'. tif, jpg, pcx come to mind.
Quote
>I would like to draw to a tabbed page, but notice there is
>no canvas.

I don't know what you mean by 'tabbed page'. If it's a VCL
object, you can use a TControlCanvas but that won't give you
access to the non-client area so I prefer to use a TCanvas but
then you need the object's HWND. For example:

HWND hWnd = get the handle of the object
TCanvas *pCanvas = new TCanvas;
pCanvas->Handle = ::GetWindowDC( hWnd );
// do your drawing on pCanvas
::ReleaseDC( Handle, pCanvas->Handle );
pCanvas->Handle = NULL;
delete pCanvas;

Note that the win32 API GetWindowDC get's a HDC for the entire
object - including the non-client area. If all you want is the
client area, use GetDC instead.

>I tried to use a TCanvas *tempCanvas = new TCanvas; but I
>noticed I have problems getting a good xresolution out of it
>using: GetDeviceCaps(tempCanvas,LOGPIXELSX)

LOGPIXELSX is for getting the PPI. If that's what you really
want, the resolution won't be any different from TForm's
PixelsPerInch property. However, I suspect that what you're
trying to do is determine the dimensions of the object. If
that's correct, you should use the win32 API GetWindowRect
to include the non-client area and GetClientRect for just the
client area. Just remember that TCanvas is zero based so
you'll have to do some math. For example:

TRect R;
::GetWindowRect( hWnd, &R );
int width = R.right - R.left;
int height = R.bottom - R.top;

~ JD
Thanks. Actually I need to LOGPIXELSX and LOGPIXELSY as they are
parameters to calls made into the library.
Off to try things out and debug. Thank you again.
Jeff Kish
 

{smallsort}

Re:graphics library usage

Jeff Kish < XXXX@XXXXX.COM >wrote:
Quote
<snip>
>I don't know what you mean by 'tabbed page'. If it's a VCL
Sorry. I am using the TPageControl which has tabs on it.

>object, you can use a TControlCanvas but that won't give you
>access to the non-client area so I prefer to use a TCanvas but
>then you need the object's HWND. For example:
>
>HWND hWnd = get the handle of the object
>TCanvas *pCanvas = new TCanvas;
>pCanvas->Handle = ::GetWindowDC( hWnd );
>// do your drawing on pCanvas
>::ReleaseDC( Handle, pCanvas->Handle );
>pCanvas->Handle = NULL;
>delete pCanvas;
>
for some reason the hdc is coming back null:

HDC theHdc = GetWindowDC(Image1->Canvas->Handle);
I'm not really sure why,
When ever you use a win32 API and it fails, you should use
GetLastError to find out why. However, in this case, I already
know why.
Examine the code more closely. You'll see that the HDC is
being assigned to the Canvas::Handle. The canvas handle is
an HDC - not an HWND.
~ JD
 

Re:graphics library usage

<snip>
Quote
I don't know what you mean by 'tabbed page'. If it's a VCL
Sorry. I am using the TPageControl which has tabs on it.
Quote
object, you can use a TControlCanvas but that won't give you
access to the non-client area so I prefer to use a TCanvas but
then you need the object's HWND. For example:

HWND hWnd = get the handle of the object
TCanvas *pCanvas = new TCanvas;
pCanvas->Handle = ::GetWindowDC( hWnd );
// do your drawing on pCanvas
::ReleaseDC( Handle, pCanvas->Handle );
pCanvas->Handle = NULL;
delete pCanvas;

for some reason the hdc is coming back null:
HDC theHdc = GetWindowDC(Image1->Canvas->Handle);
I'm not really sure why, but this is probably at the crux of at least
one of the problems I am experiencing.
<snip>
Thanks
Jeff Kish
 

Re:graphics library usage

On 16 Nov 2005 07:17:43 -0700, "JD" < XXXX@XXXXX.COM >wrote:
Quote

Jeff Kish < XXXX@XXXXX.COM >wrote:
><snip>
>>I don't know what you mean by 'tabbed page'. If it's a VCL
>Sorry. I am using the TPageControl which has tabs on it.
>
>>object, you can use a TControlCanvas but that won't give you
>>access to the non-client area so I prefer to use a TCanvas but
>>then you need the object's HWND. For example:
>>
>>HWND hWnd = get the handle of the object
>>TCanvas *pCanvas = new TCanvas;
>>pCanvas->Handle = ::GetWindowDC( hWnd );
>>// do your drawing on pCanvas
>>::ReleaseDC( Handle, pCanvas->Handle );
>>pCanvas->Handle = NULL;
>>delete pCanvas;
>>
>for some reason the hdc is coming back null:
>
>HDC theHdc = GetWindowDC(Image1->Canvas->Handle);
>I'm not really sure why,

When ever you use a win32 API and it fails, you should use
GetLastError to find out why. However, in this case, I already
know why.

Examine the code more closely. You'll see that the HDC is
being assigned to the Canvas::Handle. The canvas handle is
an HDC - not an HWND.

~ JD
thanks.... (darn.. I hate when I do stuff like that)
Jeff Kish