Solved

An Object with Handle

Posted on 1998-06-11
14
223 Views
Last Modified: 2013-11-23
Hi,

I need to create an object that recieves messages and perform some procedures according to this messages.
Is there a way to create an object with Handle, but not a subclass of TWinControl and not the DDE component,
meaning this object is derived directly from TObject?

Thanks,
Ronit
0
Comment
Question by:ronit051397
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1352163
Hi ronit,
The thing that we should note here is that Windows only posts messages to handles associated with windows class or subclass. If you do not want to use TWinControl or else we should explicitely create a Window handle and associate its message callback with CreateWindow function. But this is virtually same as what TWinControl does. So why do you need such thing. May be we can use events rather than messages.
Regards, Igor
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1352164
Hi

You can do the following:

constructor TMyObject.Create;
  inherited;
  FHandle := AllocateHWnd(WndProc);
end;

destructor TMyObject.Destroy;
begin
  DeallocateHWnd(FHandle);
  inherited;
end;

procedure TMyObject.WndProc(var AMsg: TMessage);
begin
  case Msg.Msg of
    WM_THIS:...;
    WM_THAT:...;
    else
      Msg.Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
  end;
end;

This is a similar approach to TTimer (in ExtCtrls.pas).  I haven't tried it for a TObject, but it *should* work...

Cheers,
JB
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1352165
Actually threads and processes have handles, as far as I know they can get messages and are not windows.
The DDE protocol is based on messages and it doesn't have to be related to a certain window, I mean, you can create a non windowed process and use DDE with it.
CreateWindow has something to do with visible stuff, But I am writing a non windowed "engine" that has to get messages from the system.
What I need is to Create an object and accociate a handle to it (maybe by CreateHandle or something), then to write methods that get certain messages and perform stuff.
Is it possible this way?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:JimBob091197
ID: 1352166
Oops...  change the WndProc to:

procedure TMyObject.WndProc(var Msg: TMessage);
begin
  case Msg.Msg of
    WM_THIS:...;
    WM_THAT:...;
    else
      Msg.Result := DefWindowProc(FWindowHandle, Msg.Msg, Msg.wParam, Msg.lParam);
  end;
end;

JB
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1352167
JB, I didn't see your comment, I'll check it.
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1352168
Thanks JB, it's working. If you post some answer i'll grade it.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1352169
Ronit, (some more) if you want your coponents to receive messages like top windows do, then see a component that ZifNab wrote - TCDEvents. You can find it in the Delphi pages or I can send it to you...

bosism@netvision.net.il
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1352170
Matvay, Please do:  ronith@cmr.co.il

Thanks,
Ronit
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1352171
Ronit: before I post an answer I'll wait for you to check out Zif's component which Matvey mentioned.

JB
0
 
LVL 5

Expert Comment

by:inter
ID: 1352172
Hi,
Well, this is cooperation. You are all, soo nobble guys. You make EE distinctive with these actions.
(Excuse me for my excitement but it is not common to see such a discussion on the net these days)
Regards, Igor
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1352173
Hi Igor!

It's been a long time...

Ronit, I sent you the component. It might not be the last ver, but still cool enough. -Enjoy

--Matvey
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1352174
Thanks Matvey. I have checked the component, it's derived from TComponent and it opens and closes the CD Door (meaning Eject), nice to know that there is one.
Yes, it uses the procedures you have posted, JB.
But now we know that we can use these procedures also with objects.
JB, you can post an answer if you want to.

Thanks everyone for your coorporation
Ronit

0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1352175
Hi Ronit,

Here is the answer for AllocateHWnd and DeallocateHWnd.

Bye,
JB
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1352176
-If you didn't notice, the component receives the "..._DeviceChange" message, so it's not only the eject method. The component actually receives all messages taht are posted to the top windows...

Cheers
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 119
Working with hours 3 64
Create a path if not exists 7 89
Twebbrowser add css to the header 3 27
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question