Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identify a Control 's Window Handle

Status
Not open for further replies.

antal

Programmer
Jan 11, 2005
1
GR
Hello,

First of all i am not a Delphi programmer. I am writing a dll in C++ which communicates with a Delphi program. There is a form in Delphi and it has some buttons. I need to send a message to a specific button, so i need its window handle. GetDlgItem could give me the correct HWND but it cannot work, the Spy++ application shows that HWND is equal to Control ID for all controls in a Delphi application. Is it possible to overcome this difficulty?

Thank you
Andreas
 
Not sure how to help you, but I can tell you that the window handle of each component is available as a property. Here is the simple delphi code to prove that:
Code:
procedure TForm1.FormActivate(Sender: TObject);
begin
  Edit1.Text := IntToStr( Button1.Handle );
  Edit2.Text := IntToStr( Button2.Handle );
  Edit3.Text := IntToStr( Form1.Handle );
end;
The result shows that the HWND values are
Button1: 3168
Button2: 3384
Button3: 3128

It looks like you just need a way for the Delphi program to notify your DLL of what the handles are. If you don't want to go full-blown DDE, you can define your own protocol whereby either the Delphi app responds to a message by returning the HWND you want, or by posting another message back to your DLL with the HWND in (for example) the lParam.
 

As I think about this some more, it seems the simplest approach would be for you to require the button handle as a parameter in the calling sequence for the function you are programming in the DLL. As seen above, that is not a difficult requirement for the Delphi programmer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top