Tuesday, January 4, 2011

Animate tray application windows as they open and close

unit UTrayZoom;

interface

uses
Windows;

type
TTrayZoom = class(TObject)
private
class function GetTrayRect: TRect;
class procedure DoZoom(const Wnd: HWND; const Src, Dest: TRect);
public
class procedure ZoomToTray(const Wnd: HWND);
class procedure ZoomFromTray(const Wnd: HWND);
end;

implementation

class procedure TTrayZoom.DoZoom(const Wnd: HWND; const Src, Dest: TRect);
begin
DrawAnimatedRects(Wnd, IDANI_CAPTION, Src, Dest);
end;

class function TTrayZoom.GetTrayRect: TRect;
var
TaskbarWnd, TrayWnd: HWND;
begin
TaskbarWnd := FindWindow('Shell_TrayWnd', nil);
TrayWnd := FindWindowEx(TaskbarWnd, 0, 'TrayNotifyWnd', nil);
GetWindowRect(TrayWnd, Result);
end;

class procedure TTrayZoom.ZoomFromTray(const Wnd: HWND);
var
WndRect: TRect;
begin
GetWindowRect(Wnd, WndRect);
DoZoom(Wnd, GetTrayRect, WndRect);
end;

class procedure TTrayZoom.ZoomToTray(const Wnd: HWND);
var
WndRect: TRect;
begin
GetWindowRect(Wnd, WndRect);
DoZoom(Wnd, WndRect, GetTrayRect);
end;

end.

Change the button captions in a message dialog box

function MyMessageDialog(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; Captions: array of string): Integer;
var
aMsgDlg: TForm;
i: Integer;
dlgButton: TButton;
CaptionIndex: Integer;
begin
{ Create the Dialog }
aMsgDlg := CreateMessageDialog(Msg, DlgType, Buttons);
captionIndex := 0;
{ Loop through Objects in Dialog }
for i := 0 to aMsgDlg.ComponentCount - 1 do
begin
{ If the object is of type TButton, then }
if (aMsgDlg.Components[i] is TButton) then
begin
dlgButton := TButton(aMsgDlg.Components[i]);
if CaptionIndex > High(Captions) then Break;
{ Give a new caption from our Captions array}
dlgButton.Caption := Captions[CaptionIndex];
Inc(CaptionIndex);
end;
end;
Result := aMsgDlg.ShowModal;
end;
Usage example:
procedure TForm1.Button1Click(Sender: TObject);
begin
if MyMessageDialog('How much...?', mtConfirmation, mbOKCancel,
['1', '2']) = mrOk then
ShowMessage('"1" clicked')
else
ShowMessage('"2" clicked');
end;

Modifikasi Message Dialog Delphi

unit Unit1;
interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type

TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public

{ Public declarations }
end;
var
Form1: TForm1;

implementation

{$R *.DFM}
function MyMessageDialog(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; Captions: array of string): Integer;
var
aMsgDlg: TForm;
i: Integer;
dlgButton: TButton;
CaptionIndex: Integer;
begin
aMsgDlg := CreateMessageDialog(Msg, DlgType, Buttons);
captionIndex := 0;
aMsgDlg.Color:=clYellow;
aMsgDlg.Caption:=’Pesan’;
for i := 0 to aMsgDlg.ComponentCount – 1 do
begin
if (aMsgDlg.Components[i] is TButton) then
begin
dlgButton := TButton(aMsgDlg.Components[i]);
if CaptionIndex > High(Captions) then Break;
dlgButton.Caption := Captions[CaptionIndex];
Inc(CaptionIndex);
end;
end;
Result := aMsgDlg.ShowModal;
end;
procedure Delay(msec: Longint);
var
start, stop: Longint;
begin
start := GetTickCount;
repeat
stop := GetTickCount;
Application.ProcessMessages;
until (stop – start) >= msec;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
if MyMessageDialog(‘Anda yakin…?’, mtConfirmation, mbOKCancel,
['Ya', 'Tidak']) = mrOk then
ShowMessage(‘”Ya” clicked‘)
else
ShowMessage(‘”Tidak” clicked‘);
end;


end.

Minimize Semua Window

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure
TForm1.Button1Click(Sender: TObject);
var
h : HWnd;
begin
h:=handle;
while h > 0 do
begin
if IsWindowVisible(h) then
Postmessage(h,WM_SYSCOMMAND,SC_MINIMIZE,0);
h:=GetnextWindow(h,GW_HWNDNEXT);
end;
end;
end.

Teks Berjalan Pada Form Caption

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Old_Title : String;

implementation

{$R *.DFM}

procedure
TForm1.FormCreate(Sender: TObject);
begin
Application.Title := ‘Selamat Belajar Delphi ‘;
Old_Title := Application.Title;
end;

procedure
TForm1.Timer1Timer(Sender: TObject);
var
temp : string;
begin
Temp := Application.Title;
Temp := Temp+Temp[1];
Temp := Copy(Temp,2,length(temp)-1);
Application.Title := temp;
Form1.Caption:=temp;
end;

procedure
TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled := NOT Timer1.Enabled;
if Timer1.Enabled = False then
begin
Application.Title := Old_Title;
Form1.Caption := Old_Title;
end;
end;
end.

Aplikasi bisa dijalankan sekali saja

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type

TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const
NamaAtom =’Program versi demo‘;

implementation

{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
atom : integer;
begin
if GlobalFindAtom(NamaAtom) = 0 then
atom := GlobalAddAtom(NamaAtom)
else
begin
ShowMessage(‘Program ini hanya dapat dijalankan sekali dalam satu sesi Windows’ + #10 + #13 +
‘Untuk menjalankan program ini lagi, restart komputer Anda atau silakan‘ + #10 + #13 +
REGISTER !!‘);
Application.Terminate;
end;
end;
end.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum