[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

An Object with Handle

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
ronit051397
Asked:
ronit051397
  • 5
  • 4
  • 3
  • +1
1 Solution
 
interCommented:
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
 
JimBob091197Commented:
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
 
ronit051397Author Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
JimBob091197Commented:
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
 
ronit051397Author Commented:
JB, I didn't see your comment, I'll check it.
0
 
ronit051397Author Commented:
Thanks JB, it's working. If you post some answer i'll grade it.
0
 
MatveyCommented:
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
 
ronit051397Author Commented:
Matvay, Please do:  ronith@cmr.co.il

Thanks,
Ronit
0
 
JimBob091197Commented:
Ronit: before I post an answer I'll wait for you to check out Zif's component which Matvey mentioned.

JB
0
 
interCommented:
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
 
MatveyCommented:
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
 
ronit051397Author Commented:
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
 
JimBob091197Commented:
Hi Ronit,

Here is the answer for AllocateHWnd and DeallocateHWnd.

Bye,
JB
0
 
MatveyCommented:
-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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now