(***********************************************)
(*                                             *)
(* Win32 Control Panel Application (CPl) Demo  *)
(* Copyright (c) 1998 by TMT Development Corp. *)
(* Author: Vadim Bodrov, TMT Development Corp. *)
(*                                             *)
(* Targets:                                    *)
(*   Win32 DLL(CPl)                            *)
(*                                             *)
(***********************************************)

//////////////////////////////////////////////////////
// Compiled DLL must be renamed to TESTCPL.CPL and  //
// moved to the ..\WINDOWS\SYSTEM\ subdirectory.    //
//////////////////////////////////////////////////////

{$ifndef __WIN32__}
{$define INVALID_TARGET}
{$endif}
{$ifndef __DLL__}
{$define INVALID_TARGET}
{$endif}
{$ifdef INVALID_TARGET}
  This program must be compiled as Win32 DLL (CPl) only
{$endif}

library TestCPl;

uses CPL, Windows, Messages;

{$r testcpl.res}

function DlgProc conv arg_stdcall (Dialog: HWND; Mess: UINT; WParam: WParam; LParam: LParam): LongInt;
begin
  if (Mess = WM_COMMAND) and (LoWord(WParam) = 103) then
  begin
    EndDialog(Dialog, 0);
    Result := 1;
  end else
    Result := 0;
end;

function CPlApplet conv arg_stdcall (hwndCPL: HWnd; uMsg: DWord; lParam1, lParam2: Longint): Longint;
var CPlInfo: TNewCPLInfo;
begin
  case (uMsg) of
    CPL_INIT:      // first message, sent once
              begin
                hinstance := GetModuleHandle('testcpl.cpl');
                Result := 1;
                exit;
              end;

    CPL_GETCOUNT:  // second message, sent once
              begin
                Result := 1;
                exit;
              end;

    CPL_NEWINQUIRE:   // third message, sent once per application
              begin
                FillChar(CPlInfo, SizeOf(CPlInfo), 0);
                CPlInfo.dwSize := SizeOf(CPlInfo);
                CPlInfo.hIcon := LoadIcon(HInstance, PChar(101));
                CPlInfo.szName := 'TestCPl'+#0;
                CPlInfo.szInfo := 'Windows 32-bit Control Panel Application Demo'+#0;
                Move(CPlInfo, Pointer(lParam2)^, SizeOf(CPlInfo));
              end;

    CPL_DBLCLK:    // application icon double-clicked
              begin
                DialogBoxParam(hInstance, MAKEINTRESOURCE(102), 0, @DlgProc, 0);
              end;

  end;
  Result := 0;
end;

exports
  CPlApplet name 'CPlApplet';

begin
  (* Do nothing *)
end.
