// The point object
TPointFill = class
X : Integer;
Y : Integer;
end;
// ----------------------------------------------------------------------------
// GetLinePoints
// ----------------------------------------------------------------------------
function GetLinePoints(X1, Y1, X2, Y2 : Integer) : TList;
var
ChangeInX, ChangeInY, i, MinX, MinY, MaxX, MaxY, LineLength : Integer;
ChangingX : Boolean;
Point : TPointFill;
ReturnList, ReversedList : TList;
begin
ReturnList := TList.Create;
ReversedList := TList.Create;
// Get the change in the X axis and the Max &; Min X values
if X1 >; X2 then
begin
ChangeInX := X1 - X2;
MaxX := X1;
MinX := X2;
end
else
begin
ChangeInX := X2 - X1;
MaxX := X2;
MinX := X1;
end;
// Get the change in the Y axis and the Max &; Min Y values
if Y1 >; Y2 then
begin
ChangeInY := Y1 - Y2;
MaxY := Y1;
MinY := Y2;
end
else
begin
ChangeInY := Y2 - Y1;
MaxY := Y2;
MinY := Y1;
end;
// Find out which axis has the greatest change
if ChangeInX >; ChangeInY then
begin
LineLength := ChangeInX;
ChangingX := True;
end
else
begin
LineLength := ChangeInY;
ChangingX := false;
end;
// If the x's match then the line changes only on the Y axis
if X1 = X2 then
begin
// Loop thru the points on the list, lowest to highest.
for i := MinY to MaxY do
begin
Point := TPointFill.Create;
Point.X := X1;
Point.Y := i;
ReturnList.Add(Point);
end;
// If the point was started on the right and went to the left then reverse the list.
if Y1 >; Y2 then
begin
ReversedList := ReversePointOrder(ReturnList);
ReturnList := ReversedList;
end;
end
// If the x's match then the line changes only on the Y axis
else if Y1 = Y2 then
begin
// Loop thru the points on the list, lowest to highest.
for i := MinX to MaxX do
begin
Point := TPointFill.Create;
Point.X := i;
Point.Y := Y1;
ReturnList.Add(Point);
end;
// If the point was started on the bottom and went to the top then reverse the list.
if X1 >; X2 then
begin
ReversedList := ReversePointOrder(ReturnList);
ReturnList := ReversedList;
end;
end
// The line is on an angle
else
begin
// Add the first point to the list.
Point := TPointFill.Create;
Point.X := X1;
Point.Y := Y1;
ReturnList.Add(Point);
// Loop thru the longest axis
for i := 1 to (LineLength - 1) do
begin
Point := TPointFill.Create;
// If we are moving on the x axis then get the related Y point.
if ChangingX then
begin
Point.y := Round((ChangeInY * i)/ChangeInX);
Point.x := i;
end
// otherwise we are moving on the y axis so get the related X point.
else
begin
Point.y := i;
Point.x := Round((ChangeInX * i)/ChangeInY);
end;
// if y1 is smaller than y2 then we are moving in a Top to Bottom direction.
// we need to add y1 to get the next y value.
if Y1 <; Y2 then
Point.y := Point.Y + Y1
// otherwise we are moving in a Bottom to Top direction.
// we need to subtract y1 to get the next y value.
else
Point.Y := Y1 - Point.Y;
// if X1 is smaller than X2 then we are moving in a Left to Right direction
// we need to add x1 to get the next x value
if X1 <; X2 then
Point.X := Point.X + X1
// otherwise we are moving in a Right to Left direction
// we need to subtract x1 to get the next x value.
else
Point.X := X1 - Point.X;
ReturnList.Add(Point);
end;
// Add the second point to the list.
Point := TPointFill.Create;
Point.X := X2;
Heres a nice way of adding a drop shadow to your application under Windows XP.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
protected
procedure CreateParams(var Params: TCreateParams); override; // Important !
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{------------------------------------------------------------}
// Here we check of the user is running Windows XP
function IsWinXP: Boolean;
begin
Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and
(Win32MajorVersion >;= 5) and (Win32MinorVersion >= 1);
end;
{------------------------------------------------------------}
{------------------------------------------------------------}
// Check if it is Windows XP if all is OK then create the drop shadow
procedure TForm1.CreateParams(var Params: TCreateParams);
const
CS_DROPSHADOW = $00020000;
begin
inherited;
if IsWinXP then
Params.WindowClass.Style := Params.WindowClass.Style or CS_DROPSHADOW
else
end;
{------------------------------------------------------------}
end.
private
procedure HitTest(Var Mes : TMessage);message Wm_NcHitTest;
And in implementation :
procedure HitTest(Var Mes : TMessage);
begin
inherited;
if Mes.Result=HtClient then
Mes.Result:=HtCaption;
end;
در onkeypress کد زیر را وارد کنید
if (Key in [#8, 'a'..'z']) then
begin
Showmessage ('Characters are not allowed');
Key:= #0;
procedure TForm1.Button1Click(Sender: TObject);
var
hMenuHandle: hMENU;
hMenuItem: dWord;
p: TPoint;
begin
{recalculate button coordinates to screen coordinates}
p.X := Button1.Left;
p.Y := Button1.Top;
p := Button4.ClientToScreen(p);
hMenuHandle := GetSystemMenu(Handle, False);
hMenuItem := LongWord(Windows.TrackPopupMenu(hMenuHandle, TPM_LEFTBUTTON or TPM_RIGHTBUTTON or TPM_RETURNCMD,
p.X, p.Y, 0, Handle, nil));
if hMenuItem > 0 then
SendMessage(Handle, WM_SYSCOMMAND, hMenuItem, 0);
end;
تعداد صفحات : 13
درباره ما
اطلاعات کاربری
نویسندگان
آمار سایت
کدهای اختصاصی


طراحي وبسايت
دانلود کتاب طراحی الگوریتم CLRS به همراه حل مسائل