Programlama yapalım ve Öğrenelim. - Delphi Eğitim21
  Ana Sayfa
  .NET Eğitim Notları
  Visual C# .NET Örnek Kodları
  VisualBasic.NET Örnek Kodları
  J# Örnekleri
  ASP.NET Örnek Kodları
  Delphi Eğitim
  => Delphi Eğitim1
  => Delphi Eğitim2
  => Delphi Eğitim3
  => Delphi Eğitim4
  => Delphi Eğitim5
  => Delphi Eğitim6
  => Delphi Eğitim7
  => Delphi Eğitim8
  => Delphi Eğitim9
  => Delphi Eğitim10
  => Delphi Eğitim11
  => Delphi Eğitim13
  => Delphi Eğitim14
  => Delphi Eğitim15
  => Delphi Eğitim16
  => Delphi Eğitim17
  => Delphi Eğitim18
  => Delphi Eğitim19
  => Delphi Eğitim20
  => Delphi Eğitim21
  => Delphi Eğitim22
  => Delphi Eğitim23
  => Delphi Eğitim24
  => Delphi Eğitim25
  => Delphi Eğitim26
  => Delphi Eğitim27
  => Delphi Eğitim28
  => Delphi Eğitim29
  => Delphi Eğitim30
  => Delphi Eğtim31
  => Delphi Eğitim32
  => Delphi Eğitim33
  => Delphi Eğitim34
  => Delphi Eğitim35
  => Delphi Eğitim36
  => Delphi Eğitim37
  => Delphi Eğitim38
  => Delphi Eğitim39
  => Delphi Eğitim40
  => Delphi Eğitim41
  => Delphi Eğitim42
  => Delphi Eğitim43
  => Delphi Eğitim44
  => Delphi Eğitim45
  => Delphi Eğitim46
  => Delphi Eğitim47
  => Delphi Eğitim48
  => Delphi Eğitim49
  => Delphi Eğitim50
  => Delphi Eğitim51
  => Delphi Eğitim52
  => Delphi Eğitim53
  => Delphi Eğitim54
  => Delphi Eğitim55
  => Delphi Eğitim56
  => Delphi Eğitim57
  => Delphi Eğitim58
  => Delphi Eğitim59
  => Delphi Eğitim60
  => Delphi Eğitim61
  => Delphi Eğitim62
  => Delphi Eğitim63
  => Delphi Eğitim64
  => Delphi Eğitim65
  => Delphi Eğitim66
  => Delphi Eğitim67
  => Delphi Eğitim68
  => Delphi Eğitim69
  => Delphi Eğitim70
  => Delphi Eğitim71
  => Delphi Eğitim72
  => Delphi Eğitim73
  => Delphi Eğitim74
  => Delphi Eğitim75
  => Delphi Eğitim76
  => Delphi Eğitim77
  => Delphi Eğitim78
  => Delphi Eğitim79
  => Delphi Eğitim80
  => Delphi Eğitim81
  => Delphi Eğitim82
  => Delphi Eğitim83
  => Delphi Eğitim84
  => Delphi Eğitim85
  => Delphi Eğitim86
  => Delphi Eğitim87
  => Delphi Eğitim88
  => Delphi Eğitim89
  => Delphi Eğitim90
  => Delphi Eğitim91
  => Delphi Eğitim92
  => Delphi Eğitim93
  => Delphi Eğitim94
  => Delphi Eğitim95
  => Delphi Eğitim96
  => Delphi Eğitim97
  => Delphi Eğitim98
  => Delphi Eğitim99
  => Delphi Eğitim100
  => Delphi Eğitim101
  => Delphi Eğitim102
  => Delphi Eğitim103
  => Delphi Eğitim104
  => Delphi Eğitim105
  => Delphi Eğitim106
  => Delphi Eğitim107
  => Delphi Eğitim108
  => Delphi Eğitim109
  => Delphi Eğitim110
  => Delphi Eğitim111
  => Delphi Eğitim112
  => Delphi Eğitim113
  => Delphi Eğitim114
  => Delphi Eğitim115
  => Delphi Eğitim116
  => Delphi Eğitim117
  => Delphi Eğitim118
  => Delphi Eğitim119
  => Delphi Eğitim120
  => Delphi Eğitim121
  => Delphi Eğitim122
  => Delphi Eğitim123
  => Delphi Eğitim124
  => Delphi Eğitim125
  => Delphi Eğitim126
  => Delphi Eğitim127
  => Delphi Eğitim128
  => Delphi Eğitim129
  => Delphi Eğitim130
  => Delphi Eğitim131
  => Delphi Eğitim132
  => Delphi Eğitim133
  => Delphi Eğitim134
  => Delphi Eğitim135
  => Delphi Eğitim136
  => Delphi Eğitim137
  => Delphi Eğitim138
  => Delphi Eğitim139
  => Delphi Eğitim140
  => Delphi Eğitim141
  => Delphi Eğitim142
  => Delphi Eğitim143
  => Delphi Eğitim144
  => Delphi Eğitim145
  => Delphi Eğitim146
  => Delphi eğitim147
  => Delphi Eğitim148
  => Delphi Eğitim149
  => Delphi Eğitim150
  => Delphi Eğitim151
  => Delphi Eğitim152
  => Delphi Eğitim153
  => Delphi Eğitim154
  => Delphi Eğitim155
  => Delphi Eğitim156
  => Delphi Eğitim157
  => Delphi Eğitim158
  => Delphi Eğitim159
  => Delphi Eğitim160
  => Delphi Eğitim161
  => Delphi Eğitim162
  => Delphi Eğitim164
  => Delphi Eğitim165
  => Delphi Eğitim166
  => Delphi Eğitim167
  => Delphi Eğitim168
  => Delphi Eğitim169
  => Delphi Eğitim170
  => Delphi Eğitim171
  => Delphi Eğitim172
  => Delphi Eğitim173
  => Delphi Eğitim174
  => Delphi Eğitim175
  => Delphi Eğitim176
  => Delphi Eğitim177
  => Delphi Eğitim178
  => Delphi Eğitim179
  => Delphi Eğitim180
  => Delphi Eğitim181
  => Delphi Eğitim182
  => Delphi Eğitim183
  => Delphi Eğitim184
  => Delphi Eğitim185
  => Delphi Eğitim186
  => Delphi Eğitim187
  => Delphi Eğitim188
  => Delphi Eğitim189
  => Delphi Eğitim190
  => Delphi Eğitim191
  => Delphi Eğitim192
  => Delphi Eğitim193
  => Delphi Eğitim194
  => Delphi Eğitim195
  => Delphi Eğitim196
  => Delphi Eğitim197
  => Delphi Eğitim198
  => Delphi Eğitim199
  => Delphi Eğitim200
  => Delphi Eğitim201
  => Delphi Eğitim202
  => Delphi Eğitim203
  => Delphi Eğitim204
  => Delphi Eğitim205
  => Delphi Eğitim206
  => Delphi Eğitim207
  => Delphi Eğitim208
  => Delphi Eğitim209
  => Delphi Eğitim210
  => Delphi Eğitim211
  => Delphi Eğitim212
  => Delphi Eğitim213
  => Delphi Eğitim214
  => Delphi Eğitim215
  => Delphi Eğitim216
  => Delphi Eğitim217
  => Delphi Eğitim218
  => Delphi Eğitim219
  => Delphi Eğitim220
  => Delphi Eğitim221
  => Delphi Eğitim222
  => Delphi Eğitim223
  => Delphi Eğitim224
  => Delphi Eğitim225
  => Delphi Eğitim226
  => Delphi Eğitim227
  => Delphi Eğitim228
  => Delphi Eğitim229
  => Delphi Eğitim230
  => Delphi Eğitim231
  => Delphi Eğitim232
  => Delphi Eğitim233
  => Delphi Eğitim234
  => Delphi Eğitim235
  => Delphi Eğitim236
  => Delphi Eğitim237
  => Delphi Eğitim238
  => Delphi Eğitim239
  => Delphi Eğitim240
  => Delphi Eğitim241
  => Delphi Eğitim242
  İletişim

Enter tuşunun Tab yerine kullanılabileceği bir Tedit bileşeni

Enter (Return) tuşuna basıldığında Tab tuşuna basılmış etkisi yaratmak için aşağıdaki kod kullanılabilir.

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);

begin

if key=#13 then

begin

   perform(wm_nextdlgctl,0,0);

   key:=#0;

end;

end;

Aşağıdaki bileşen kodu, standart bir Tedit bileşenini, değiştirerek Enter ve Ok tuşlarına tepki verebilecek yeni bir Edit kontrolü haline getirmektedir.

unit Entedit;

interface

uses

  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,

  Forms, Dialogs, StdCtrls;

type

  TEnterEdit = class(TEdit)

  private

  protected

    procedure KeyPress(var Key: Char); override;

    procedure KeyDown(var Key: Word; Shift: TShiftState); override;

  public

  published

  end;

procedure Register;

implementation

 

procedure Register;

begin

  RegisterComponents('Kitap', [TEnterEdit]);

end;

 

procedure TEnterEdit.KeyPress(var Key: Char);

var

   MYForm: TcustomForm;

begin

   if Key = #13 then

   begin

       MYForm := GetParentForm( Self );

       if not (MYForm = nil ) then

           SendMessage(MYForm.Handle, WM_NEXTDLGCTL, 0, 0);

       Key := #0;

   end;

 

   if Key <> #0 then inherited KeyPress(Key);

end;

 

procedure TEnterEdit.KeyDown(var Key: Word; Shift: TShiftState);

var

   MYForm: TcustomForm;

   CtlDir: Word;

begin

 

   if (Key = VK_UP) or (Key = VK_DOWN) then

   begin

       MYForm := GetParentForm( Self );

       if Key = VK_UP then CtlDir := 1

       else CtlDir :=0;

       if not (MYForm = nil ) then

           SendMessage(MYForm.Handle, WM_NEXTDLGCTL, CtlDir, 0);

   end

   else inherited KeyDown(Key, Shift);

end;

end.

Tarih doğru mu

Function Tarihgecerlimi(DateString: String): Boolean;

 

Begin

  Try

    StrToDateTime(DateString);

    Result := True;

  Except

    Result := False;

  End;

End;

Ayda kaç gün var?

Function AydakiGunSayisi(DateValue: TDateTime): Integer;

var

  yil    : Word;

  ay   : Word;

  gün     : Word;

  yeniyil   : Word;

  yeniay  : Word;

  yenigun    : Word;

  sayacr   : Integer;

  yenitarih   : TDateTime;

Begin

  Result := 30;

  Try

    DecodeDate(DateValue, Yil, ay, gun);

    NewDate := EncodeDate(yil, ay, 26);

    For sayac := 26 To 32 Do

    Begin

      yenitarih := NewDate+1;

      DecodeDate(yenitarih, yeniyil, yeniay, yenigun);

      If MonthNew <> MonthIn Then

      Begin

        DecodeDate(yenitarih-1, Yeniyil, yeniay, yenigun);

        Result := yenigun;

        Break;

      End;

    End;

  Except

  End;

End;

Geçen Haftanın ilk Günü

Function GecenHaftaninIlkGunu(DateValue: TDateTime): TDateTime;

Begin

  Result := HaftaninIlkGunu(DateValue-7);

End;

Sonraki Ayın ilk Günü

Function SonrakiAyinIlkGunu(DateValue: TDateTime): TDateTime;

Begin

  Try

    Result  := AyinSonGunu(DateValue)+1;

  Except

    Result  := DateValue;

  End;

End;

Sonraki haftanın ilk günü

Function SonrakiHaftaninIlkGunu(DateValue: TDateTime): TDateTime;

Begin

  Result := HaftaninIlkGunu(DateValue+7);

End;

Haftanın ilk günü

Function HaftaninIlkGunu(DateValue: TDateTime): TDateTime;

Begin

  Try

    Result := DateValue - (DayOfWeek(DateValue)) +1;

  Except

    Result := 0;

  End;

End;

Ayın son günü

Function AyinSonGunu(DateValue: TDateTime): TDateTime;

 

Var

  LastDay : String;

Begin

  LastDay := IntToStr(AydakiGunSayisi(DateValue));

  Result  := StrToDate(

               FormatDateTime('mm',DateValue)+

               '/'+

               LastDay+

               '/'+

               FormatDateTime('yyyy',DateValue));

End;

Ay

Function Ay(DateValue: TDateTime): Integer;

Var

  Year, Month, Day: Word;

Begin

  Result := -1;

  Try

    DecodeDate(DateValue, Year, Month, Day);

    Result := Integer(Month);

  Except

    Result := -1;

  End;

End;

 

Gelecek ay

Function GelecekAy(DateValue: TDateTime): Integer;

Var

  Year, Month, Day: Word;

  CurMonth   : Integer;

  NewMonth  : Integer;

Begin

  Result := -1;

  Try

    DecodeDate(DateValue, Year, Month, Day);

    CurMonth := Integer(Month);

    NewMonth := ((CurMonth + 12 + 1) mod 12);

    If NewMonth = 0 Then NewMonth := 12;

    Result := NewMonth;

  Except

    Result := -1;

  End;

End;

Geçen ay

Function GecenAy(DateValue: TDateTime): Integer;

Var

  Year, Month, Day: Word;

  CurMonth   : Integer;

  NewMonth  : Integer;

Begin

  Result := -1;

  Try

    DecodeDate(DateValue, Year, Month, Day);

    CurMonth := Integer(Month);

    NewMonth := ((CurMonth + 24 - 1) mod 12);

    If NewMonth = 0 Then NewMonth := 12;

    Result := NewMonth;

  Except

    Result := -1;

  End;

End;

Gün sonra

Function nGunSonra(

  DateValue    : TDateTime;

  DateMovement : Integer): TDateTime;

Begin

  Result := DateValue + DateMovement;

End;

Gelecek ay

 

Function GelecekAy(DateValue: TDateTime): TDateTime;

Begin

  Result := nGumSonra(DateValue,1);

End;

Önceki gün

Function onceki_gun(DateValue: TDateTime): TDateTime;

Begin

  Result := NGunSonra(DateValue,-1);

End;

Geçen hafta

Function GecenHaftak(DateValue: TDateTime): TDateTime;

Begin

  Result := nGunSonra(DateValue,-7);

End;

Metin içerisinden bir karakter silme

Function DeleteCharacterInString(InputCharacter,InputString: String): String;

Var

  CharPos : Integer;

Begin

  Result := InputString;

  While True Do

  Begin

    CharPos := Pos(InputCharacter,InputString);

    If Not (CharPos = 0) Then

    Begin

      Delete(InputString,CharPos,1);

    End

    Else

    Begin

      Break;

    End;

  End;

  Result := InputString;

End;

Metin içerisinden, bir karakteri değiştirme

Function ReplaceCharInString(S,OldChar,NewChar :String): String;

Var

  NewString  : String;

  i          : Integer;

  L          : Integer;

  C          : String;

Begin

  Result     := '';

  NewString  := '';

  L          := Length(S);

 

  If L = 0 Then Exit;

 

  If Pos(UpperCase(OldChar),UpperCase(S)) = 0 Then

  Begin

    Result := S;

    Exit;

  End;

 

  For i := 1 To L Do

  Begin

    C := SubStr(S,i,1);

    If UpperCase(C) = UpperCase(OldChar) Then

    Begin

      NewString := NewString + NewChar;

    End

    Else

    Begin

      NewString := NewString + C;

    End;

  End;

  Result     := NewString;

End;

Bir metni belli bir uzunluğa tamamlama

Function StringPad(

  InputStr,//tamamlanacak metin

  FillChar: String;//tamamlama karakteri

  StrLen: Integer;//uzunluk

  StrJustify: Boolean): String;//tamamlama yönü

Var

  TempFill: String;

  Counter : Integer;

Begin

  If Not (Length(InputStr) = StrLen) Then

  Begin

    If Length(InputStr) > StrLen Then

    Begin

      InputStr := SubStr(InputStr,1,StrLen);

    End

    Else

    Begin

      TempFill := '';

      For Counter := 1 To StrLen-Length(InputStr) Do

      Begin

        TempFill := TempFill + FillChar;

      End;

      If StrJustify Then

      Begin

        InputStr := InputStr + TempFill;

      End

      Else

      Begin

        InputStr := TempFill + InputStr ;

      End;

    End;

  End;

  Result := InputStr;

End;

Metin değiştirme

Function String_Replace(

  OldSubString : String;//atılacak metin

  NewSubString : String;//atılanın yerine konacak metin

  SourceString : String): String;//üzerinde dğişiklik

                                               //yapılacak metin

 

Var

  P    : Integer;

  S    : String;

  R    : String;

  LOld : Integer;

  LNew : Integer;

Begin

  S      := SourceString;

  R      := '';

  LOld   := Length(OldSubString);

  LNew   := Length(NewSubString);

  Result := S;

  If OldSubString = '' Then Exit;

  If SourceString = '' Then Exit;

  P := Pos(OldSubString,S);

  If P = 0 Then

  Begin

    R := S;

  End

  Else

  Begin

    While P <> 0 Do

    Begin

      Delete(S,P,LOld);

      R := R + Copy(S,1,P-1)+NewSubString;

      S := Copy(S,P,Length(S)-(P-1));

      P := Pos(OldSubString,S);

      If P = 0 Then R := R + S;

    End;

  End;

  Result := R;

End;

Program içerisinden, başka bir uygulamaya tuş gönderme

WinHand :=  FindWindow(nil,'Untitled - Notepad');

  SetForegroundWindow(WinHand);

  keybd_event(VK_MENU, 0, 0, 0);

  keybd_event(VK_Menu, 0, KEYEVENTF_KEYUP, 0);

  keybd_event(VK_right, 0, 0, 0);

  keybd_event(VK_right, 0, KEYEVENTF_KEYUP, 0);

  keybd_event(VK_right, 0, 0, 0);

  keybd_event(VK_right, 0, KEYEVENTF_KEYUP, 0);

  keybd_event(VK_right, 0, 0, 0);

  keybd_event(VK_right, 0, KEYEVENTF_KEYUP, 0);

  keybd_event(VK_down, 0, 0, 0);

  keybd_event(VK_down, 0, KEYEVENTF_KEYUP, 0);

  keybd_event(VK_down, 0, 0, 0);

  keybd_event(VK_down, 0, KEYEVENTF_KEYUP, 0);

  keybd_event(VK_return, 0, 0, 0);

  keybd_event(VK_return, 0, KEYEVENTF_KEYUP, 0);

Programı Deneme sürümü haline getirme

Programcıların kabusu, ürünlerinin kolaylıkla bedavacıların eline geçmesidir. Bu durum ürünlerin tanıtım sürümlerinin dağıtılmasında bir takım tedbirleri gerektirir. Bunun çok çeşitli yolları vardır. İşte bunlardan birisi. Aşağıdaki fonksiyon, Windows'un global atom tablosuna belirli bir not yazarak, çalışma esnasında bu notu okumaktadır. Şayet not okunabilirse, programın daha önce çalıştırılmış olduğu ortaya çıkar ve uyarı mesajını takiben çalışması durdurulur. Programın yeniden çalıştırılabilmesi için, Windowsun yeniden başlatılması gerekir.

procedure TForm1.FormShow(Sender : TObject);

var atom : integer;

    CRLF : string;

begin

    if

      GlobalFindAtom('Kontrol için kullanılacak metin') = 0 then

         atom := GlobalAddAtom(' Kontrol için kullanılacak metin ')

    else

       begin

          CRLF := #10 + #13;

          ShowMessage('Bu program, her windows sezonunda 1

                                     kez çalışır.'+crlf+'+

                                     Windows'u yeniden başlatın.'+crlf+

                                     'Ya da bizi arayıp satın alın');

          Close;

       end;

end;

ListBox bileşenine yatay kaydırma çubuğu eklenmesi

Delphi'nin TlistBox Bileşeni, satır sayısı gösterebileceğinden fazla ise, otomatik olarak dikey kaydırma çubuğunu kullanıma açar. Fakat satır uzunluğu gösterebileceği genişlikten daha fazla ise, bir kolaylık sağlamaz. Aşağıdaki kod kullanılarak, yatay kaydırma çubuğununda eklenmesi sağlanabilir.

Aşağıdaki kod, formun OnCrate olay yordamına yazılmalıdır.

 procedure TForm1.FormCreate(Sender: TObject);

var

i, MaxWidth: integer;

begin

MaxWidth := 0;

for i := 0 to ListBox1.Items.Count - 1 do

if MaxWidth < ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]) then

MaxWidth := ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]);

SendMessage(ListBox1.Handle, LB_SETHORIZONTALEXTENT, MaxWidth+2, 0);

end;

Kod öncelikle, listbox içerisindeki en uzun satırın uzunluğunun Piksel cinsinden hesaplar. Ondan sonra LB_SETHORIZONTALEXTENT mesajını kullanarak, yatay kaydırma çubuğunu ayarlar.

Kontrol panel apletlerinin Delphi içerisinden kullanılması

Bazı sistem ayarları, kontrol panelden yapılmaktadır. Program içerisinden bu ayarlara müdahele etmek gerektiğinde, en kolay yol yine kontrol panel apletlerini kullanmaktır. Aşağıdaki fonksiyon, istenen kontrol panel apletini çalıştırmaktadır.

unit open_cpl;

interface

function RunControlPanelApplet(

 sAppletFileName : string) : integer;

implementation

uses Windows;

//sAppletFileName değeri aşağıdaki tablodan seçilebilir.

function RunControlPanelApplet(

 sAppletFileName : string) : integer;

begin

 Result :=

 WinExec(

  PChar('rundll32.exe shell32.dll,'+

  'Control_RunDLL '+sAppletFileName),

  SW_SHOWNORMAL);

end;

end.

Windows95 ve NT de ortak olan kontrol panel apletleri şunlardır.

access.cpl  Erişilebilirlik

appwiz.cpl  Program ekle/kaldır

desk.cpl    Görüntü

intl.cpl    Bölgesel ayarlar

joy.cpl     Oyun çubuğu

main.cpl    Fare

mmsys.cpl   Çoklu ortam

modem.cpl   Modem

sysdm.cpl   Sistem

timedate.cpl      Tarih/Saat

Sistem Tarih/Saat ayarının değiştirilmesi

Sistemin tarih ve saat ayarları programsal olarak da değiştirilebilir. Bunun için Aşağıdaki fonksiyonu kullanabilirsiniz.

function SetPCSystemTime(tDati: TDateTime): Boolean;

var

   tSetDati: TDateTime;

   vDatiBias: Variant;

   tTZI: TTimeZoneInformation;

   tST: TSystemTime;

begin

   GetTimeZoneInformation(tTZI);

   vDatiBias := tTZI.Bias / 1440;

   tSetDati := tDati + vDatiBias;

   with tST do

   begin

        wYear := StrToInt(FormatDateTime('yyyy', tSetDati));

        wMonth := StrToInt(FormatDateTime('mm', tSetDati));

        wDay := StrToInt(FormatDateTime('dd', tSetDati));

        wHour := StrToInt(FormatDateTime('hh', tSetDati));

        wMinute := StrToInt(FormatDateTime('nn', tSetDati));

        wSecond := StrToInt(FormatDateTime('ss', tSetDati));

        wMilliseconds := 0;

   end;

   SetPCSystemTime := SetSystemTime(tST);

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

tti:tdatetime;

begin

tti:=strtodatetime('11.11.98 14:15:20');

Setpcsystemtime(tti)

"     ALT+TAB ve CTRL+ALT+DEL tuş kombinasyonlarının kullanıma kapatılması

Eğer programınız çalışırken, kullanıcıların bu tuş kombinasyonlarını kullanmasını istemiyorsanız, aşağıdaki kod örneği tam size göre

uses

  WinProcs;

 

{$R *.RES}

 

var

   Dummy : integer;

 

begin

  Dummy := 0;

//ALT+TAB kombinasyonu için

  SystemParametersInfo( SPI_SETFASTTASKSWITCH, 1, @Dummy, 0);

 

//CTRL+ALT+DEL kombinasyonu için

SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @Dummy, 0);

end.

Ekran koruyucunun devreden çıkarılması

SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, Addr(SaverActive), 0);

if SaverActive then

  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, nil, SPIF_UPDATEINIFILE);

Burada "SaverActive" global bir Boolean değişkendir. Ekran koruyucu tekrar aktif hale getirilmek istendiğinde ise

if SaverActive then

  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, nil, SPIF_UPDATEINIFILE);

Diğer bir yol ise, şu şekildedir. Bir ekran koruyucu çalışmaya başlamadan önce "WM_SYSCOMMAND" mesajı gönderir. Bu mesaj yakalanarak ekran koruyucunun devreye girmesi engellenir. TApplication nesnesinin OnMessage. Olayı yerine kullanılacak yeni bir davranış yaratıp bu mesajı herkesden önce yakalayabiliriz.

Bu işlem şöyle olur.

procedure AppMessage(var Msg: TMsg; var Handled: Boolean);

Daha sonra ana formun OnCreate davranışı içerisinde,

Application.OnMessage := AppMessage;

Appmessage yordamında yakalanan mesajın WM_sysCommand ve Wparam değerinin de SC_ScreenSave olup olmadığı kontrol edilir. Eğer öyle ise, Handled parametresi True yapılarak, o mesajın işlem gördüğü imajı yaratılarak, windows'un ekran koruyucuyu başlatması engellenir.

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);

begin

  if (Msg.Message = WM_SYSCOMMAND) and

    ((Msg.wParam) = SC_SCREENSAVE) then begin

    Handled := True;

  end;

end;

Programın, windowsun başlangıcında çalıştırılması

Windows Startup klasörüne konan programlar, windowsun başlaması ile birlikte çalışmaya başlarlar. Fakat bunu program içerisinden yapmak istiyorsanız, veya programınız, bir kereye mahsus başlangıçta çalışsın istiyorsanız,aşağıdaki fonksiyonu kullanarak geçici veya kalıcı olarak gerekeni yapabilirsiniz.

procedure RunOnStartup(

  sProgTitle,

  sCmdLine    : string;

  bRunOnce    : boolean );

var

  sKey : string;

  reg  : TRegIniFile;

begin

  if( bRunOnce )then

    sKey := 'Once'

  else

    sKey := '';

 

  reg := TRegIniFile.Create( '' );

  reg.RootKey := HKEY_LOCAL_MACHINE;

  reg.WriteString(

    'SoftwareMicrosoft'

    + 'WindowsCurrentVersionRun'

    + sKey + #0,

    sProgTitle,

    sCmdLine );

  reg.Free;

end;
end.

Bu web sitesi ücretsiz olarak Bedava-Sitem.com ile oluşturulmuştur. Siz de kendi web sitenizi kurmak ister misiniz?
Ücretsiz kaydol