Solved

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

Posted on 2003-10-29
6
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2 91
Dev Express grid collapse 2 55
How to renew a Delphi rad-studio licence? 5 95
Broadcast a message using ICS 2 51
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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