unit UnCTOC;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,clipbrd, AppEvnts, XPMan, Buttons, INIFILES;
type
TForm1 = class(TForm)
ColorDialog1: TColorDialog;
label8: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ListBox1: TListBox;
Panel3: TPanel;
CB1: TCheckBox;
CB2: TCheckBox;
CB3: TCheckBox;
procedure CB1Click(Sender: TObject);
procedure CB2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure CB3Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
procedure WMHotKey(var Message: TMessage);
public
{ Public declarations }
procedure primenenie(r,g,b:Byte);
procedure readiniparam;
procedure writeiniparam;
end;
var
Form1: TForm1;
indexlistbox:integer;
indexlb:integer;
rectlb:trect;
drawlb:TOwnerDrawState;
MouseHook: HHOOK;
ini:tinifile;
implementation
{$R *.dfm}
procedure TForm1.readiniparam;
begin
try
ini:=TIniFile.Create(ExtractFilePath(ParamStr(0))+ExtractFileName(ParamStr(0))+'.ini');
cb1.Checked:=ini.ReadBool('Application_Main_Form',':'+name+ '|cb1|Checked-->', false);
cb2.Checked:=ini.ReadBool('Application_Main_Form',':'+name+ '|cb2|Checked-->', false);
cb3.Checked:=ini.ReadBool('Application_Main_Form',':'+name+ '|cb3|Checked-->', false);
label8.Color:=StringToColor(ini.ReadString('Application_Main_Form',':'+name+ '|EdColorCode|Color-->', 'clblack'));
label8.Text:=ini.ReadString('Application_Main_Form',':'+name+ '|EdColorCode|Text-->', '');
listbox1.ItemIndex:=ini.ReadInteger('Application_Main_Form',':'+name+ '|LBS|ID-->', 0);
finally
ini.Free;
end;
end;
procedure TForm1.writeiniparam;
begin
try
ini:=TIniFile.Create(ExtractFilePath(ParamStr(0))+ExtractFileName(ParamStr(0))+'.ini');
ini.WriteString('Application_Main_Form',':'+name+ '|EdColorCode|Color-->',ColorToString(label8.Color));
ini.WriteString('Application_Main_Form',':'+name+ '|EdColorCode|Text-->',label8.Text);
ini.WriteBool('Application_Main_Form',':'+name+ '|cb1|Checked-->',cb1.Checked);
ini.WriteBool('Application_Main_Form',':'+name+ '|cb2|Checked-->',cb2.Checked);
ini.WriteBool('Application_Main_Form',':'+name+ '|cb3|Checked-->',cb3.Checked);
ini.WriteInteger('Application_Main_Form',':'+name+ '|LBS|ID-->', indexlb);
finally
ini.Free;
end;
end;
procedure ptg;
var DC: HDC;
cur:TPoint;
begin
Windows.GetCursorPos(Cur);
DC := GetDC(GetDesktopWindow);
try
Form1.Label8.Text := IntToStr(Cur.X) + ' : ' + IntToStr(Cur.Y);
Form1.Label8.Color:= GetPixel(DC, Cur.X, Cur.Y);
Form1.ListBox1DrawItem(Form1.listbox1, indexlb, rectlb, drawlb);
finally
ReleaseDC(GetDesktopWindow, DC)
end;
end;
function TColorToKAM(Color : TColor) : string;
begin
Result :='[$'+
IntToHex(GetBValue(Color), 2) +
IntToHex(GetGValue(Color), 2) +
IntToHex(GetRValue(Color), 2)+']';
end;
procedure TForm1.primenenie(r, g, b: Byte);
VAR
VremText1,VremText2,VremText3,VremText4,VremText5:String;
begin
If CB1.Checked Then begin
VremText1:=#39;
VremText2:=#59;
VremText3:=#40;
VremText4:=#41;
VremText5:='RGB';
end else begin
VremText1:='';
VremText2:='';
VremText3:='';
VremText4:='';
VremText5:='';
end;
Case indexlistbox of
0:Clipboard.SetTextBuf(PChar(ColorToString(RGB(R, G, B))+VremText2));
1:Clipboard.SetTextBuf(PChar(IntToStr(RGB(R, G, B))+VremText2));
2:Clipboard.SetTextBuf(PChar(VremText1+TColorToKAM(RGB(R, G, B))+VremText1+VremText2));
3:Clipboard.SetTextBuf(PChar(VremText5+VremText3+IntToStr(r)+', '+IntToStr(g)+', '+IntToStr(b)+VremText4+VremText2));
end;
end;
procedure TForm1.WMHotKey(var Message: TMessage);
begin
ptg;
end;
function LowLevelMouseProc(nCode: Integer; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
var DC: HDC;
cur:TPoint;
begin
Result:= CallNextHookEx(MouseHook, nCode, WParam, LParam);
if WParam = WM_MBUTTONDOWN then ptg;
end;
procedure TForm1.CB1Click(Sender: TObject);
begin
If CB1.Checked then begin
CB1.Font.Style:=[fsbold];
CB2.Enabled:=TRUE;
END else BEGIN
CB1.Font.Style:=[];
CB2.Enabled:=FALSE;
IF CB2.Checked THEN
CB2.Checked:=fALSE;
END;
ListBox1DrawItem(listbox1, indexlb, rectlb, drawlb);
end;
procedure TForm1.CB2Click(Sender: TObject);
begin
If CB2.Checked then
CB2.Font.Style:=[fsbold]
else
CB2.Font.Style:=[];
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
application.Terminate;
writeiniparam;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
Var
Colors: Longint;
r, g, b: Byte;
begin
listbox1.Canvas.FillRect(rect);
listbox1.Canvas.TextOut(rect.Left, rect.Top, listbox1.Items.Strings[Index]);
indexlistbox:=listbox1.Itemindex;
Colors:=label8.Color;
r := Colors;
g := Colors shr 8;
b := Colors shr 16;
primenenie(R, G, B);
Label8.Text:=Clipboard.AsText;
Label8.Hint:='Сейчас в буфере: "'+Clipboard.AsText+'"';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterHotKey(form1.Handle,12345, MOD_ALT or MOD_SHIFT, $5A);
MouseHook:= SetWindowsHookEx(14, @LowLevelMouseProc, HInstance, 0);
readiniparam;
if cb3.Checked then
ListBox1DrawItem(listbox1, indexlb, rectlb, drawlb);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
If ColorDialog1.Execute then begin
label8.Color:=ColorDialog1.Color;
ListBox1DrawItem(listbox1, indexlb, rectlb, drawlb);
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
VAR
r, g, b: Byte;
begin
RANDOMIZE;
R:=RANDOM(256);
G:=RANDOM(256);
B:=RANDOM(256);
label8.Color:=RGB(R, G, B);
ListBox1DrawItem(listbox1, indexlb, rectlb, drawlb);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnregisterHotKey(Handle, 12345);
UnhookWindowsHookEx(MouseHook);
end;
procedure TForm1.CB3Click(Sender: TObject);
begin
If CB3.Checked then
CB3.Font.Style:=[fsbold]
else
CB3.Font.Style:=[];
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
indexlb:=listbox1.ItemIndex;
end;
end.