4

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.

Johan
  • 74,508
  • 24
  • 191
  • 319
Mojtaba Tajik
  • 1,725
  • 16
  • 34

2 Answers2

4

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;
Issam Ali
  • 1,703
  • 3
  • 15
  • 35
  • Issam, I think that's not true, if you use winspy and dig into paint and calc, you will find u can get handle for each controls inside it, which isn't the same case when u built with winforms or WPF. – Mohammed Nasman Jun 18 '11 at 09:53
  • @Mohammad I can't find official paper from MS about this issue but there are some pages around talk about it like this one: http://social.msdn.microsoft.com/Forums/en/wpf/thread/9e1fb1b3-248c-4a74-9822-0327152988fb Maybe the MS guys in SO can give us the truth about this subject, or they will consider it subjective question? What do you think? ;) – Issam Ali Jun 19 '11 at 10:51
0

you must make Visible:= False.

var
  Hand: THandle;
  Object1: TButton;
begin
  Hand:= FindWindow('TForm1', 'Form1');
  if Hand <> 0 then
  begin
    Object1:= TButton.CreateParented(Hand);
    Object1.Caption:= 'Test';
    Object1.Visible:= False ;
    Object1.Show;
  end;
end;