Modifikasi Message Dialog Delphi


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
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.

TransCODE Software

Daftar Semua File Dalam Direktory


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses

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

type
TForm1 = class(TForm)
btn1: TButton;
lst1: TListBox;
procedure btn1Click(Sender: TObject);
private

{ Private declarations }
public
{ Public declarations }
end;

var

Form1: TForm1;

implementation


{$R *.DFM}

procedure ListFileDir(Path: string; FileList: TStrings);
var
SR: TSearchRec;
begin
if FindFirst(Path + ‘*.*’, faAnyFile, SR) = 0 then
begin
repeat
if (SR.Attr <> faDirectory) then
begin
FileList.Add(SR.Name);
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
ListFileDir(‘C:\WINDOWS\’, Lst1.Items);
end;

end.

TransCODE Software

Display Waktu Pada Caption


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
dc: hDC;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var
TheTime: array[0..80] of char;
begin
StrPCopy(TheTime, TimeToStr(time));
TextOut(dc, width DIV 2, 5, TheTime, StrLen(TheTime));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
dc := GetWindowDC(handle);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ReleaseDC(handle, dc);
end;

end.

TransCODE Software

Minimize Semua Window


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
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.

TransCODE Software

Mendeteksi VGA Card


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Memo1: TMemo;
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
lpDisplayDevice: TDisplayDevice;
dwFlags: DWORD;
cc: DWORD;
begin
memo1.Clear;
lpDisplayDevice.cb := sizeof(lpDisplayDevice);
dwFlags := 0;
cc:= 0;
while EnumDisplayDevices(nil, cc, lpDisplayDevice , dwFlags) do
begin
Inc(cc);
memo1.lines.add(lpDisplayDevice.DeviceString);
show;
end;
end;

end.

TransCODE Software