For Newbie

Tuesday, 15 November 2011

Tricks to read and change the size of Windows XP's start button by Delphi

resized start button delphi

Function and procedure declarations:/ / Used to check the Start Button pulled Presence or NotStartButtonExists function: Boolean;var
  
targetHwnd: hWnd;begin
  
targetHwnd: = GetWindow (FindWindow ('Shell_TrayWnd', nil), GW_CHILD or GW_HWNDFIRST);
  
if targetHwnd <> 0 then Result: = True else Result: = False;end;
/ / Used To Read The size of the Start ButtonGetStartButtonSize procedure (var w, h: Integer);var
  
targetHwnd: hWnd;
  
xRect: TRect;begin
  
if StartButtonExists then
  
begin
    
/ / Start Button Window Handle
    
targetHwnd: = GetWindow (FindWindow ('Shell_TrayWnd', nil), GW_CHILD or GW_HWNDFIRST);
    
/ / Get the Rectangle
    
GetWindowRect (targetHwnd, xRect);
    
/ / Width of StartButton
    
w: = xRect.Right;
    
/ / Height of StartButton (Formula: Rect.Bottom - Rect.Top)
    
h: = xRect.Bottom - xRect.Top;
  
end
  
else
  
begin
    
/ / Can not read
    
w: = -1;
    
h: = -1;
  
end;end;
/ / Used To Change Start Button SizeChangeStartButtonSize procedure (const w, h: Integer);var
  
targetHwnd: hWnd;
  
xRect: TRect;begin
  
/ / Start Button Window Handle
  
targetHwnd: = GetWindow (FindWindow ('Shell_TrayWnd', nil), GW_CHILD or GW_HWNDFIRST);
  
/ / Get the Rectangle
  
if targetHwnd <> 0 then MoveWindow (targetHwnd, 0, 0, w, h, True);end;

Examples of implementation # 1:/ / Get SizeTForm1.FormCreate procedure (Sender: TObject);var
  
w, h: Integer;begin
  
GetStartButtonSize (w, h);
  
Edit1.Text: = IntToStr (w);
  
Edit2.Text: = IntToStr (h);end;
/ / Set Sizeprocedure TForm1.Button1Click (Sender: TObject);begin
  
ChangeStartButtonSize (32, 32);end;

Example implementations # 2 (using TUpDown):TForm1.FormCreate procedure (Sender: TObject);var
  
w, h: Integer;begin
  
GetStartButtonSize (w, h);
  
UpDown1.Position: = w;
  
UpDown2.Position: = h;
  
if StartButtonExists then Button1.Enabled: = True
  
else Button1.Enabled: = False;end;
procedure TForm1.Button1Click (Sender: TObject);begin
  
ChangeStartButtonSize (UpDown1.Position, UpDown2.Position);end;
TForm1.FormClose procedure (Sender: TObject; var Action: TCloseAction);begin
  
/ / Standard Start Button
  
ChangeStartButtonSize (99, 32);end;

Share on Facebook
Share on Twitter
Share on Google+

Related : Tricks to read and change the size of Windows XP's start button by Delphi