شهریور ماه 87 - کدهای آماده دلفی افزایش بازدید - افزایش بازدید و ترافیک سایت شما
سفارش تبلیغ
صبا ویژن
توانگرى و درویشى آنگاه آشکار شود که در قیامت عرضه بر کردگار شود . [نهج البلاغه]
کدهای آماده دلفی

 

برای استفاده ابتدا یک یونیت جدید ایجاد کنید و نام آن را MSProdKey بگذارید و ان را به دلفی معرفی کنید. اگر مشکلی در استفاده از این یونیت داشتید حتما در تالار بیان کنید.

unit MSProdKey;

interface

uses Registry, Windows, SysUtils, Classes;

function IS_WinVerMin2K: Boolean; // Check OS for Win 2000 or higher
function View_Win_Key: string; // View the Windows Product Key
function IS_OXP_Installed: Boolean;  // Check if Office XP is installed
function View_OXP_Key: string;  // View the Office XP Product Key
function IS_O2K3_Installed: Boolean; // Check if Office 2003 is installed
function View_O2K3_Key: string; // View the Office 2003 Product Key
function DecodeProductKey(const HexSrc: array of Byte): string;
  // Decodes the Product Key(s) from the Registry

var
  Reg: TRegistry;
  binarySize: INTEGER;
  HexBuf: array of BYTE;
  temp: TStringList;
  KeyName, KeyName2, SubKeyName, PN, PID, DN: string;

implementation

function IS_WinVerMin2K: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  Result := (OS.dwMajorVersion >= 5) and
    (OS.dwPlatformId = VER_PLATFORM_WIN32_NT);
  PN     := ""; // Holds the Windows Product Name
  PID    := ""; // Holds the Windows Product ID
end;


function View_Win_Key: string;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKeyReadOnly("\SOFTWARE\Microsoft\Windows NT\CurrentVersion") then
    begin
      if Reg.GetDataType("DigitalProductId") = rdBinary then
      begin
        PN         := (Reg.ReadString("ProductName"));
        PID        := (Reg.ReadString("ProductID"));
        binarySize := Reg.GetDataSize("DigitalProductId");
        SetLength(HexBuf, binarySize);
        if binarySize > 0 then
        begin
          Reg.ReadBinaryData("DigitalProductId", HexBuf[0], binarySize);
        end;
      end;
    end;
  finally
    FreeAndNil(Reg);
  end;

  Result := "";
  Result := DecodeProductKey(HexBuf);
end;

function IS_OXP_Installed: Boolean;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    Result      := Reg.KeyExists("SOFTWARE\MICROSOFT\Office\10.0\Registration");
  finally
    Reg.CloseKey;
    Reg.Free;
  end;
  DN  := ""; // Holds the Office XP Product Display Name
  PID := ""; // Holds the Office XP Product ID
end;

function View_OXP_Key: string;
begin
  try
    Reg         := TRegistry.Create;
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    KeyName     := "SOFTWARE\MICROSOFT\Office\10.0\Registration\";
    Reg.OpenKeyReadOnly(KeyName);
    temp := TStringList.Create;
    Reg.GetKeyNames(temp); // Enumerate and hold the Office XP Product(s) Key Name(s)
    Reg.CloseKey;
    SubKeyName  := temp.Strings[0]; // Hold the first Office XP Product Key Name
    Reg         := TRegistry.Create;
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    KeyName2    := "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\";
    Reg.OpenKeyReadOnly(KeyName2 + SubKeyName);
    DN := (Reg.ReadString("DisplayName"));
    Reg.CloseKey;
  except
    on E: EStringListError do
      Exit
  end;
  try
    if Reg.OpenKeyReadOnly(KeyName + SubKeyName) then
    begin
      if Reg.GetDataType("DigitalProductId") = rdBinary then
      begin
        PID        := (Reg.ReadString("ProductID"));
        binarySize := Reg.GetDataSize("DigitalProductId");
        SetLength(HexBuf, binarySize);
        if binarySize > 0 then
        begin
          Reg.ReadBinaryData("DigitalProductId", HexBuf[0], binarySize);
        end;
      end;
    end;
  finally
    FreeAndNil(Reg);
  end;

  Result := "";
  Result := DecodeProductKey(HexBuf);
end;

function IS_O2K3_Installed: Boolean;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    Result      := Reg.KeyExists("SOFTWARE\MICROSOFT\Office\11.0\Registration");
  finally
    Reg.CloseKey;
    Reg.Free;
  end;
  DN  := ""; // Holds the Office 2003 Product Display Name
  PID := ""; // Holds the Office 2003 Product ID
end;

function View_O2K3_Key: string;
begin
  try
    Reg         := TRegistry.Create;
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    KeyName     := "SOFTWARE\MICROSOFT\Office\11.0\Registration\";
    Reg.OpenKeyReadOnly(KeyName);
    temp := TStringList.Create;
    Reg.GetKeyNames(temp);
    // Enumerate and hold the Office 2003 Product(s) Key Name(s)
    Reg.CloseKey;
    SubKeyName  := temp.Strings[0]; // Hold the first Office 2003 Product Key Name
    Reg         := TRegistry.Create;
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    KeyName2    := "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\";
    Reg.OpenKeyReadOnly(KeyName2 + SubKeyName);
    DN := (Reg.ReadString("DisplayName"));
    Reg.CloseKey;
  except
    on E: EStringListError do
      Exit
  end;
  try
    if Reg.OpenKeyReadOnly(KeyName + SubKeyName) then
    begin
      if Reg.GetDataType("DigitalProductId") = rdBinary then
      begin
        PID        := (Reg.ReadString("ProductID"));
        binarySize := Reg.GetDataSize("DigitalProductId");
        SetLength(HexBuf, binarySize);
        if binarySize > 0 then
        begin
          Reg.ReadBinaryData("DigitalProductId", HexBuf[0], binarySize);
        end;
      end;
    end;
  finally
    FreeAndNil(Reg);
  end;

  Result := "";
  Result := DecodeProductKey(HexBuf);
end;

function DecodeProductKey(const HexSrc: array of Byte): string;
const
  StartOffset: Integer = $34; { //Offset 34 = Array[52] }
  EndOffset: Integer   = $34 + 15; { //Offset 34 + 15(Bytes) = Array[64] }
  Digits: array[0..23] of CHAR = ("B", "C", "D", "F", "G", "H", "J",
    "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9");
  dLen: Integer = 29; { //Length of Decoded Product Key }
  sLen: Integer = 15;
  { //Length of Encoded Product Key in Bytes (An total of 30 in chars) }
var
  HexDigitalPID: array of CARDINAL;
  Des: array of CHAR;
  I, N: INTEGER;
  HN, Value: CARDINAL;
begin
  SetLength(HexDigitalPID, dLen);
  for I := StartOffset to EndOffset do
  begin
    HexDigitalPID[I - StartOffSet] := HexSrc[I];
  end;

  SetLength(Des, dLen + 1);

  for I := dLen - 1 downto 0 do
  begin
    if (((I + 1) mod 6) = 0) then
    begin
      Des[I] := "-";
    end
    else
    begin
      HN := 0;
      for N := sLen - 1 downto 0 do
      begin
        Value := (HN shl 8) or HexDigitalPID[N];
        HexDigitalPID[N] := Value div 24;
        HN    := Value mod 24;
      end;
      Des[I] := Digits[HN];
    end;
  end;
  Des[dLen] := Chr(0);

  for I := 0 to Length(Des) do
  begin
    Result := Result + Des[I];
  end;
end;

end.



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:41 عصر

 

با این کد می توانید ورژن (نگارش) ورد نصب شده را بدست آورید.

function GetInstalledWordVersion: Integer;
var
  word: OLEVariant;
begin
  word := CreateOLE("Word.Application");
  result := word.version;
  word.Quit;
  word := UnAssigned;
end;



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:40 عصر



 

خروجی این فانکشن یک خروجی منطقی است.با این کد می توانید به سادگی تشخیص دهید که سطل زباله خالی است یا پر.

uses
  Activex, ShlObj, ComObj;


function RecycleBinIsEmpty: Boolean;
const
  CLSID_IRecycleBin: TGUID = (D1: $645FF040; D2: $5081; D3: $101B;
    D4: ($9F, $08, $00, $AA, $00, $2F, $95, $4E));
var
  EnumIDList: IEnumIDList;
  FileItemIDList: PItemIDList;
  ItemCount: ULONG;
  RecycleBin: IShellFolder;
begin
  CoInitialize(nil);
  OleCheck(CoCreateInstance(CLSID_IRecycleBin, nil, CLSCTX_INPROC_SERVER or
    CLSCTX_LOCAL_SERVER, IID_IShellFolder, RecycleBin));
  RecycleBin.Enums(0,
    SHCONTF_FOLDERS or
    SHCONTF_NONFOLDERS or
    SHCONTF_INCLUDEHIDDEN,
    EnumIDList);
  Result := EnumIDList.Next(1, FileItemIDList, ItemCount) <> NOERROR;
  CoUninitialize;
end;



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:40 عصر

 

با این کد می توانید تعیین کنید که آیا هر یک از اجزای Office در حال اجرا می باشند یا خیر

uses
  ComObj, ActiveX;

function IsActive(ClassName: string): Boolean;
var
  ClassID: TCLSID;
  Unknown: IUnknown;
begin
  try

    ClassID := ProgIDToClassID(ClassName);
    Result  := GetActive(ClassID, nil, Unknown) = S_OK;
  except
    // raise;
    Result := False;
  end;
end;

 مثال:

procedure TForm1.Button1Click(Sender: T);
begin
  if IsActive("Word.Application") then ShowMessage("Word is running !");
  if IsActive("Excel.Application") then ShowMessage("Excel is running !");
  if IsActive("Outlook.Application") then ShowMessage("Outlook is running !");
  if IsActive("Access.Application") then ShowMessage("Access is running !");
  if IsActive("Powerpoint.Application") then ShowMessage("Powerpoint is running !");
end;



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:40 عصر

 

با این تابع شما می توانید امکان ارسال ایمیل را برای کاربر فراهم سازید.این کد از ایمیل سندر ویندوز استفاده می کند.ویژگی این کد نسبت به دیگر کدهای موجود این است که شما می توانید متن نامه و مضوع آن را نیز به طور پیش فرض برای کاربر قرار دهید.در کد زیر Subject نامه کلمه ی Test و Body ایمیل This Is Body است.

MailTo := "mailto:someone@somewhere.com?subject=Test&body=This Is Body";

if ShellExecute(GetDesktopWindow(), "open", PChar(MailTo), nil, nil,SW_SHOWNORMAL) <= 32 then
 MessageDlg("An Error occurred with Mail!",mtError,[mbOK],0);



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:38 عصر

 

خروجی یک مقدار منطقی است.با این کد به راحتی می توانید تشخیص دهید که آیا AutoHide در Task Bar فعال است یا خیر؟

uses ShellAPI;

function IsTaskbarAutoHideOn : boolean;
var
  ABData : TAppBarData;
begin
  ABData.cbSize := sizeof(ABData);
  Result :=
    (SHAppBarMessage(ABM_GETSTATE, ABData)
     and ABS_AUTOHIDE) > 0;
end;



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:38 عصر

 

با این کد می توانید به راحتی از داخل برنامه ی خودتان فایل های دیگر را اجرا کنید.

function ExecuteFile(const FileName, Params, DefaultDir: string;
  ShowCmd: Integer): THandle;
var
  zFileName, zParams, zDir: array[0..79] of Char;
begin 
  Result := ShellExecute(Application.MainForm.Handle, nil,
    StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
    StrPCopy(zDir, DefaultDir), ShowCmd);
end;

مثال:

 ExecuteFile("notepad.exe","","",1)



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:37 عصر

 

یک Message Dialog با امکان تغییر نوشته ی دکمه و تمام قسمتها:

function CustomMsg(const DlgCaption,Text:string; MsgType:TMsgDlgType; Buttons:TMsgDlgButtons):integer;
var
  MsgBox   : TForm;
  i        : byte;
  PicWidth : integer;
begin
  MsgBox := CreateMessageDialog(Text,MsgType,Buttons);
  try
    //Change TEXT Properties
    with (MsgBox.Controls[1] as Tlabel) do
    begin
      Font.Name := "Tahoma";
      Font.Style := Font.Style + [fsBOLD];
      Font.Size := 8;
      WordWrap := False;
    end;
    //Change Messagebox Properties
    with MsgBox do
    begin
//      BiDiMode := bdRightToLeft;
      Font.Name := "Tahoma";
      Font.Size := 8;
      Caption := DlgCaption;
      Width := (Controls[0] as TImage).Width +
               (Controls[1] as Tlabel).Width + 100;
    end;
  //Change Buttons" caption
    for i := 0 to MsgBox.ControlCount-1 do
      if (MsgBox.Controls[i] is TButton) then
        with (MsgBox.Controls[i] as TButton) do
        begin
          if      (UpperCase(Caption) = "&OK")         then Caption := "EC??I"
          else if (UpperCase(Caption) = "&YES")        then Caption := "E??"
          else if (UpperCase(Caption) = "&NO")         then Caption := "I??"
          else if (UpperCase(Caption) = "CANCEL")      then Caption := "C???C?"
          else if (UpperCase(Caption) = "&ABORT")      then Caption := "?U?"
          else if (UpperCase(Caption) = "&RETRY")      then Caption := "I?EC??"
          else if (UpperCase(Caption) = "&IGNORE")     then Caption := "?I"
          else if (UpperCase(Caption) = "&ALL")        then Caption := "???"
          else if (UpperCase(Caption) = "N&O TO ALL")  then Caption := "I?? E? ???"
          else if (UpperCase(Caption) = "YES TO &ALL") then Caption := "E?? E? ???"
          else Caption := "?C???C";
        end; {with}
    Result := MsgBox.ShowModal;
  finally
    MsgBox.Free;
  end; {try}
end;

مثال:

procedure TForm1.Button1Click(Sender: T);
begin
 CustomMsg("caption","this is a test for delphi center",mtWarning,mbOKCancel)
end;



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:35 عصر

 

uses ShellApi;

procedure TForm1.Button1Click(Sender: T);
begin
  
ShellExecute (HWND(nil), "open", "taskmgr", "", "", SW_SHOWNORMAL);
end;



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:33 عصر

 

هر هاردی یک سریال دارد.این سریال برای ساخت نرم افزار های تجاری و رجیستری بسیار لازم است:

 
procedure TForm1.Button1Click(Sender: T);
var
  SerialNum: DWord;
  A,B: DWord;
  C: array [0..255] of Char;
  Buffer: array [0..255] of Char;
begin

  if GetVolumeInformation(
    PChar("C:\"),
    Buffer,
    256,
    @SerialNum,
    A,
    B,
    C,
    256) then Label1.Caption:=IntToStr(SerialNum);
end;



محمد مقصودلو ::: چهارشنبه 87/7/24::: ساعت 1:28 عصر

<      1   2   3      >

لیست کل یادداشت های این وبلاگ

>> بازدیدهای وبلاگ <<
بازدید امروز: 1
بازدید دیروز: 4
کل بازدید :87624

>> درباره خودم <<
کدهای آماده دلفی
محمد مقصودلو
در این وبلاگ سعی میکنم مطالب مربوط به برنامه نویسی دلفی ، پاسکال و گرافیک رایانه ای 2 بعدی و 3 بعدی را به روز کنم منتظر سوالات شما نیز هستم

>>تست سرعت تایپ<<

>> پیوندهای روزانه <<

>>فهرست موضوعی یادداشت ها<<

>>آرشیو شده ها<<

>>لوگوی وبلاگ من<<
کدهای آماده دلفی

>>لوگوی دوستان<<



>>اشتراک در خبرنامه<<
 

>>طراح قالب<<


>>ذکر روزهای هفته<<

>>جستجوگر وبلاگها<<

>>ساعت<<

>> اخبار فناوری<<

>>جدیدترین اس ام اس های اینترنت<<

>>فال حافظ<<

>>دیکشنری آنلاین<<
-

>>جک یا لطیفه<<

>>هواشناسی<<

>>تاریخ و ساعت<<
شنبه 103/2/29 ساعت 7:14 صبح