Mengubah Resolusi Layar


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;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
function SetScreenResolution(Width, Height: integer): Longint;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
OldWidth, OldHeight: integer;

implementation

{$R *.DFM}

function
TForm1.SetScreenResolution(Width, Height: integer): Longint;
var
DeviceMode: TDeviceMode;
begin
with DeviceMode do
begin
dmSize := SizeOf(TDeviceMode);
dmPelsWidth := Width;
dmPelsHeight := Height;
dmFields := DM_PELSWIDTH or DM_PELSHEIGHT;
end;
Result := ChangeDisplaySettings(DeviceMode, CDS_UPDATEREGISTRY);
end;

procedure
TForm1.Button1Click(Sender: TObject);
begin
SetScreenResolution(640, 480);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin

//resolusi semula
SetScreenResolution(OldWidth, OldHeight);
end;

procedure
TForm1.FormCreate(Sender: TObject);
begin
OldWidth := GetSystemMetrics(SM_CXSCREEN);
OldHeight := GetSystemMetrics(SM_CYSCREEN);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
SetScreenResolution(800, 600);
end;


procedure
TForm1.Button4Click(Sender: TObject);
begin
SetScreenResolution(1024, 768);
end;

end.

TransCODE Software

Menyimpan Posisi Form


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

interface

uses

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

type

TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses IniFiles;

procedure TForm1.FormCreate(Sender: TObject);
var
INI: TIniFile;
begin
INI := TIniFile.Create(ChangeFileExt(ParamStr(0), ‘.INI’));
Top  := INI.ReadInteger(ClassName, ‘Top’, 0);
Left := INI.ReadInteger(ClassName, ‘Left’, 0);
INI.Free;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
INI: TIniFile;
begin
INI := TIniFile.Create(ChangeFileExt(ParamStr(0), ‘.INI’));
INI.WriteInteger(ClassName, ‘Top’, Top);
INI.WriteInteger(ClassName, ‘Left’, Left);
INI.Free;
end;

end.

TransCODE Software

Warna Teks Pada MessageDialog


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
MsgForm : TForm;
i : integer;
begin
MsgForm := CreateMessageDialog(‘Tulisan ini berwarna merah !!’, mtInformation, [mbOK]);
with MsgForm do
begin
for i:=0 to ComponentCount-1 do
if Components[i] is TLabel then
(Components[i] as TLabel).Font.Color := clRed;
ShowModal;
end;
MsgForm.Free;
end;

end.

TransCODE Software

Mengirim teks ke Notepad


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)
edt1: TEdit;
procedure edt1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.edt1Change(Sender: TObject);
var
wnd: HWND;
i: Integer;
s: string;
begin
// mencari handle Notepad

wnd := FindWindow(‘notepad’, nil);
if wnd <> 0 then
begin
wnd := FindWindowEx(wnd, 0, ‘Edit’, nil);

// Teks yang akan dikirim
s := Edt1.Text;
// menulis teks pada Notepad
for i := 1 to Length(s) do
SendMessage(wnd, WM_CHAR, Word(s[i]), 0);
// simulasi tombol enter
PostMessage(wnd, WM_KEYDOWN, VK_RETURN, 0);
// simulasi tombol spasi
PostMessage(wnd, WM_KEYDOWN, VK_SPACE, 0);
end;
end;

end.

TransCODE Software

Enkripsi dan Deskripsi


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)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Button2: TButton;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
function Decrypt(S: string): string;
function Encrypt(S: string): string;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.Encrypt(S: string): string;
var
Angka, i: Integer;
begin
Result := ‘ ‘ + S;
Angka := 32;
for i := 1 to Length(S) do begin
Angka := Angka + Ord(S[i]);
while Angka > 126 do
Angka := Angka – 95;
end;
Result[1] := Chr(Angka);
for i := 2 to Length(Result) do begin
Angka := Ord(Result[i]) + Ord(Result[i – 1]);
while Angka > 126 do
Angka := Angka – 95;
Result[i] := Chr(Angka);
end;
end;

function TForm1.Decrypt(S: string): string;
var
Angka1, Angka2,
Angka, i: Integer;
begin
Result := S;
for i := Length(S) downto 2 do begin
Angka1 := Ord(S[i]);
Angka2 := Ord(S[i – 1]);
if Angka1 >= Angka2 then
Angka := Angka1 – Angka2
else
Angka := (Angka1 + 95) – Angka2;
while Angka < 32 do
Angka := Angka + 95;
Result[i] := Chr(Angka);
end;
Delete(Result, 1, 1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit2.Text := Encrypt(Edit1.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Edit3.Text := Decrypt(Edit2.Text);
end;

end.

TransCODE Software