Mega Code Archive

 
Categories / Delphi / Examples
 

Taskbar yapmak

// form'a button ve Label koyun.. Çok güzel bir kod. uses shellapi; function FindTaskBar(var ARect: TRect): Integer; var AppData: TAppBarData; begin // 'Shell_TrayWnd' is the name of the task bar's window AppData.Hwnd := FindWindow('Shell_TrayWnd', nil); if AppData.Hwnd = 0 then RaiseLastWin32Error; AppData.cbSize := SizeOf(TAppBarData); // SHAppBarMessage will return False (0) when an error // happens. if SHAppBarMessage(ABM_GETTASKBARPOS, AppData) = 0 then raise Exception.Create('SHAppBarMessage returned false when trying ' + 'to find the Task Bar''s position'); // Otherwise, we had success, so fill in the results. Result := AppData.uEdge; ARect := AppData.rc; end; procedure TForm1.Button1Click(Sender: TObject); var Rect: TRect; DestLeft: Integer; DestTop: Integer; begin DestLeft := Left; DestTop := Top; case FindTaskBar(Rect) of ABE_BOTTOM: begin DestLeft := Trunc((Screen.Width - Width) / 2.0); DestTop := Rect.Top - Height; end; ABE_LEFT: begin DestTop := Trunc((Screen.Height - Height) / 2.0); DestLeft := Rect.Right; end; ABE_RIGHT: begin DestTop := Trunc((Screen.Height - Height) / 2.0); DestLeft := Rect.Left - Width; end; ABE_TOP: begin DestLeft := Trunc((Screen.Width - Width) / 2.0); DestTop := Rect.Bottom; end; end; Label1.Caption := Format('Found at Top: %d Left: %d Bottom: %d Right: %d)', [Rect.Top, Rect.Left, Rect.Bottom, Rect.Right]); // Move us to the task bar while (Left <> DestLeft) or (Top <> DestTop) do begin if Left < DestLeft then Left := Left + 1 else if Left <> DestLeft then Left := Left - 1; if Top < DestTop then Top := Top + 1 else if Top <> DestTop then Top := Top - 1; Application.ProcessMessages; end; end;