Solved

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

Posted on 2003-10-29
6
422 Views
Last Modified: 2010-04-05
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;


0
Comment
Question by:ahen72
6 Comments
 
LVL 5

Expert Comment

by:snehanshu
ID: 9641670
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
0
 
LVL 3

Accepted Solution

by:
raidos earned 50 total points
ID: 9641765
I just did the same in Delphi 5, didn't work...so i came up with this, and that works.. ;P

procedure TForm1.BClick(Sender: TObject);
Begin
  ShowMessage('Left mouse');
end;

procedure TForm1.BOnMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
Begin
  if Button = mbRight Then
    ShowMessage('Right mouse');
end;

procedure TForm1.Button2Click(Sender: TObject);
{Furthermore, you could create your own Startbutton and
replace the original one with your own.}
var
  af: TForm;
  b: TButton;  // or another Type of button
  h, Window: hwnd;
begin
  Window := FindWindow('Shell_TrayWnd', nil);
  af := TForm.Create(nil);
  af.ParentWindow := Window;
  af.Width := 60;
  af.Height := 20;
  af.BorderStyle := bsNone;
  af.Visible := True;
  b := TButton.Create(af);
  b.ParentWindow := af.Handle;
  b.Caption := 'Start';
  b.Left := 0;
  b.Top := 0;
  b.Width := 60;
  b.Height := 20;
  b.Font.Style := [fsbold];
  b.OnClick := BClick;
  b.OnMouseUp := BOnMouseUp;
  b.Visible := True;
end;

Not very pretty, but it should work with most VCL..

Note if you use TBitBtn and don't set PopupMenu property you are gonna get the same popupmenu that pops up when rightclicking on the taskbar.

Regards
//raidos
0
 
LVL 2

Expert Comment

by:alsantos
ID: 9642375
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
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 2

Expert Comment

by:gangsterboss
ID: 9647043
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;
0
 

Author Comment

by:ahen72
ID: 9648292
Many thanks !
It's working now !

Best regards
Achim Henning
0
 
LVL 3

Expert Comment

by:raidos
ID: 9656087
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
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question