Link to home
Start Free TrialLog in
Avatar of ahen72
ahen72

asked on

Hide Startbutton -> Draw new Startbutton -> OnClick not working

Hello,

I found on www.swissdelphicenter.com a source how to hide and disable the start button and draw a new button.
That works fine, but I  can't add an action to the left or right mouseclick to the button.

For example:
right mouseclick -> popupmenu1
left mouselcik    -> popupmenu2

Also it's not possible to use a TBitBtn instead of a TButton.

I hope you can help me again.


Thanks in advance
Achim Henning

------------------------------------------------------------
The source code from www.swissdelphicenter.com:
{
  The ShowStartButton function shows how to hide the start
  button, how to disable the windows buttons (LWin and RWin)
  (indirectly) and consequently how to hide the start menu.
}

procedure ShowStartButton(bvisible: Boolean);
var
  h: hwnd;
  TaskWindow: hwnd;
begin
  if bvisible then
  begin
    h := FindWindowEx(GetDesktopWindow, 0, 'Button', nil);
    TaskWindow := FindWindow('Shell_TrayWnd', nil);
    ShowWindow(h, 1);
    Windows.SetParent(h, TaskWindow);
  end  
  else
  begin
    h := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil);
    ShowWindow(h, 0);
    Windows.SetParent(h, 0);
  end;
end;

{Example to hide/reshow the Startbutton}
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowStartButton(False); // or true to reshow
end;

{Furthermore, you could create your own Startbutton and
replace the original one with your own.}
var
  b: TButton;  // or another Type of button
  h, Window: hwnd;
begin
  Window := FindWindow('Shell_TrayWnd', nil);
  b := TButton.Create(nil);
  b.ParentWindow := Window;
  b.Caption := 'Start';
  b.Width := 60;
  b.Font.Style := [fsbold];
end;


Avatar of snehanshu
snehanshu

ahen72,
  If you have Delphi 6, you get a popup menu property with the button.
  I simply dropped a popup menu on my form and did this:
{Example to hide/reshow the Startbutton}
procedure TForm1.Button1Click(Sender: TObject);
var
  b: TButton;  // or another Type of button
  h, Window: hwnd;
begin
  ShowStartButton(False); // or true to reshow
  Window := FindWindow('Shell_TrayWnd', nil);
  b := TButton.Create(nil);
  b.ParentWindow := Window;
  b.Caption := 'Start';
  b.Width := 60;
  b.Font.Style := [fsbold];
  b.PopupMenu := PopupMenu1;
end;


  And it works.
  Not sure about the BitBtn though.
HTH
...Snehanshu
ASKER CERTIFIED SOLUTION
Avatar of raidos
raidos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ahen72, you can use the raidos's code and delete the line  b.OnMouseUp := BOnMouseUp; and b.OnClick := BClick;

and put:

  b.OnClick := LeftClick;
  b.PopupMenu := PopupMenu1;

and LeftClick is

procedure TForm1.LeftClick(Sender: TObject);
Begin
  PopupMenu1.Popup(0, 685);  // 685 if the resolution is 1024x768 .
end;

alsantos
hide and disable the start button and the start menu?
 
  The ShowStartButton function shows how to hide the start
  button, how to disable the windows buttons (LWin and RWin)
  (indirectly) and consequently how to hide the start menu.
}

{
  Die ShowStartButton Prozedur zeigt, wie man den Startbutton
  verstecken kann und die Windows Tasten (LWin and RWin)
  indirekt deaktivieren kann. Auch der Zugriff auf das
  Startmenu wird folglich nicht mehr möglich sein.
}

procedure ShowStartButton(bvisible: Boolean);
var
  h: hwnd;
  TaskWindow: hwnd;
begin
  if bvisible then
  begin
    h := FindWindowEx(GetDesktopWindow, 0, 'Button', nil);
    TaskWindow := FindWindow('Shell_TrayWnd', nil);
    ShowWindow(h, 1);
    Windows.SetParent(h, TaskWindow);
  end  
  else
  begin
    h := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil);
    ShowWindow(h, 0);
    Windows.SetParent(h, 0);
  end;
end;

{Example to hide/reshow the Startbutton
Beispiel, um den Startbutton zu verstecken/wieder anzuzeigen.}

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowStartButton(False); // or true to reshow
end;

{Furthermore, you could create your own Startbutton and
replace the original one with your own.}

{Es ist auch möglich, einen "eigenen" Startbutton durch
den original Startbutton zu ersetzen.}

var
  b: TButton;  // or another Type of button
  h, Window: hwnd;
begin
  Window := FindWindow('Shell_TrayWnd', nil);
  b := TButton.Create(nil);
  b.ParentWindow := Window;
  b.Caption := 'Start';
  b.Width := 60;
  b.Font.Style := [fsbold];
end;
Avatar of ahen72

ASKER

Many thanks !
It's working now !

Best regards
Achim Henning
That's nice....then i suggest you accept a comment as answer...
or provide info on how you solved it, if other way then suggested
by any comment and leave a post in E-E community support or whatever..

Regards
//raidos