Solved

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

Posted on 2003-10-29
6
448 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
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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month7 days, 3 hours left to enroll

622 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