Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 5

Project USECOL

Project Structure


USECOL.DPR

program Usecol;

uses
  Forms,
  UseColF in 'UseColF.pas' {Form1};

{$R *.RES}

begin
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

USECOLF.PAS

unit UseColF;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    BtnChange: TButton;
    BtnSelect: TButton;
    BtnApp: TButton;
    BtnSync: TButton;
    procedure BtnChangeClick(Sender: TObject);
    procedure BtnSelectClick(Sender: TObject);
    procedure BtnAppClick(Sender: TObject);
    procedure BtnSyncClick(Sender: TObject);
  private
    { Private declarations }
  public
    procedure UserMessage (var Msg: TMessage);
      message wm_user;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function GetColor (Col: LongInt): LongInt;
  stdcall; external 'FormDLL.DLL';
procedure ShowColor (Col: LongInt;
  FormHandle: THandle; MsgBack: Integer);
  stdcall; external 'FormDLL.DLL';
procedure SyncApp (AppHandle: THandle);
  stdcall; external 'FormDLL.DLL';

procedure TForm1.BtnChangeClick(Sender: TObject);
var
  Col: LongInt;
begin
  Col := ColorToRGB (Color);
  Color := GetColor (Col)
end;

procedure TForm1.BtnSelectClick(Sender: TObject);
var
  Col: LongInt;
begin
  Col := ColorToRGB (Color);
  ShowColor (Col, Handle, wm_user);
end;

procedure TForm1.UserMessage(var Msg: TMessage);
begin
  Color := Msg.WParam;
end;

procedure TForm1.BtnAppClick(Sender: TObject);
begin
  ShowMessage ('Application Handle: ' +
    IntToStr (Application.Handle));
end;

procedure TForm1.BtnSyncClick(Sender: TObject);
begin
  SyncApp (Application.Handle);
  BtnSync.Enabled := False;
end;

end.

USECOLF.DFM

object Form1: TForm1
  Left = 222
  Top = 159
  Width = 193
  Height = 267
  Caption = 'Test Form DLL'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
  object BtnChange: TButton
    Left = 40
    Top = 34
    Width = 105
    Height = 33
    Caption = 'Change Color'
    TabOrder = 0
    OnClick = BtnChangeClick
  end
  object BtnSelect: TButton
    Left = 40
    Top = 88
    Width = 105
    Height = 33
    Caption = 'Select Color'
    TabOrder = 1
    OnClick = BtnSelectClick
  end
  object BtnApp: TButton
    Left = 40
    Top = 136
    Width = 105
    Height = 33
    Caption = 'Application'
    TabOrder = 2
    OnClick = BtnAppClick
  end
  object BtnSync: TButton
    Left = 40
    Top = 184
    Width = 105
    Height = 33
    Caption = 'Sync App'
    TabOrder = 3
    OnClick = BtnSyncClick
  end
end