Google
 

Thursday, July 30, 2009

Make System Tray Application in delphi,


Make System Tray Application in Delphi in order to run background or placed on system tray is very easy. We Only need one API function that is Shell_NotifyIcon,the Application will be run as system tray with there function.
The First at private you must declaration
private
{ Private declarations }
systemTrayIcon:TNotifyIconData;

And Then, make a form, on event on Create add script below this

with systemTrayIcon do
begin
cbSize := Sizeof(systemTrayIcon);
Wnd:=Handle;
uID := 0;
uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
uCallbackMessage := WM_USER;
hIcon := Application.Icon.Handle;
StrCopy(szTip,'Aplikasi System Tray');
End;
Shell_NotifyIcon(NIM_ADD,@systemTrayIcon);

xplanation script above are :
Wnd is parameter from systemTrayIcon that use for appear icon on system tray and receive message information from system.
hIcon is parameter for appear icon on system tray
szTip is parameter for appear icon tips on system tray
And then the most important part is Shell_NotifyIcon(NIM_ADD,@systemTrayIcon); that useful to place application on system tray
To make our application disable on taskbar we must add some line in project part :

begin
Application.Initialize;
Application.ShowMainForm := false; //tambahkan baris ini
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

If you want to disable icon when you close yout application you must add some code below on even OnDestroy at Form1
Shell_NotifyIcon(NIM_DELETE,@systemTrayIcon);

After you finished, now we make our application can run normally or foreground, we can make a procedure,
Example i have declaration procedure gotoTray at private section

procedure gotoTray(pesan :TMessage);
message WM_USER;

if you have been declaration, we must make implementation of procedure gotoTray.
This script below is implementation of procedure gotoTray

procedure TForm1.gotoTray(pesan :TMessage);
begin
case pesan.LParam of
WM_LBUTTONDOWN:
begin
ShowMessage('Form ditampilkan');
Form1.Show;
end;
WM_RBUTTONDOWN:
begin
ShowMessage('Form Menuju System Tray');
Form1.Hide;
end;
end;
end;

Tuesday, August 26, 2008

ganti atribut file

The following code reads a file's attributes into a set variable, sets the check boxes in a file-attribute dialog box to represent the current attributes, then executes the dialog box. If the user changes and accepts any dialog box settings, the code sets the file attributes to match the changed settings:

procedure TFMForm.Properties1Click(Sender: TObject);
var
Attributes, NewAttributes: Word;
begin
with FileAttrForm do
begin
FileDirName.Caption := FileList.Items[FileList.ItemIndex];
{ set box caption }
PathName.Caption := FileList.Directory;
{ show directory name }
ChangeDate.Caption :=
DateTimeToStr(FileDateToDateTime(FileAge(FileList.FileName)));
Attributes := FileGetAttr(FileDirName.Caption);
{ read file attributes }
ReadOnly.Checked := (Attributes and SysUtils.faReadOnly) = faReadOnly;
Archive.Checked := (Attributes and faArchive) = faArchive;
System.Checked := (Attributes and faSysFile) = faSysFile;
Hidden.Checked := (Attributes and faHidden) = faHidden;
if ShowModal <> id_Cancel then { execute dialog box }
begin
NewAttributes := Attributes;
{ start with original attributes }
if ReadOnly.Checked then
NewAttributes := NewAttributes or SysUtils.faReadOnly
else
NewAttributes := NewAttributes and not SysUtils.faReadOnly;
if Archive.Checked then
NewAttributes := NewAttributes or faArchive
else
NewAttributes := NewAttributes and not faArchive;
if System.Checked then
NewAttributes := NewAttributes or faSysFile
else
NewAttributes := NewAttributes and not faSysFile;
if Hidden.Checked then
NewAttributes := NewAttributes or faHidden
else
NewAttributes := NewAttributes and not faHidden;
if NewAttributes <> Attributes then { if anything changed... }
FileSetAttr(FileDirName.Caption, NewAttributes);
{ ...write the new values }
end;
end;
end;

Delphi - membuka control panel

Membuka Control Panel

Gunakan kode di bawah ini untuk membuka Control Panel dari program Delphi Anda. Jangan lupa tampahkan ShellApi pada bagian uses :

procedure TForm1.Buton1Click(Sender : TObject);
begin
ShellExecute(Handle,\'Open\',\'control\',
nil,nil,SW_SHOWNORMAL);
end;