Skip to content

Commit 3c0c76f

Browse files
committed
Load images and cursors from a native resource file
1 parent f35169d commit 3c0c76f

File tree

4 files changed

+43
-2143
lines changed

4 files changed

+43
-2143
lines changed

Source/VirtualTrees.pas

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ interface
336336
{$ifdef DEBUG_VTV}
337337
VTLogger,
338338
{$endif}
339-
LCLType, LResources, LMessages, Types,
339+
LCLType, LMessages, Types,
340340
SysUtils, Classes, Graphics, Controls, Forms, ImgList, StdCtrls, Menus, Printers,
341341
SyncObjs, // Thread support
342342
Clipbrd // Clipboard support
@@ -3878,6 +3878,8 @@ function WrapString(DC: HDC; const S: String; const Bounds: TRect; RTL: Boolean;
38783878

38793879
implementation
38803880

3881+
{$R VirtualTrees.res}
3882+
38813883
uses
38823884
StrUtils, Math,
38833885
{$ifdef EnableOLE}
@@ -4986,12 +4988,17 @@ procedure InitializeGlobalStructures;
49864988

49874989
// initialization of stuff global to the unit
49884990

4991+
var
4992+
TheInstance: THandle;
4993+
49894994
begin
49904995
Initialized := True;
49914996

49924997
// For the drag image a fast MMX blend routine is used. We have to make sure MMX is available.
49934998
MMXAvailable := HasMMX;
49944999

5000+
TheInstance := HINSTANCE;
5001+
49955002
// There is a bug in Win95 and WinME (and potentially in Win98 too) regarding GetDCEx which causes sometimes
49965003
// serious trouble within GDI (see method WMNCPaint).
49975004

@@ -5008,15 +5015,15 @@ procedure InitializeGlobalStructures;
50085015

50095016
UtilityImages := TBitmap.Create;
50105017
UtilityImages.Transparent := True;
5011-
UtilityImages.LoadFromLazarusResource('VT_UTILITIES');
5018+
UtilityImages.LoadFromResourceName(0, 'VT_UTILITIES');
50125019

50135020
// Specify an useful timer resolution for timeGetTime.
50145021
timeBeginPeriod(MinimumTimerInterval);
50155022

50165023
// Delphi (at least version 6 and lower) does not provide a standard split cursor.
50175024
// Hence we have to load our own.
5018-
Screen.Cursors[crHeaderSplit] := LoadCursorFromLazarusResource('VT_HEADERSPLIT');
5019-
Screen.Cursors[crVertSplit] := LoadCursorFromLazarusResource('VT_VERTSPLIT');
5025+
Screen.Cursors[crHeaderSplit] := LoadCursor(TheInstance, 'VT_HEADERSPLIT');
5026+
Screen.Cursors[crVertSplit] := LoadCursor(TheInstance, 'VT_VERTSPLIT');
50205027
// Clipboard format registration.
50215028
// Native clipboard format. Needs a new identifier and has an average priority to allow other formats to take over.
50225029
// This format is supposed to use the IStream storage format but unfortunately this does not work when
@@ -13120,21 +13127,23 @@ procedure TBaseVirtualTree.LimitPaintingToArea(Canvas: TCanvas; ClipRect: TRect;
1312013127
//----------------------------------------------------------------------------------------------------------------------
1312113128

1312213129
procedure TBaseVirtualTree.LoadPanningCursors;
13123-
13130+
var
13131+
TheInstance: THandle;
1312413132
begin
13133+
TheInstance := HINSTANCE;
1312513134
with Screen do
1312613135
begin
13127-
Cursors[crVT_MOVEALL]:=LoadCursorFromLazarusResource('VT_MOVEALL');
13128-
Cursors[crVT_MOVEEW]:=LoadCursorFromLazarusResource('VT_MOVEEW');
13129-
Cursors[crVT_MOVENS]:=LoadCursorFromLazarusResource('VT_MOVENS');
13130-
Cursors[crVT_MOVENW]:=LoadCursorFromLazarusResource('VT_MOVENW');
13131-
Cursors[crVT_MOVESW]:=LoadCursorFromLazarusResource('VT_MOVESW');
13132-
Cursors[crVT_MOVESE]:=LoadCursorFromLazarusResource('VT_MOVESE');
13133-
Cursors[crVT_MOVENE]:=LoadCursorFromLazarusResource('VT_MOVENE');
13134-
Cursors[crVT_MOVEW]:=LoadCursorFromLazarusResource('VT_MOVEW');
13135-
Cursors[crVT_MOVEE]:=LoadCursorFromLazarusResource('VT_MOVEE');
13136-
Cursors[crVT_MOVEN]:=LoadCursorFromLazarusResource('VT_MOVEN');
13137-
Cursors[crVT_MOVES]:=LoadCursorFromLazarusResource('VT_MOVES');
13136+
Cursors[crVT_MOVEALL]:=LoadCursor(TheInstance, 'VT_MOVEALL');
13137+
Cursors[crVT_MOVEEW]:=LoadCursor(TheInstance, 'VT_MOVEEW');
13138+
Cursors[crVT_MOVENS]:=LoadCursor(TheInstance, 'VT_MOVENS');
13139+
Cursors[crVT_MOVENW]:=LoadCursor(TheInstance, 'VT_MOVENW');
13140+
Cursors[crVT_MOVESW]:=LoadCursor(TheInstance, 'VT_MOVESW');
13141+
Cursors[crVT_MOVESE]:=LoadCursor(TheInstance, 'VT_MOVESE');
13142+
Cursors[crVT_MOVENE]:=LoadCursor(TheInstance, 'VT_MOVENE');
13143+
Cursors[crVT_MOVEW]:=LoadCursor(TheInstance, 'VT_MOVEW');
13144+
Cursors[crVT_MOVEE]:=LoadCursor(TheInstance, 'VT_MOVEE');
13145+
Cursors[crVT_MOVEN]:=LoadCursor(TheInstance, 'VT_MOVEN');
13146+
Cursors[crVT_MOVES]:=LoadCursor(TheInstance, 'VT_MOVES');
1313813147
end;
1313913148
end;
1314013149
//----------------------------------------------------------------------------------------------------------------------
@@ -13380,7 +13389,7 @@ procedure TBaseVirtualTree.PrepareBitmaps(NeedButtons, NeedLines: Boolean);
1338013389
LineTo(Width - 2 , Width div 2);
1338113390
end
1338213391
else
13383-
FMinusBM.LoadFromLazarusResource('VT_XPBUTTONMINUS');
13392+
FMinusBM.LoadFromResourceName(0, 'VT_XPBUTTONMINUS');
1338413393
FHotMinusBM.Canvas.Draw(0, 0, FMinusBM);
1338513394
end;
1338613395
end;
@@ -13422,7 +13431,7 @@ procedure TBaseVirtualTree.PrepareBitmaps(NeedButtons, NeedLines: Boolean);
1342213431
LineTo(Width div 2, Width - 2);
1342313432
end
1342413433
else
13425-
FPlusBM.LoadFromLazarusResource('VT_XPBUTTONPLUS');
13434+
FPlusBM.LoadFromResourceName(0, 'VT_XPBUTTONPLUS');
1342613435
FHotPlusBM.Canvas.Draw(0, 0, FPlusBM);
1342713436
end;
1342813437
end;
@@ -20294,7 +20303,7 @@ procedure TBaseVirtualTree.CheckImageListNeeded;
2029420303
begin
2029520304
FCheckImages := TBitmap.Create;
2029620305
FCheckImages.Transparent := True;
20297-
FCheckImages.LoadFromLazarusResource(CheckImagesStrings[FCheckImageKind]);
20306+
FCheckImages.LoadFromResourceName(0, CheckImagesStrings[FCheckImageKind]);
2029820307
end;
2029920308
end;
2030020309

@@ -23328,7 +23337,7 @@ procedure TBaseVirtualTree.StartWheelPanning(const Position: TPoint);
2332823337
else
2332923338
ImageName := 'VT_MOVENS_BMP';
2333023339

23331-
FPanningWindow.Image.LoadFromLazarusResource(ImageName);
23340+
FPanningWindow.Image.LoadFromResourceName(0, ImageName);
2333223341

2333323342
FPanningWindow.Show(CreateClipRegion);
2333423343

@@ -32933,7 +32942,6 @@ function TVirtualDrawTree.GetOptionsClass: TTreeOptionsClass;
3293332942
//----------------------------------------------------------------------------------------------------------------------
3293432943

3293532944
initialization
32936-
{$I virtualtrees.lrs}
3293732945
// Necessary for dynamic package loading.
3293832946
Initialized := False;
3293932947
NeedToUnitialize := False;

Source/VirtualTrees.res

7.34 KB
Binary file not shown.

0 commit comments

Comments
 (0)