Wtyczka jest biblioteką DLL zawierającą formę, która podczepiana jest pod program.
Aby wtyczka działała musi zostać skompilowana z informacjami o wersji.
Delphi
library Test;
{Przykładowa wtyczka do X-Tweakera
Wtyczka jest zwykłym plikiem *.dll
Wtyczka musi miec rozszerzenie *.xtp}
uses
SysUtils,forms,
Classes,
dllfrm in 'dllfrm.pas' {DllForm};
{$E xtp} // => kompilacja od razu z rozszerzeniem *.xtp
{$R *.res}
//Wyświetlenie nazwy wtyczki na liscie i w menu w X-Tweakerze
Function XTPGetName:shortstring;stdcall;
begin
result:='Plugin testowy // Delphi';
end;
//Wyświetlenie autora wtyczki na liscie X-Tweakerze
Function XTPGetAutor:shortstring;stdcall;
begin
result:='Autor wtyczki';
end;
//Wyswietlenie formy
Procedure ShowDLLWND(x,y:integer;z:pchar);stdcall;
begin
FX:=X; //Ustawienie pozycji okna
FY:=Y; //Ustawienie pozycji okna
WNAme:=Z;
if not Assigned(DLLForm)then DLLForm:=TDLLForm.Create(Application);
DLLForm.Show;
end;
//Obsługa zmiany wielkości formy wraz ze zmianą wielkości X-Tweakera
//Jezeli forma ma nie być podczepiona pod program zostaw ta procedurę a
// jedynie usuń instrukcje pomiędy begin i end;
Procedure ResizeDLLWND(x,y:integer);stdcall;
begin
DLLForm.width:=x;
DLLForm.height:=y;
end;
{Zapis ustawień wtyczki
Jezeli wtyczka wyswietla tylko informacje i nie ma żadnych opcji zapisu
usuń instrukcje pomiędy begin i end;}
Procedure DLLSave;stdcall;
begin
DllForm.Apply;
end;
Exports
XTPGetName name 'XTPGetName',
XTPGetAutor name 'XTPGetAutor',
ResizeDLLWND name 'ResizeDLLWND',
ShowDLLWND name 'ShowDLLWND',
DLLSave name 'DLLSave';
end.
unit dllfrm;
{Jeżeli wtyczka ma byc podczepiona pod program ustaw
BorderStyle na bsNone}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDllForm = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Apply;
private
{ Private declarations }
public
{ Public declarations }
end;
var
DllForm: TDllForm;
Wind:pchar;
FX:integer; //Ustawienie pozycji okna
FY:integer; //Ustawienie pozycji okna
Wname:pchar;
implementation
{$R *.dfm}
//Wyświetlenie formy i automatyczne podczepienie pod program
//Niepotrzebne jeżeli forma ma być wyswietlona jako zwykłe okienk zamiast podczepienia pod program
procedure TDllForm.FormCreate(Sender: TObject);
var
H : THandle;
begin
H := FindWindow(nil, Wname);
SetWindowLong(self.handle,GWL_STYLE,WS_CHILD);
SetWindowLong(self.handle,GWL_EXSTYLE,GetWindowLong((H),GWL_EXSTYLE));
Windows.SetParent(self.handle, H);
self.Top := FX;
self.Left :=FY;
end;
//Zapis ustawien wtyczki
procedure TDllForm.Apply;
begin
label1.caption:='Test zakonczony. Plugin działa.';
end;
end.
C++ Builder / Turbo C++
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
#include <Unit2.cpp>
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
extern "C"
{
void __declspec(dllexport) _stdcall ShowDLLWND(int x,int y,PChar Z )
{
FX=x; //Ustawienie pozycji okna
FY=y; //Ustawienie pozycji okna
WName=Z;
Application->CreateForm(__classid(TForm1), &Form1);
Form1->Show();
}
void __declspec(dllexport) _stdcall ResizeDLLWND(int x,int y)
{
Form1->Width=x;
Form1->Height=y;
}
ShortString __declspec(dllexport) _stdcall XTPGetName()
{
return "C++ Plugin";
}
ShortString __declspec(dllexport) _stdcall XTPGetAutor()
{
return "Autor wtyczki";
}
void __declspec(dllexport) _stdcall DLLSave()
{
Form1->Zastosuj();
}
}
Unit2.cpp - Forma
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int FX;
int FY;
PChar WName;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
HWND H = FindWindow(NULL, WName);
SetWindowLong(Form1->Handle,GWL_STYLE,WS_CHILD);
SetWindowLong(Form1->Handle,GWL_EXSTYLE,GetWindowLong((H),GWL_EXSTYLE));
::SetParent(Form1->Handle, H);
Form1->Top = FX;
Form1->Left =FY;
}
void __fastcall TForm1::Zastosuj()
{
Label1->Caption= "Test zakonczony. Plugin działa.";
}
//---------------------------------------------------------------------------