https://github.com/nicolacimmino/PLC-14500
https://hackaday.io/project/170548-wdr-1-bit-computer
https://github.com/nicolacimmino/PLC-14500
https://hackaday.io/project/170548-wdr-1-bit-computer
https://www.streamlinehq.com/icons/streamline-mini-line
curiously recurring template pattern
https://stackoverflow.com/questions/3991788/can-a-delphi-generic-class-descend-from-its-class-argument
https://blog.grijjy.com/2022/01/25/crgp/
The Curiously Recurring Generic Pattern
https://www.fluentcpp.com/2017/05/12/curiously-recurring-template-pattern/
The Curiously Recurring Template Pattern (CRTP) - Fluent C++
https://9to5answer.com/practical-uses-for-the-quot-curiously-recurring-template-pattern-quot
https://dev.to/sandordargo/the-curiously-recurring-template-pattern-crtp-46j7
The Curiously Recurring Template Pattern (CRTP)
https://dev.to/sandordargo/the-curiously-recurring-template-pattern-crtp-46j7
https://en.cppreference.com/w/cpp/language/crtp
https://www.geeksforgeeks.org/curiously-recurring-template-pattern-crtp-2/
https://rosettacode.org/wiki/Singleton
https://habr.com/en/post/307902/
Преобразование обычного класса в странно повторяющийся шаблон / Habr
https://wdv4758h.github.io/notes/cpp/crtp.html
CRTP (Curiously Recurring Template Pattern) — wdv4758h-notes latest 說明文件
https://stackoverflow.com/questions/43322010/generics-in-delphi-and-returning-a-reference-to-tlistclass
https://dm7blog.wordpress.com/2019/05/15/delphide-linked-list-ve-tlist-kullanimi/
https://infosys.beckhoff.com/english.php?content=../content/1033/tcsample_bdelphi/html/TcAdsDLL_COM_Delphi_Setup.htm&id=
Linking to Delphi XE2 (COM interface)
The TcAdsDll.dll type library has to be imported (TcAdsDll_TLB.pas unit). Depending on the Delphi version, manual adjustments may be required in order to ensure error-free translation.
Requirements
Delphi XE2;
TwinCAT 2.9 or higher;
TcAdsDll.dll - dynamic function library located in the Windows NT/2000 /XP/... 'System32' directory.
Import Type Library
1. Select Component -> Import component menu command. In dialog window select the option: Import type library and confirm with the Next button.
https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getlogicalprocessorinformation
http://msdn.microsoft.com/en-us/library/ms683194(v=vs.85).aspx
GetLogicalProcessorInformation function
GetLogicalProcessorInformation
http://msdn.microsoft.com/en-us/library/ms686694(v=vs.85).aspx
SYSTEM_LOGICAL_PROCESSOR_INFORMATION structure
http://msdn.microsoft.com/en-us/library/ms684197(v=vs.85).aspx
LOGICAL_PROCESSOR_RELATIONSHIP enumeration
http://msdn.microsoft.com/en-us/library/ms681979(v=vs.85).aspx
CACHE_DESCRIPTOR structure
http://msdn.microsoft.com/en-us/library/ms684844(v=vs.85).aspx
PROCESSOR_CACHE_TYPE enumeration
GetProcessorCoreCount(DWORD &PhysicalProcessorCoreCount,DWORD &LogicalProcessorCoreCount )
{
typedef BOOL(WINAPI *LPFN_GLPI)(
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION,
PDWORD);
LPFN_GLPI glpi = (LPFN_GLPI)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetLogicalProcessorInformation");
if (NULL == glpi)
return 0;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
DWORD returnLength = 0;
PhysicalProcessorCoreCount = 0;
LogicalProcessorCoreCount = 0;
while (true)
{
DWORD rc = glpi(buffer, &returnLength);
if (FALSE == rc)
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
if (buffer)
free(buffer);
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(
returnLength);
if (NULL == buffer)
return 0;
}
else
{
return 0;
}
}
else
{
break;
}
}
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = buffer;
DWORD byteOffset = 0;
while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength)
{
switch (ptr->Relationship)
{
case RelationProcessorCore:
{
++PhysicalProcessorCoreCount;
// count the logical processor, which is equal the count of digital 1's of ptr->ProcessorMask
ULONG_PTR ProcessorMask = ptr->ProcessorMask;
while (ProcessorMask != 0)
{
ProcessorMask &= ProcessorMask - 1;
LogicalProcessorCoreCount++;
}
break;
}
default:
break;
}
byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
++ptr;
}
free(buffer);
return -1;
}
https://en.wikipedia.org/wiki/Hyper-threading
使用GetLogicalProcessorInformation获取逻辑处理器的详细信息(NUMA节点数、物理CPU数、CPU核心数、逻辑CPU数、各级Cache)
https://www.cnblogs.com/findumars/p/4805207.html
https://stackoverflow.com/questions/66130195/delphi-getlogicalprocessorinformation-x64
https://en.wikipedia.org/wiki/Category:Typesetting_software
https://zh.wikipedia.org/zh-tw/TeX
https://github.com/search?l=Pascal&q=ShellExecute+Madness&type=Code
http://vbnet.mvps.org/index.html?code/shell/shellexecute.htm
TArray
TDictionary
TEnumerable
TEnumerator
TList
TObjectDictionary
TObjectList
TObjectQueue
TObjectStack
TQueue
TStack
TThreadedQueue
TThreadList
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Generics.Collections
https://delphisources.ru/pages/faq/master-delphi-7/content/LiB0053.html
delphi TTreeNode Structures data TDictionary
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.LibModuleList
linked list of records
https://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.Controls.TDockZone
https://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.ActnMan.TActionManager.LinkedActionLists
delphi TTreeNode Structures data TDictionary
https://docwiki.embarcadero.com/RADStudio/Sydney/en/About_Data_Types_(Delphi)
https://devopedia.org/data-structures
https://en.wikipedia.org/wiki/Linked_list
https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.Classes.TList.Sort
https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.Classes.TStringList.CustomSort
https://www.geeksforgeeks.org/sorting-algorithms/
https://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.Classes.TCollection
https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Working_with_Lists
https://stackoverflow.com/questions/46934591/how-to-make-delphi-tbutton-control-stay-pressed
Vcl.Themes,
Vcl.Styles ;
StyleAPI
StyleElements
FInternalImageList
TSeStyle
procedure TSysStyleHook.UpdateColors;
begin
if (OverrideEraseBkgnd) or (OverridePaint) then
Color := StyleServices.GetStyleColor(scWindow)
else
Color := clBtnFace;
if OverrideFont then
FontColor := StyleServices.GetSystemColor(clWindowText)
else
FontColor := clBlack;
end;
procedure TSysStyleHook.SetStyleElements(Value: TStyleElements);
begin
if Value <> FStyleElements then
begin
FStyleElements := Value;
OverridePaint := (seClient in FStyleElements);
// OverrideEraseBkgnd := OverridePaint;
OverridePaintNC := (seBorder in FStyleElements);
OverrideFont := (seFont in FStyleElements);
end;
end;
TCustomButton = class(TButtonControl)
FImages: TCustomImageList;
FInternalImageList: TImageList;
procedure TCustomButton.SetImages(const Value: TCustomImageList);
procedure TCustomButton.UpdateImages;
begin
if CheckWin32Version(5, 1) and (FImageIndex <> -1) then
begin
FInternalImageList.Clear;
// PBS_NORMAL
FInternalImageList.AddImage(FImages, FImageIndex);
// PBS_HOT
if FHotImageIndex <> -1 then
FInternalImageList.AddImage(FImages, FHotImageIndex)
else
FInternalImageList.AddImage(FImages, FImageIndex);
// PBS_PRESSED
if FPressedImageIndex <> -1 then
FInternalImageList.AddImage(FImages, FPressedImageIndex)
else
TButtonImageList BUTTON_IMAGELIST
https://docs.microsoft.com/zh-tw/windows/win32/api/commctrl/nf-commctrl-imagelist_replace
ImageList_Replace function (commctrl.h)
hbmImage
Type: HBITMAP
A handle to the bitmap that contains the image.
hbmMask
Type: HBITMAP
https://theroadtodelphi.com/category/vcl-styles/
https://delphiaball.co.uk/2014/10/22/adding-vcl-styles-runtime/
https://github.com/RRUZ/vcl-styles-utils
https://stackoverflow.com/questions/14031125/styling-only-one-vcl-component-in-delphi
https://theroadtodelphi.com/2012/02/06/changing-the-color-of-edit-controls-with-vcl-styles-enabled/
https://blogs.embarcadero.com/vcl-per-control-styles-coming-in-rad-studio-10-4/
MyBaseを試してみる。(フィールド作成編): Delphi-fan
http://hiderin.air-nifty.com/delphi/2011/09/mybase-dcff.html
http://delphi.ktop.com.tw/board.php?cid=30&fid=66&tid=51084
https://blog.karatos.in/a?ID=00200-12c89300-5e82-48ad-ada0-aab6e1319adf
https://stackoverflow.com/questions/67149100/how-to-detect-user-either-in-dbgrid-or-clientdataset-has-deleted-data-in-a-cell
https://www.delphipower.xyz/guide_6/working_with_data_using_a_client_dataset.html
delphi DataSource TDataSetProvider Advanced Data TableGram ADTG
https://docwiki.embarcadero.com/Libraries/Sydney/en/Data.Win.ADODB.TPersistFormat
https://torry.net/quicksearchd.php?String=dataset&page=6
https://github.com/osmanatam/delphi-foundations
https://github.com/zhugecaomao/DelphiSourceCodeCollection
FMX Utilities
Tweaks to TClipboard code to compile with newer FMX versions
Misc/Generics.Defaults if done with metaclasses
XE2 book
01. Language basics
02. Enums, numbers, dates and times
04. Classes and records
05. String handling
06. Arrays, collections and enumerators
07. Basic IO
08. Streams
Cleaned up source for fuller visual control demo
09. ZIP, XML, Registry and INI files
10. Packages
11. Dynamic typing and expressions
12. RTTI
13. Native APIs
Make comment more precise
14. Dynamic libraries
15. Multithreading
Another little FileSearchThread.pas thing
standard Microsoft SDK resource compiler
https://github.com/graphics32/GR32PNG
RC.EXE, the Microsoft SDK Resource Compiler
https://forum.lazarus.freepascal.org/index.php?topic=12312.0
https://www.wireshark.org/docs/wsdg_html_chunked/ChToolsMSChain.html
https://support.microsoft.com/en-us/topic/an-updated-resource-compiler-for-the-windows-sdk-for-windows-server-2008-and-for-the-net-framework-3-5-is-now-available-a716ac6a-19a7-5b45-b5df-55980cd4cdb4
https://archicadapi.graphisoft.com/documentation/graphisoft-resource-compiler-4
https://docs.microsoft.com/zh-tw/windows/win32/menurc/resource-compiler
https://en.wikibooks.org/wiki/Windows_Programming/Resource_Scripts
Var
jpg: TJPEGImage;
resStream: TResourceStream;
begin
jpg := TJPEGImage.Create;
resStream := TResourceStream.Create(HInstance, 'testJpg', 'jpgtype');
jpg.LoadFromStream(resStream);
Image1.Picture.Assign(jpg);
jpg.Free;
resStream.Free;
end;
//RC: testBmp bitmap res\test.bmp
Image1.Picture.Bitmap.LoadFromResourceName(HInstance, 'res\test.bmp');
//RC: testBmp bmptype res\test.bmp
var
resStream: TResourceStream;
begin
resStream := TResourceStream.Create(HInstance, 'testBmp', 'bmptype');
Image1.Picture.Bitmap.LoadFromStream(resStream);
resStream.Free;
end;
http://melander.dk/reseditor/
https://wiki.freepascal.org/Lazarus_Resources
https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/menurc/resource-compiler.md
Microsoft platform SDK Resource Compiler
https://docwiki.embarcadero.com/RADStudio/Sydney/en/RC.EXE,_the_Microsoft_SDK_Resource_Compiler
https://delphi.cjcsoft.net/viewthread.php?tid=43646
Title: Extracting Resource Data from an Exe
Question: Article 832 mentions how one can put Files into an Exe. This shows you how you can get it out
Answer:
I've written a simple function that does this for you, just cut and paste (some detail is below)
procedure ExtractToFile(Instance:THandle; ResID:Integer; ResType, FileName:String);
var
ResStream: TResourceStream;
FileStream: TFileStream;
begin
try
ResStream := TResourceStream.CreateFromID(Instance, ResID, pChar(ResType));
try
//if FileExists(FileName) then
//DeleteFile(pChar(FileName));
FileStream := TFileStream.Create(FileName, fmCreate);
try
FileStream.CopyFrom(ResStream, 0);
finally
FileStream.Free;
end;
finally
ResStream.Free;
end;
except
on E:Exception do
begin
DeleteFile(FileName);
raise;
end;
end;
end;
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Classes.TResourceStream
https://github.com/osmanatam/delphi-foundations/tree/ea2c878f01107146674bd92ea518908d8f3e185d/XE2%20book/08.%20Streams/TResourceStream
[ GDI+ サンプル ] [ G080_RotateTransform による画像とオブジェクトの回転 ] - Mr.XRAY
https://stackoverflow.com/questions/65163260/image-transformation-python
https://medium.com/analytics-vidhya/opencv-perspective-transformation-9edffefb2143
https://en.wikipedia.org/wiki/Archimedean_spiral#General_Archimedean_spiral
https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#gab75ef31ce5cdfb5c44b6da5f3b908ea4
The Rick Sammon Swirl Effect
https://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl/
https://stackoverflow.com/questions/5964701/how-to-draw-a-translucent-image-on-a-form
transparent background http://delphiexamples.com/forms/transpform.html
https://sourceforge.net/projects/widget32/
https://parnassus.co/transparent-graphics-with-pure-gdi-part-2-and-introducing-the-ttransparentcanvas-class/
Form com área transparente no Lazarus/Windows
http://fanzinepas.blogspot.com/2012/06/form-com-area-transparente-no.html
THandle CreateRectRgn CreateRectRgn SetWindowRgn Winuser.h
https://www.codeguru.com/cplusplus/transparent-listbox/
https://stackoverflow.com/questions/48511634/partially-transparent-window-opengl-win32
winapi Transparent form layer GetMonitorInfo
https://www.experts-exchange.com/articles/1783/Win32-Semi-Transparent-Window.html
Layered Windows
https://docs.microsoft.com/en-us/previous-versions/ms997507(v=msdn.10)?redirectedfrom=MSDN
https://www.codeproject.com/Articles/1822/Per-Pixel-Alpha-Blend-in-C
http://suyamasoft.blue.coocan.jp/ExcelVBA/Sample/SetLayeredWindowAttributes/index.html
http://suyamasoft.blue.coocan.jp/ExcelVBA/Sample/SetLayeredWindowAttributes/index.html
https://docs.microsoft.com/en-us/windows/win32/winauto/magapi/magapi-intro
Žarko Gajić gZoom – Delphi Implementation of the Missing Mode in Windows Magnifier
https://zarko-gajic.iz.hr/gzoom-delphi-implementation-of-the-missing-mode-in-windows-magnifier/
https://www.codeproject.com/Articles/5051/Various-methods-for-capturing-the-screen
https://www.codeproject.com/Articles/607288/Screenshot-using-the-Magnification-library
https://en.wikipedia.org/wiki/Comparison_of_parser_generators
https://en.wikipedia.org/wiki/Source-to-source_compiler
https://en.wikipedia.org/wiki/Language_binding
https://wiki.freepascal.org/C_to_Pascal
https://wiki.lazarus.freepascal.org/User:Roozbeh
https://discourse.panda3d.org/t/help-with-swig/570
Developer Tools Code Code Convertors
https://torry.net/pages.php?id=1518
llvm parsing pascal
https://intel.github.io/llvm-docs/clang_doxygen/ParseExprCXX_8cpp_source.html
https://forum.lazarus.freepascal.org/index.php?topic=43007.15
https://github.com/mladedav/mila-compiler
https://github.com/FrozenGene/LLVMPascalCompiler
https://aclanthology.org/people/p/pascal-denis/
http://www.eteks.com/jeks/en/doc/com/eteks/parser/PascalSyntax.html
https://www.freepascal.org/docs-html/user/userse62.html
https://en.wikipedia.org/wiki/Comparison_of_Pascal_and_C
https://www.codeproject.com/Articles/371453/Visual-AST-for-ANTLR-Generated-Parser-Output
https://github.com/RomanYankovsky/DelphiAST
https://www.texttransformer.com/Delphi2Cpp_en.html
http://ivan.vecerina.com/code/delphi2cpp/
https://www.codeproject.com/Articles/10115/Crafting-an-interpreter-Part-1-Parsing-and-Grammar
https://www.codeproject.com/Articles/10142/Crafting-an-interpreter-Part-2-The-Calc0-Toy-Langu
https://www.codeproject.com/Articles/10421/Crafting-an-interpreter-Part-3-Parse-Trees-and-Syn
Rectangles, Regions, and Clipping rectangular region CreateRoundRectRgn
https://miffyzzang.tistory.com/378
CreateWindow("button","",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_BITMAP | BS_OWNERDRAW, 100,100,70,30,hWnd,(HMENU)IDC_BUTTON, hInst,NULL);
Creating Owner-Drawn Controls - Windows Programming
BS_OWNERDRAW SetButtonStyle SetWindowRgn
https://stackoverflow.com/questions/18745447/how-can-i-change-the-background-color-of-a-button-winapi-c
https://www.pablosoftwaresolutions.com/html/cimagebutton.html
#pragma comment( \
linker, \
"/manifestdependency:\"type='win32' \
name='Microsoft.Windows.Common-Controls' \
version='6.0.0.0' \
processorArchitecture='*' \
publicKeyToken='6595b64144ccf1df' \
language='*'\"")
https://www.pablosoftwaresolutions.com/html/ccolorbutton.html
https://stackoverflow.com/questions/17678261/how-to-change-color-of-a-button-while-keeping-buttons-functions-in-win32
https://stackoverflow.com/questions/8695185/why-my-edit-control-looks-odd-in-my-win32-c-application-using-no-mfc
https://stackoverflow.com/questions/18745447/how-can-i-change-the-background-color-of-a-button-winapi-c
https://github.com/pauloalvis/Delphi-PraButtonStyle
https://rmklever.com/?tag=rkglassbutton
Klever on Delphi
My take at Delphi, tips and tricks and how tos
Skip to content
HomeAbout Contact Downloads
Tag Archives: rkGlassButton
Glassbutton updated to v2.4
3 Comments
This is a long forgotten update to my rkGlassButton component. Some bugs have been corrected and it now work more as expected.
The first ting first. The autosize property is working like it should.
Secondly the down property also work when duostyle is active.
Last but not forgotten OnClick now work as expected.
Please report any bugs you find to me.
Hope this helps a little
Download rkGlassButton v2.4
This entry was posted in Component, GUI and tagged Component, GUI, rkGlassButton on August 19, 2014.
Klever on Delphi
My take at Delphi, tips and tricks and how tos
Skip to content
HomeAbout Contact Downloads
A smarter button
8 Comments
There is a lot of buttons out there I know but I have yet to find a button like this where you can have more than one button in “one button” (see screen shot). Especially at no cost.
RkSmartButton on display.
RkSmartButton on display.
I belive this is all you need to get started using rkSmartButton. I have tried to make it easy to use but there are a few things worth noticing… to show a popupmenu on any of the buttons you must set a flag in ButtonsPopup property which will look, something like this: 0010 “0” means do not show “1” means show. In this case only third button will get the popup. I also use this technic for enabling buttons and keeping hold of which one is down. No popup will be shown if CheckButtons is set. Popupmenu is shown after the button is pressed and hold down for the time given in PopupDelay property (like in Chrome). To get images on button add an imagelist and set the indexes in the ImageIndexes property. Use format like this: 0,1,2,7,4. To know which button was pressed use SelectedIndex property. Button number one gets the index of 0.
Thats it, hope you like it.
Next up is an update of SmartPathBar.
Download: Project with source
unit ColorButton; { Article: TColorButton - button with Color properties http://delphi.about.com/library/weekly/aa061104a.htm Full source code of the TColorButton Delphi component, an extension to the standard TButton control, with font color, background color and mouse over color properties. } interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, StdCtrls, Buttons, ExtCtrls; type TColorButton = class(TButton) private FBackBeforeHoverColor: TColor; private FCanvas: TCanvas; IsFocused: Boolean; FBackColor: TColor; FForeColor: TColor; FHoverColor: TColor; procedure SetBackColor(const Value: TColor); procedure SetForeColor(const Value: TColor); procedure SetHoverColor(const Value: TColor); property BackBeforeHoverColor : TColor read FBackBeforeHoverColor write FBackBeforeHoverColor; protected procedure CreateParams(var Params: TCreateParams); override; procedure WndProc(var Message : TMessage); override; procedure SetButtonStyle(Value: Boolean); override; procedure DrawButton(Rect: TRect; State: UINT); procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED; procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED; procedure CNMeasureItem(var Message: TWMMeasureItem); message CN_MEASUREITEM; procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property BackColor: TColor read FBackColor write SetBackColor default clBtnFace; property ForeColor: TColor read FForeColor write SetForeColor default clBtnText; property HoverColor: TColor read FHoverColor write SetHoverColor default clBtnFace; end; procedure Register; implementation constructor TColorButton.Create(AOwner: TComponent); begin inherited Create(AOwner); FCanvas := TCanvas.Create; BackColor := clBtnFace; ForeColor := clBtnText; HoverColor := clBtnFace; end; (*Create*) destructor TColorButton.Destroy; begin FCanvas.Free; inherited Destroy; end; (*Destroy*) procedure TColorButton.WndProc(var Message : TMessage); begin if (Message.Msg = CM_MOUSELEAVE) then begin BackColor := BackBeforeHoverColor; invalidate; end; if (Message.Msg = CM_MOUSEENTER) then begin BackBeforeHoverColor := BackColor; BackColor := HoverColor; invalidate; end; inherited; end; (*WndProc*) procedure TColorButton.CreateParams(var Params: TCreateParams); begin inherited CreateParams(Params); with Params do Style := Style or BS_OWNERDRAW; end; (*CreateParams*) procedure TColorButton.SetButtonStyle(Value: Boolean); begin if Value <> IsFocused then begin IsFocused := Value; Invalidate; end; end; (*SetButtonStyle*) procedure TColorButton.CNMeasureItem(var Message: TWMMeasureItem); begin with Message.MeasureItemStruct^ do begin itemWidth := Width; itemHeight := Height; end; end; (*CNMeasureItem*) procedure TColorButton.CNDrawItem(var Message: TWMDrawItem); var SaveIndex: Integer; begin with Message.DrawItemStruct^ do begin SaveIndex := SaveDC(hDC); FCanvas.Lock; try FCanvas.Handle := hDC; FCanvas.Font := Font; FCanvas.Brush := Brush; DrawButton(rcItem, itemState); finally FCanvas.Handle := 0; FCanvas.Unlock; RestoreDC(hDC, SaveIndex); end; end; Message.Result := 1; end; (*CNDrawItem*) procedure TColorButton.CMEnabledChanged(var Message: TMessage); begin inherited; Invalidate; end; (*CMEnabledChanged*) procedure TColorButton.CMFontChanged(var Message: TMessage); begin inherited; Invalidate; end; (*CMFontChanged*) procedure TColorButton.SetBackColor(const Value: TColor); begin if FBackColor <> Value then begin FBackColor:= Value; Invalidate; end; end; (*SetButtonColor*) procedure TColorButton.SetForeColor(const Value: TColor); begin if FForeColor <> Value then begin FForeColor:= Value; Invalidate; end; end; (*SetForeColor*) procedure TColorButton.SetHoverColor(const Value: TColor); begin if FHoverColor <> Value then begin FHoverColor:= Value; Invalidate; end; end; (*SetHoverColor*) procedure TColorButton.DrawButton(Rect: TRect; State: UINT); var Flags, OldMode: Longint; IsDown, IsDefault, IsDisabled: Boolean; OldColor: TColor; OrgRect: TRect; begin OrgRect := Rect; Flags := DFCS_BUTTONPUSH or DFCS_ADJUSTRECT; IsDown := State and ODS_SELECTED <> 0; IsDefault := State and ODS_FOCUS <> 0; IsDisabled := State and ODS_DISABLED <> 0; if IsDown then Flags := Flags or DFCS_PUSHED; if IsDisabled then Flags := Flags or DFCS_INACTIVE; if IsFocused or IsDefault then begin FCanvas.Pen.Color := clWindowFrame; FCanvas.Pen.Width := 1; FCanvas.Brush.Style := bsClear; FCanvas.Rectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom); InflateRect(Rect, - 1, - 1); end; if IsDown then begin FCanvas.Pen.Color := clBtnShadow; FCanvas.Pen.Width := 1; FCanvas.Brush.Color := clBtnFace; FCanvas.Rectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom); InflateRect(Rect, - 1, - 1); end else DrawFrameControl(FCanvas.Handle, Rect, DFC_BUTTON, Flags); if IsDown then OffsetRect(Rect, 1, 1); OldColor := FCanvas.Brush.Color; FCanvas.Brush.Color := BackColor; FCanvas.FillRect(Rect); FCanvas.Brush.Color := OldColor; OldMode := SetBkMode(FCanvas.Handle, TRANSPARENT); FCanvas.Font.Color := ForeColor; if IsDisabled then DrawState(FCanvas.Handle, FCanvas.Brush.Handle, nil, Integer(Caption), 0, ((Rect.Right - Rect.Left) - FCanvas.TextWidth(Caption)) div 2, ((Rect.Bottom - Rect.Top) - FCanvas.TextHeight(Caption)) div 2, 0, 0, DST_TEXT or DSS_DISABLED) else DrawText(FCanvas.Handle, PChar(Caption), - 1, Rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER); SetBkMode(FCanvas.Handle, OldMode); if IsFocused and IsDefault then begin Rect := OrgRect; InflateRect(Rect, - 4, - 4); FCanvas.Pen.Color := clWindowFrame; FCanvas.Brush.Color := clBtnFace; DrawFocusRect(FCanvas.Handle, Rect); end; end; (*DrawButton*) procedure Register; begin RegisterComponents('delphi.about.com', [TColorButton]); end; end.
https://delphisources.ru/pages/faq/base/change_button_color.html
Изменить цвет TButton
{
You cannot change the color of a standard TButton,
since the windows button control always paints itself with the
button color defined in the control panel.
But you can derive derive a new component from TButton and handle
the and drawing behaviour there.
}
unit ColorButton;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;
type
TDrawButtonEvent = procedure(Control: TWinControl;
Rect: TRect; State: TOwnerDrawState) of object;
TColorButton = class(TButton)
private
FCanvas: TCanvas;
IsFocused: Boolean;
FOnDrawButton: TDrawButtonEvent;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure SetButtonStyle(ADefault: Boolean); override;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CNMeasureItem(var Message: TWMMeasureItem); message CN_MEASUREITEM;
procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
procedure DrawButton(Rect: TRect; State: UINT);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Canvas: TCanvas read FCanvas;
published
property OnDrawButton: TDrawButtonEvent read FOnDrawButton write FOnDrawButton;
property Color;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TColorButton]);
end;
constructor TColorButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCanvas := TCanvas.Create;
end;
destructor TColorButton.Destroy;
begin
inherited Destroy;
FCanvas.Free;
end;
procedure TColorButton.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do Style := Style or BS_OWNERDRAW;
end;
procedure TColorButton.SetButtonStyle(ADefault: Boolean);
begin
if ADefault <> IsFocused then
begin
IsFocused := ADefault;
Refresh;
end;
end;
procedure TColorButton.CNMeasureItem(var Message: TWMMeasureItem);
begin
with Message.MeasureItemStruct^ do
begin
itemWidth := Width;
itemHeight := Height;
end;
end;
procedure TColorButton.CNDrawItem(var Message: TWMDrawItem);
var
SaveIndex: Integer;
begin
with Message.DrawItemStruct^ do
begin
SaveIndex := SaveDC(hDC);
FCanvas.Lock;
try
FCanvas.Handle := hDC;
FCanvas.Font := Font;
FCanvas.Brush := Brush;
DrawButton(rcItem, itemState);
finally
FCanvas.Handle := 0;
FCanvas.Unlock;
RestoreDC(hDC, SaveIndex);
end;
end;
Message.Result := 1;
end;
procedure TColorButton.CMEnabledChanged(var Message: TMessage);
begin
inherited;
Invalidate;
end;
procedure TColorButton.CMFontChanged(var Message: TMessage);
begin
inherited;
Invalidate;
end;
procedure TColorButton.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
Perform(WM_LBUTTONDOWN, Message.Keys, Longint(Message.Pos));
end;
procedure TColorButton.DrawButton(Rect: TRect; State: UINT);
var
Flags, OldMode: Longint;
IsDown, IsDefault, IsDisabled: Boolean;
OldColor: TColor;
OrgRect: TRect;
begin
OrgRect := Rect;
Flags := DFCS_BUTTONPUSH or DFCS_ADJUSTRECT;
IsDown := State and ODS_SELECTED <> 0;
IsDefault := State and ODS_FOCUS <> 0;
IsDisabled := State and ODS_DISABLED <> 0;
if IsDown then Flags := Flags or DFCS_PUSHED;
if IsDisabled then Flags := Flags or DFCS_INACTIVE;
if IsFocused or IsDefault then
begin
FCanvas.Pen.Color := clWindowFrame;
FCanvas.Pen.Width := 1;
FCanvas.Brush.Style := bsClear;
FCanvas.Rectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
InflateRect(Rect, - 1, - 1);
end;
if IsDown then
begin
FCanvas.Pen.Color := clBtnShadow;
FCanvas.Pen.Width := 1;
FCanvas.Brush.Color := clBtnFace;
FCanvas.Rectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
InflateRect(Rect, - 1, - 1);
end
else
DrawFrameControl(FCanvas.Handle, Rect, DFC_BUTTON, Flags);
if IsDown then OffsetRect(Rect, 1, 1);
OldColor := FCanvas.Brush.Color;
FCanvas.Brush.Color := Color;
FCanvas.FillRect(Rect);
FCanvas.Brush.Color := OldColor;
OldMode := SetBkMode(FCanvas.Handle, TRANSPARENT);
FCanvas.Font.Color := clBtnText;
if IsDisabled then
DrawState(FCanvas.Handle, FCanvas.Brush.Handle, nil, Integer(Caption), 0,
((Rect.Right - Rect.Left) - FCanvas.TextWidth(Caption)) div 2,
((Rect.Bottom - Rect.Top) - FCanvas.TextHeight(Caption)) div 2,
0, 0, DST_TEXT or DSS_DISABLED)
else
DrawText(FCanvas.Handle, PChar(Caption), - 1, Rect,
DT_SINGLELINE or DT_CENTER or DT_VCENTER);
SetBkMode(FCanvas.Handle, OldMode);
if Assigned(FOnDrawButton) then
FOnDrawButton(Self, Rect, TOwnerDrawState(LongRec(State).Lo));
if IsFocused and IsDefault then
begin
Rect := OrgRect;
InflateRect(Rect, - 4, - 4);
FCanvas.Pen.Color := clWindowFrame;
FCanvas.Brush.Color := clBtnFace;
DrawFocusRect(FCanvas.Handle, Rect);
end;
end;
end.