unit DeskletSDK;
////////////////////////////////////////////////////////////////////////////////
// DESKLET SDK FOR AVEDESK 1.0
//
// (c) copyright Andreas Verhoeven 2004
// website: http://www.avedesk.com
// e-mail: averhoev.2@hccnet.nl
//
//
// filename:		DeskletSDK.pas
// Description:		Delphi version of the DeskletSDK for AveDesk 1.0
// Author:		Andreas Verhoeven
// Last modified:	15 June 2004, 14:26
// Version:		1
// Comments:  		<none>
//
// 
//	(c) copyright Andreas Verhoeven 2004
//	Do not modify or reproduce this file without my permission!

////////////////////////////////////////////////////////////////////////////////

interface

uses Windows, SysUtils;

// CONSTANTS
const ANIMATION_NONE	= 0;
const ANIMATION_FADEIN	= 1;
const ANIMATION_FADEOUT	= 2;
const ANIMATION_FADEINANDOUT = 3;
const ANIMATION_FADEOUTANDIN = 4;

const DM_CONTROLPANEL = 0;
const DM_SAVE = 1;
const DM_ABOUT = 2;
const DM_HELP = 3;
const DM_EXIT = 4;
const DM_GLOBALSETTINGS = 5;
const DM_DEFAULTDESKLETPROPERTIES = 6;
const DM_ADD = 7;


(* uknown type, probably declared in some obscure unit *)
type
	DLGPROC = function(hdlg:HWND;msg:Integer;wp:WPARAM;lp:LPARAM):BOOL;stdcall;

(* types used by AveDesk *)
type
	TTabPage = record
        	title:pchar;	     	// title of the page
                titleLength:integer;	// length of the title
                resourceName:pchar;	// resource name
                hInstance:Cardinal;	// instance where resource is located
                dlgPrc:DLGPROC;		// callback dialog proc
	end;

PTabPage = ^TTabPage;

        TPropertyDialogStruct = record
        	lp:LPARAM;		// reserved
                pagesCount:Integer;	// number of pages
                pages:PTabPage;		// array of tabpages

        end;

PPropertyDialogStruct = ^TPropertyDialogStruct;
PPointer = ^Pointer;

(* API function declarations *)
function  DeskletIsVisible(hd:HWND):BOOL;
function  DeskletGetRect(hd:HWND):BOOL;
function  DeskletGetLabel(hd:HWND;lbl:pchar):Integer;
function  DeskletSetLabel(hd:HWND;lbl:pchar):Integer;
procedure DeskletSetImageFile(hd:HWND;imageFileName:pchar);
procedure DeskletSetImageOverlayFile(hd:HWND;imageFileName:pchar);
function  DeskletBrowseForImage(hd:HWND;imageFileName:pchar):BOOL;
procedure DeskletGetRelativeFolder(hd:HWND;folder:pchar);
procedure DeskletGetRootFolder(hd:HWND;folder:pchar);
procedure DeskletDefaultConfigDialog(hd:HWND;pds:PPropertyDialogStruct);

function  DeskletRemove(hd:HWND;ask:BOOL):BOOL;
procedure DeskletHide(hd:HWND);
procedure DeskletShow(hd:HWND);
procedure DeskletSetPosition(hd:HWND;p:PPoint);
procedure DeskletSetSize(hd:HWND;S:PSIZE);
procedure DeskletSetAlpha(hd:HWND;alpha:BYTE);
procedure DeskletSetRotation(hd:HWND;rotation:Integer);
procedure DeskletGetPosition(hd:HWND;p:PPOINT);
function  DeskletGetAlpha(hd:HWND):BYTE;
function  DeskletGetRotation(hd:HWND):Integer;
function  DeskletLoad(filename:pchar;ini:pchar;iniSection:pchar;p:PPointer;makeVisible:BOOL):HWND;
function  DeskletGetParentOK(): Integer;
procedure DeskletManager(action:Integer);
procedure DeskletSetStatic(hd:HWND;isStatic:BOOL);

(* function types to be used in the implementation of all functions *)
type
	TDeskletIsVisible 		= function(hd:HWND):BOOL;stdcall;
        TDeskletGetRect  		= function(hd:HWND):BOOL; stdcall;
        TDeskletGetLabel 		= function(hd:HWND;lbl:pchar):Integer;stdcall;
        TDeskletSetLabel 		= function(hd:HWND;lbl:pchar):Integer;stdcall;
        TDeskletSetImageFile	 	= procedure (hd:HWND;imageFileName:pchar);stdcall;
	TDeskletSetImageOverlayFile	= procedure (hd:HWND;imageFileName:pchar);stdcall;
	TDeskletBrowseForImage		= function (hd:HWND;imageFileName:pchar):BOOL;stdcall;
	TDeskletGetRelativeFolder 	= procedure (hd:HWND;folder:pchar);stdcall;
	TDeskletGetRootFolder		= procedure (hd:HWND;folder:pchar);stdcall;
	TDeskletDefaultConfigDialog 	= procedure (hd:HWND;pds:PPropertyDialogStruct);stdcall;
        TDeskletRemove 			= function (hd:HWND;ask:BOOL):BOOL;stdcall;
	TDeskletHide 			= procedure (hd:HWND);stdcall;
	TDeskletShow 			= procedure (hd:HWND);stdcall;
	TDeskletSetPosition 		= procedure (hd:HWND;p:PPOINT);stdcall;
	TDeskletSetSize 		= procedure (hd:HWND;s:PSIZE);stdcall;
        TDeskletSetAlpha 		= procedure (hd:HWND;alpha:BYTE);stdcall;
	TDeskletSetRotation 		= procedure (hd:HWND;rotation:Integer);stdcall;
	TDeskletGetPosition 		= procedure (hd:HWND;p:PPOINT);stdcall;
	TDeskletGetAlpha 		= function  (hd:HWND):BYTE;stdcall;
	TDeskletGetRotation 		= function  (hd:HWND):Integer;stdcall;
	TDeskletLoad 			= function  (filename:pchar;ini:pchar;iniSection:pchar;p:PPointer;makeVisible:BOOL):HWND;stdcall;
	TDeskletGetParentOK 		= function  : Integer;stdcall;
	TDeskletManager 		= procedure (action:Integer);stdcall;
	TDeskletSetStatic 		= procedure (hd:HWND;isStatic:BOOL);stdcall;


(* implementation of each function *)
(* when a function is not found, an Exception has been raised *)
implementation

function DeskletIsVisible(hd:HWND):BOOL;
var
	f:TDeskletIsVisible;
begin
	f := TDeskletIsVisible(GetProcAddress(GetModuleHandle(nil),'DeskletIsVisible'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletIsVisible not found');
	DeskletIsVisible := f(hd);
end;

function  DeskletGetRect(hd:HWND):BOOL;
var
	f:TDeskletGetRect;
begin
	f := TDeskletGetRect(GetProcAddress(GetModuleHandle(nil),'DeskletGetRect'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletGetRect not found');
	DeskletGetRect := f(hd);
end;

function  DeskletGetLabel(hd:HWND;lbl:pchar):Integer;
var
	f:TDeskletGetLabel;
begin
	f := TDeskletGetLabel(GetProcAddress(GetModuleHandle(nil),'DeskletGetLabel'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletGetLabel not found');
	DeskletGetLabel := f(hd,lbl);
end;

function  DeskletSetLabel(hd:HWND;lbl:pchar):Integer;
var
	f:TDeskletSetLabel;
begin
	f := TDeskletSetLabel(GetProcAddress(GetModuleHandle(nil),'DeskletSetLabel'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletSetLabel not found');
	DeskletSetLabel := f(hd,lbl);
end;

procedure DeskletSetImageFile(hd:HWND;imageFileName:pchar);
var
	f:TDeskletSetImageFile;
begin
	f := TDeskletSetImageFile(GetProcAddress(GetModuleHandle(nil),'DeskletSetImageFile'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletSetImageFile not found');
	f(hd,imageFileName);
end;

procedure DeskletSetImageOverlayFile(hd:HWND;imageFileName:pchar);
var
	f:TDeskletSetImageOverlayFile;
begin
	f := TDeskletSetImageOverlayFile(GetProcAddress(GetModuleHandle(nil),'DeskletSetImageOverlayFile'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletSetImageOverlayFile not found');
	f(hd,imageFileName);
end;
function  DeskletBrowseForImage(hd:HWND;imageFileName:pchar):BOOL;
var
	f:TDeskletBrowseForImage;
begin
	f := TDeskletBrowseForImage(GetProcAddress(GetModuleHandle(nil),'DeskletBrowseForImage'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletBrowseForImage not found');
	DeskletBrowseForImage := f(hd,imageFileName);
end;
procedure DeskletGetRelativeFolder(hd:HWND;folder:pchar);
var
	f:TDeskletGetRelativeFolder;
begin
	f := TDeskletGetRelativeFolder(GetProcAddress(GetModuleHandle(nil),'DeskletGetRelativeFolder'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletGetRelativeFolder not found');
	f(hd,folder);
end;

procedure DeskletGetRootFolder(hd:HWND;folder:pchar);
var
	f:TDeskletGetRootFolder;
begin
	f := TDeskletGetRootFolder(GetProcAddress(GetModuleHandle(nil),'DeskletGetRootFolder'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletGetRootFolder not found');
	f(hd,folder);
end;

procedure DeskletDefaultConfigDialog(hd:HWND;pds:PPropertyDialogStruct);
var
	f:TDeskletDefaultConfigDialog;
begin
	f := TDeskletDefaultConfigDialog(GetProcAddress(GetModuleHandle(nil),'DeskletDefaultConfigDialog'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletDefaultConfigDialog not found');
	f(hd,pds);
end;

function  DeskletRemove(hd:HWND;ask:BOOL):BOOL;
var
	f:TDeskletRemove;
begin
	f := TDeskletRemove(GetProcAddress(GetModuleHandle(nil),'DeskletRemove'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletRemove not found');
	DeskletRemove := f(hd,ask);
end;


procedure DeskletHide(hd:HWND);
var
	f:TDeskletHide;
begin
	f := TDeskletHide(GetProcAddress(GetModuleHandle(nil),'DeskletHide'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletHide not found');
	f(hd);
end;
procedure DeskletShow(hd:HWND);
var
	f:TDeskletShow;
begin
	f := TDeskletShow(GetProcAddress(GetModuleHandle(nil),'DeskletShow'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletShow not found');
	f(hd);
end;
procedure DeskletSetPosition(hd:HWND;p:PPOINT);
var
	f:TDeskletSetPosition;
begin
	f := TDeskletSetPosition(GetProcAddress(GetModuleHandle(nil),'DeskletSetPosition'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletSetPosition not found');
	f(hd,p);
end;
procedure DeskletSetSize(hd:HWND;S:PSIZE);
var
	f:TDeskletSetSize;
begin
	f := TDeskletSetSize(GetProcAddress(GetModuleHandle(nil),'DeskletSetSize'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletSetSize not found');
	f(hd,s);
end;
procedure DeskletSetAlpha(hd:HWND;alpha:BYTE);
var
	f:TDeskletSetAlpha;
begin
	f := TDeskletSetAlpha(GetProcAddress(GetModuleHandle(nil),'DeskletSetAlpha'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletSetAlpha not found');
	f(hd,alpha);
end;
procedure DeskletSetRotation(hd:HWND;rotation:Integer);
var
	f:TDeskletSetRotation;
begin
	f := TDeskletSetRotation(GetProcAddress(GetModuleHandle(nil),'DeskletSetRotation'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletSetRotation not found');
	f(hd,rotation);
end;
procedure DeskletGetPosition(hd:HWND;p:PPOINT);
var
	f:TDeskletGetPosition;
begin
	f := TDeskletGetPosition(GetProcAddress(GetModuleHandle(nil),'DeskletGetPosition'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletGetPosition not found');
	f(hd,p);
end;
function  DeskletGetAlpha(hd:HWND):BYTE;
var
	f:TDeskletGetAlpha;
begin
	f := TDeskletGetAlpha(GetProcAddress(GetModuleHandle(nil),'DeskletGetAlpha'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletGetAlpha not found');
	DeskletGetAlpha := f(hd);
end;
function  DeskletGetRotation(hd:HWND):Integer;
var
	f:TDeskletGetRotation;
begin
	f := TDeskletGetRotation(GetProcAddress(GetModuleHandle(nil),'DeskletGetRotation'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletGetRotation not found');
	DeskletGetRotation := f(hd);
end;
function  DeskletLoad(filename:pchar;ini:pchar;iniSection:pchar;p:PPointer;makeVisible:BOOL):HWND;
var
	f:TDeskletLoad;
begin
	f := TDeskletLoad(GetProcAddress(GetModuleHandle(nil),'DeskletLoad'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletLoad not found');
	DeskletLoad := f(filename,ini,iniSection,p,makeVisible);
end;
function  DeskletGetParentOK(): Integer;
var
	f:TDeskletGetParentOK;
begin
	f := TDeskletGetParentOK(GetProcAddress(GetModuleHandle(nil),'DeskletGetParentOK'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletGetParentOK not found');
	DeskletGetParentOK := f();
end;
procedure DeskletManager(action:Integer);
var
	f:TDeskletManager;
begin
	f := TDeskletManager(GetProcAddress(GetModuleHandle(nil),'DeskletManager'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletManager not found');
	f(action);
end;
procedure DeskletSetStatic(hd:HWND;isStatic:BOOL);
var
	f:TDeskletSetStatic;
begin
	f := TDeskletSetStatic(GetProcAddress(GetModuleHandle(nil),'DeskletSetStatic'));
        if(Addr(f) = nil)then raise Exception.Create('function DeskletSetStatic not found');
	f(hd,isStatic);
end;

(*eof*)
end.
