ایا توابع API را در دلفی میتوان استفاده کرد یا خیر
بله.
اگر جواب بله است کدام توابع را
تمام شان را !
ابزار بهتر از توابع API آیا وجود دارد که استفاده انها در دلفی بهتر باشد
برنامه های دلفی کلا با فراخوانی توابع API کار میکنند. خود VCL که چهارچوب برنامه نویسی در دلفی است در حقیقت لایه ای بر روی توابع API است.
در صورت نیاز به فرخوانی مستقیم توابع API کافی است یونیت Windows را در فرم تان Use کنید.
مثال:
<span dir=ltr>- ActivateKeyboardLayout
Unit
Windows.Pas
Syntax
ActivateKeyboardLayout(
klh: HKL; {keyboard layout handle}
Flags: UINT {activation flag}
): HKL; {returns previous handle}
Description
The ActivateKeyboardLayout function activates the keyboard layout identified by the specified keyboard layout handle. In Windows95, it takes effect for the current thread. In Windows NT, it affects all threads.
Parameters
klh: The keyboard layout handle. This handle can be obtained by calling LoadKeyboardLayout or GetKeyboardLayoutList. This parameter can also be set to HKL_NEXT or HKL_PREV which refer to the next or previous entries in the keyboard layout list.
Flags: Specifies Keyboard layout options.
Return Value
If the function succeeds, the return value is the keyboard layout handle of the previous keyboard layout. If the function fails, it returns zero, indicating no matching keyboard layout was found. To get extended error information, call the GetLastError function.
Example:
</span>var
Form1: TForm1;
List : array [0..MAX_HKL] of HKL; // list of keyboard handles
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
MyLangID: WORD; // holds a language identifier
begin
{load the keyboard layout specified by language IDs}
MyLangID:=MakeLangID(WORD(StrToInt( ;Edit1.Text)), WORD(StrToInt(Edit2.Text)));
if LoadKeyBoardLayout(PChar('0000' + IntToHex(MyLangID,4)),KLF_ACTIVATE) ; = 0
then ShowMessage('Error loading keyboard layout');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
{activate the highlighted keyboard layout}
if (ActivateKeyboardLayout(StrToInt(ListB ox1.Items[Listbox1.Itemindex]),
KLF_REORDER) = 0) then
ShowMessage('Error activating the keyboard layout');
{clear the keyboard layout list and repopulate it}
ListBox1.Clear;
FormCreate(Sender);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
pwszKLID: PChar; // holds the name of a keyboard layout
MyListIndex: Integer; // specifies a list index
begin
{get the keyboard layout lists}
GetKeyboardLayoutList(MAX_HKL, List);
{allocate a buffer for the keyboard layout name string}
GetMem(pwszKLID, KL_NAMELENGTH);
{retrieve the name string for active keyboard layout}
GetKeyboardLayoutName(pwszKLID);
ShowMessage('The active keyboard layout is '+pwszKLID);
StatusBar1.SimpleText:= 'Active keyboard layout ' + pwszKLID;
{retrieve the code page identifier}
StaticText1.Caption:=IntTostr(GetACP);
{free the string memory}
FreeMem(pwszKLID);
{list all the keyboard layout in the list box}
MyListIndex := 0;
while (List[MyListIndex] <> 0) do
begin
ListBox1.Items.Add(IntToStr(List[MyLis tIndex]));
Inc(MyListIndex);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
{unload keyboard layout}
if not UnloadKeyboardLayout(StrToInt(ListBox1.Ite ms[Listbox1.ItemIndex])) then
ShowMessage('Error Unloading Keyboard Layout');
end;
function MakeLangID(PrimLang, SubLang:WORD): WORD;
begin
{make a Language ID by combining the Primary language ID and Sub language ID}
Result := (SubLang SHL 10) + PrimLang;
end;