Search code examples
delphicross-application

Create Button on other application window


I wrote below code to create an extra button on Calculator, but the button don't show:

var
  Object1 : TButton ;
  Hand: THandle;
begin
   Hand:= FindWindow('CalcFrame', 'Calculator');
   Object1 := TButton.CreateParented(Hand);
   Object1.Show ;
end;

I get the controls on the calculator after running the above code using EnumChildWindow API function and see the created button in control list that EnumChildWindow returns, but why does the created button not show ?

As I remember I use this code on windows XP and it works without problem but now in windows 7 the created button doesn't appear.


Solution

  • calculator and Paint in Win7 are rebuilt using .NET and WPF, and there is no way to "contact" with .NET code through native code especially WPF which use different way to paint its controls.

    edit: to make your code work for native applictions you can use code like this:

    hand := FindWindow('TForm1','Form1');
    object1 := TButton.Create(self);
    object1.ParentWindow := hand;