Solved

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

Posted on 2003-10-29
6
410 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now