Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is that possible to allocate windows handle to TObject direct descendant?

83 views
Skip to first unread message

Chau Chee Yang

unread,
Oct 24, 2007, 10:33:58 AM10/24/07
to
Hi,

If we want to use SendMessage or PostMessage, we have to supply a window
handle to the 2 function. The most common way of using pattern is
TWinControl descendant.

W := TWinControl_Descendant.Create(nil);
W.Parent := Application.MainForm;
PostMessage(W.Handle, 10000, 0, 0);

W must have parent set else the handle won't be allocated. I just
wondering if we can declare a handle to a TObject descendant and
allocate a handle to it without setting the parent. Is that possible to
do so?

--
Best regards,
Chau Chee Yang

E Stream Software Sdn Bhd
URL: www.sql.com.my
SQL Financial Accounting

Jeff Overcash (TeamB)

unread,
Oct 24, 2007, 11:30:12 AM10/24/07
to
Chau Chee Yang wrote:
> Hi,
>
> If we want to use SendMessage or PostMessage, we have to supply a window
> handle to the 2 function. The most common way of using pattern is
> TWinControl descendant.
>
> W := TWinControl_Descendant.Create(nil);
> W.Parent := Application.MainForm;
> PostMessage(W.Handle, 10000, 0, 0);
>
> W must have parent set else the handle won't be allocated. I just
> wondering if we can declare a handle to a TObject descendant and
> allocate a handle to it without setting the parent. Is that possible to
> do so?
>

IBX does this in the SQLMonitor code look at the TIBCustomSQLMonitor class in
IBSQLMonitor.pas. The create allocates a windows handle, the destroy cleans it
up, and MonitorWndProc processes the messages.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted corridors of Whitehall.
(Fish)

Remy Lebeau (TeamB)

unread,
Oct 24, 2007, 1:27:38 PM10/24/07
to

"Chau Chee Yang" <c...@sql.com.my> wrote in message
news:471f580e$1...@newsgroups.borland.com...

> I just wondering if we can declare a handle to a TObject
> descendant and allocate a handle to it without setting the
> parent. Is that possible to do so?

You can use the VCL's AllocateHWnd() function to create a hidden HWND that
has a class method assigned as its window procedure. Some of the VCL's own
non-visual components, such as TTimer, use this technique.


Gambit


Peter Below (TeamB)

unread,
Oct 24, 2007, 1:34:26 PM10/24/07
to
Chau Chee Yang wrote:

> Hi,
>
> If we want to use SendMessage or PostMessage, we have to supply a
> window handle to the 2 function. The most common way of using
> pattern is TWinControl descendant.
>
> W := TWinControl_Descendant.Create(nil);
> W.Parent := Application.MainForm;
> PostMessage(W.Handle, 10000, 0, 0);
>
> W must have parent set else the handle won't be allocated. I just
> wondering if we can declare a handle to a TObject descendant and
> allocate a handle to it without setting the parent. Is that possible
> to do so?

Look at the AllocateHwnd and DeallocateHwnd functions from the Classes
unit. Just make sure you pass any messages you do not process from the
message handler function you provide to DefWindowProc. The two
functions are not thread-safe, by the way.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

0 new messages