Re: Write onto Active-X Control

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Christoph Basedau (e_tonne_at_hotmail.com)
Date: 11/03/04


Date: Wed, 03 Nov 2004 02:25:36 +0100

02.11.2004 09:32, Mike D Sutton schrieb:

Hi Mike,

first of all thanks for your competent support

>> I needed to write *text* onto the MSChart Active-X Control.
>> The controls object-model doesn't allow to place axis-Y-labels
>> at any desired point of/near the axis, they're always
>> positioned in a centered manner.
>
> You would most likely need to subclass the control and draw you additional captions in it's WM_PAINT message handler.

Gee, how to i do that with VB? I know it's hard in VC.
Do you have sample-code for subclassing a control in VB?
Btw what is subclassing about, what does it mean?
I have the idea that I somehow link to the window-message queues
of a window that may or may not belong to my own app and somehow
take control of the action that happens if a certain message
is coming in like e.g. WM_PAINT (sounds pretty much like hacking
or 'hostile takeover' ...*eg* ).
Is that what a bit of what subclassing means?
How much code and how many working hours will I need for subclassing
a MSChart-Object placed on VB-form? (I don't even know how to
get the window-handle, there's no such property in terms of
VB-properties....)
 
>> Afaik with VB-methods you can't place label- or shape-objects
>> on top of MSChart, because the control has kind of a higher
>> priority and always covers the label (regardless of ZOrder).
>
> The reason for this is that the label and shape controls don't
> actually exist at runtime, meaning they don't have their own windows
> but are simply overlaid on their parent when it redraws -
> essentially this is exactly the same as you'd be doing with the above
> method.

Interesting, probably a 'Line' in VB is actually a call of LineTo()
at a certain time.
 
>> Can I use API-methods to draw lines or Text onto the control
>> and will this text remain visible, if the controls plot is
>> redrawn?
>
> For lines use the MoveToEx() and LineTo() API calls (it will also use the
> currently selected pen to style the line)

Can I also select a different pen? I need the labels/text to appear in a
certain color and also a selected font with a defined size.

> and for text have a look at the TextOut() or DrawText() API calls depending on exactly what you need to draw.

I've done some examples from Charles Petzold's Windows-Programming in C
that use TextOut() and DrawText(). It wasn't that difficult.
The problem for me is how to get handle to the DC and other handles that
aren't exposed by VB. According to MSDN the hDC prop applies to Forms
PictureBoxes UserControls and some Others, but not to MSChart.
Or is a VB-Control also kind of a UserControl?
 
>> Can I find out the coords of the axis-peak and how do I translate
>> the to API coords (that twips to pixels thing)?
>
> The DC will more than likely be using MM_TEXT mapping mode which equates to pixels, however if you're at all worried then you can
> convert the pixel coordinates to logical coordinates on the target DC using the DPtoLP() call. If your source coordinates are not
> in pixels in your VB application

But there is a property in VB that can set the default-scaling to pixels,
isn't it? it goes like VBnnnn = vbPixels. I forgot the name of that property.

> then you'll need to use the ScaleX()/ScaleY() methods to convert them to pixels before sending them
> on to the call (DPtoLP = Device Position to Logical Position, DP == Pixels.)
> Hope this helps,

Okay that points my into th right direction.

My goal is simply to display lines and bars on a 2D-plot and label datapoints
and axises at any position of the plot, MSChart is buggy (The Datapoints-Collection
only accepts index -1, this problem hasn't been fixed since 1998! And one cannot
place the axis-label on top of the axis, because an axises have no location-object
and the internal location is always centered. Thats very creepy because setting
the units on top is the common way to do for scientific graphs)

So would you think that it is better to subclass a control to achieve the
things that it can't do on its own or is it better (and in the end less work)
to write a fully new 'mini-chart-application' on my own?
I've seen VB-Code that does charting using API in combination with normal VB
drawing. It wasn't that much code (the vb-sample is called: "A Chart with
Windows API", forgot where it was from). It only uses three API-Function
(CreateFont, SelectObject and TextOut) to draw a nice little chart that has
precise scaling an it also looks beautiful and very clean.
I have the impression that i can do more without the MSChart control
with less code. But maybe i am wrong. What do you think is subclassing easier
or writing a self-made API-chart?

-- 
Gruesse, Christoph
Rio Riay Riayo - Gordon Sumner, 1979


Relevant Pages

  • Re: Preventing pasting in a TEdit
    ... >the WndProc method or add custom message-handling methods? ... Far and away the largest number of messages going into Windows ... Subclassing is a fairly common and easily enacted way of modifying the ... Now what happens is that instead of the messages for the Edit control going ...
    (comp.lang.pascal.delphi.misc)
  • Re: Preventing pasting in a TEdit
    ... At the base of it all is the Windows EDIT class. ... When I suggested overriding WndProc, it was implicit that I was ... but I understand quite well what subclassing is. ... The advantages are obvious, you can create your own menus, control ...
    (comp.lang.pascal.delphi.misc)
  • Re: Preventing pasting in a TEdit
    ... Almost every program for windows uses subclassing... ... edit control, whether transparently by VCL tools or overtly in WinApi ...
    (comp.lang.pascal.delphi.misc)
  • Re: GetDialogBaseUnits returns
    ... For Windows CE a publicly visible header file includes a secret DS_USEPIXELS ... resize each control in handling the WM_INITDIALOG message. ... kind of DBU and other APIs convert different kinds of DBUs into pixels. ...
    (microsoft.public.vc.mfc)
  • Re: older games dont work
    ... the support of my work have it and will burn a CD to me. ... and any other tips to make this game works will be great. ... Windows 95 including but not limited to: ... to map a pedal as a control ...
    (microsoft.public.windowsxp.games)