Results 1 to 8 of 8

Thread: ComboBox animatie onderdrukken

  1. #1
    Stijn Sanders develyoy's Avatar
    Join Date
    Jun 2008
    Location
    GentBrugge, Belgi?½
    Posts
    1,046

    ComboBox animatie onderdrukken

    Hoe zou ik kunnen de drop-down-animatie van combo-boxes kunnen onderdrukken binnen een applicatie met code? Ik heb deze geprobeerd, maar dit lijkt niet te werken:

    Delphi Code:
    1. function DwmSetWindowAttribute(HWND:THandle;Attr:cardinal;var attrValue:integer;size:integer):integer; stdcall;
    2.  
    3. implementation
    4.  
    5. const
    6.   DWMWA_TRANSITIONS_FORCEDISABLED = 2;
    7. function DwmSetWindowAttribute; external 'dwmapi.dll';
    8.  
    9. ... FormShow...
    10. var
    11.   i:integer;
    12. begin
    13.   i:=1;
    14.   DwmSetWindowAttribute(Handle,DWMWA_TRANSITIONS_FORCEDISABLED,i,4);

  2. #2
    Weet je zeker dat die constante 2 moet zijn? Volgens mij zit er nog een DWMWA_NCRENDERING_POLICY tussen DWMWA_NCRENDERING_ENABLED en DWMWA_TRANSITIONS_FORCEDISABLED.
    https://docs.microsoft.com/en-us/win...indowattribute

    (dit even buiten het feit of deze aanroep voor een drop-down zou werken)

    Yep. Hier staat dat het 3 moet zijn.
    https://pub.dev/documentation/win32/...-constant.html

  3. #3
    Stijn Sanders develyoy's Avatar
    Join Date
    Jun 2008
    Location
    GentBrugge, Belgi?½
    Posts
    1,046
    Vreemd, zelfs met DWMWA_TRANSITIONS_FORCEDISABLED = 3 blijven die comboboxes 'geänimeerd' open gaan. Ze staan wel op een frame in een page-control, zou het daarmee kunnen te maken hebben? Moet de HWND deze zijn van de frame? Of de combobox zelf?

  4. #4
    Ik was nieuwsgierig maar kan geen manier vinden om dat per applicatie of per combobox te regelen.
    Ik heb die call geprobeerd op de handles van het form, de combobox, en de aparte EditHandle en ListHandle van de combobox. Ook TComboBoxEx lijkt er niets voor te hebben.

    Ik krijg ook de indruk dat dit voor een ander soort animatie is. De constanten voor combobox-animaties heet: `SPI_SETCOMBOBOXANIMATION`, maar die is voor een SystemParametersInfoW, die 'm systeembreed zet, als je applicatie dat mag. In de meeste gevallen zal dat niet mogen.

    En dat brengt me eigenlijk bij de vraag: Als een gebruiker dit in kan stellen in Windows, waarom zou je daar dan in je applicatie van af willen wijken?
    1+1=b

  5. #5
    Stijn Sanders develyoy's Avatar
    Join Date
    Jun 2008
    Location
    GentBrugge, Belgi?½
    Posts
    1,046
    Ik vind het ook gek. Ik was ook al aan het denken dat dat animatietje geen Windows-ding is maar een VCL-ding, en dan moet ik even gaan afdalen tot in de VCL code... (Alleen krijg ik op dit project 'Use debug DCUs' niet aan, vreemd).

    Even nog wat achtergrond: een collega van me heeft op (alle!) comboboxen met ownerdraw een checkbox toegevoegd. Dit werkt op zich wel knap, maar bij elke checkbox-klik aan of uit, doet de combobox dropdown zijn animatietie opnieuw. Op zich wel storend, dus dacht ik ik zoek als ik die kan onderdrukken. Voorlopig vond ik dus nog niets...

  6. #6
    Ik heb een eigen combobox met een checkbox (boolean combo). Wellicht heb je daar iets aan?

    Unit:
    Delphi Code:
    1. {
    2.   untERDCombobox v1.0.0 -
    3.   Custom comboboxes with DropDownList style
    4.  
    5.   for Delphi 2010 - 10.4 by Ernst Reidinga
    6.   [url]https://erdesigns.eu[/url]
    7.  
    8.   This unit is part of the ERDesigns Component Pack.
    9.  
    10.   (c) Copyright 2021 Ernst Reidinga <ernst@erdesigns.eu>
    11.  
    12.   Bugfixes / Updates:
    13.   - Initial Release 1.0.0
    14.  
    15. }
    16.  
    17. unit untERDCombobox;
    18.  
    19. interface
    20.  
    21. uses
    22.   System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, Winapi.Messages,
    23.   System.Types, Vcl.Graphics, Winapi.Windows;
    24.  
    25. const
    26.   ERDComboVersion        = '1.0.0.0';
    27.   ERDBooleanComboVersion = '1.0.0.0';
    28.  
    29. const
    30.   CBRO_NORMAL   = 1;
    31.     CBRO_HOT      = 2;
    32.     CBRO_PRESSED  = 3;
    33.     CBRO_DISABLED = 4;
    34.  
    35.   OM_FIRST      = $7F00;
    36.   OM_AFTERENTER = OM_FIRST + 8;
    37.   OM_AFTEREXIT  = OM_FIRST + 9;
    38.  
    39. type
    40.   TERDCustomComboStyle = (csFixedItemSize, csVariableItemSize);
    41.  
    42.   TERDCustomCombo = class(TCustomComboBox)
    43.   private
    44.     { Private declarations }
    45.     FCurrentState             : Cardinal;
    46.     FNewState                 : Cardinal;
    47.     FBufferedPaintInitialized : Boolean;
    48.     FKillFocus                : Boolean;
    49.     FComboStyle               : TERDCustomComboStyle;
    50.     FFocusRect                : Boolean;
    51.     FItemHeight               : Integer;
    52.  
    53.     procedure SetItemHeight(const I: Integer);
    54.  
    55.     procedure CNCommand(var Message: TWmCommand); message CN_COMMAND;
    56.     procedure CNCtlColorEdit(var Message: TMessage); message CN_CTLCOLOREDIT;
    57.  
    58.     procedure WMKillFocus(var Msg : TWMKillFocus); message WM_KILLFOCUS;
    59.     procedure WMSetFocus(var Msg : TWMSetFocus); message WM_SETFOCUS;
    60.     procedure WMSize(var Message: TMessage); message WM_SIZE;
    61.     procedure WMPaint(var Msg : TWMPaint); message WM_PAINT;
    62.  
    63.     procedure CMMouseEnter(var Message : TMessage); message CM_MOUSEENTER;
    64.     procedure CMMouseLeave(var Message : TMessage); message CM_MOUSELEAVE;
    65.     procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
    66.     procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
    67.     procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
    68.   protected
    69.     { Protected declarations }
    70.     procedure DrawItem(Index: Integer; ItemRect: TRect; State: TOwnerDrawState); override;
    71.  
    72.     procedure CreateParams(var Params: TCreateParams); override;
    73.     procedure SetStyle(const S : TERDCustomComboStyle); reintroduce;
    74.  
    75.     procedure Select; override;
    76.     procedure SetItemIndex(const Value: Integer); override;
    77.  
    78.     procedure PaintWindow(DC : HDC); override;
    79.  
    80.     procedure PaintState(DC: HDC; State: Cardinal);
    81.     procedure StartAnimation(NewState: Cardinal);
    82.     procedure CloseUp; override;
    83.  
    84.     procedure DrawItemX(Index: Integer; ItemRect: TRect; State: TOwnerDrawState; Themed: Boolean); virtual;
    85.   public
    86.     { Public declarations }
    87.     constructor Create(AOwner: TComponent); override;
    88.     destructor Destroy; override;
    89.   published
    90.     { Published declarations }
    91.     property Style: TERDCustomComboStyle read FComboStyle write SetStyle default csFixedItemSize;
    92.     property FocusRect: Boolean read FFocusRect write FFocusRect default True;
    93.     property ItemHeight: Integer read FItemHeight write SetItemHeight default 16;
    94.   end;
    95.  
    96.   TERDCombobox = class(TERDCustomCombo)
    97.   private
    98.     { Private declarations }
    99.     FImages: TImageList;
    100.  
    101.     procedure SetImages(const I: TImageList);
    102.   protected
    103.     { Protected declarations }
    104.     procedure DrawItemX(Index: Integer; ItemRect: TRect; State: TOwnerDrawState; Themed: Boolean); override;
    105.   published
    106.     property Images: TImageList read FImages write SetImages;
    107.  
    108.     property Anchors;
    109.     property Constraints;
    110.     property DragKind;
    111.     property Align;
    112.     property Color;
    113.     property Ctl3D;
    114.     property Cursor;
    115.     property DragCursor;
    116.     property DragMode;
    117.     property DropDownCount;
    118.     property DoubleBuffered;
    119.     property Enabled;
    120.     property Font;
    121.     property FocusRect;
    122.     property ImeMode;
    123.     property ImeName;
    124.     property Items;
    125.     property ItemIndex;
    126.     //property ItemHeight;
    127.     property MaxLength;
    128.     property ParentColor;
    129.     property ParentCtl3D;
    130.     property ParentFont;
    131.     property ParentShowHint;
    132.     property PopupMenu;
    133.     property ShowHint;
    134.     property Sorted;
    135.     //property Style default csFixedItemSize;
    136.     property TabOrder;
    137.     property TabStop;
    138.     property Text;
    139.     property Visible;
    140.     property OnClick;
    141.     property OnDblClick;
    142.     property OnDragDrop;
    143.     property OnDragOver;
    144.     property OnDropDown;
    145.     property OnEndDrag;
    146.     property OnEnter;
    147.     property OnExit;
    148.     property OnKeyDown;
    149.     property OnKeyPress;
    150.     property OnKeyUp;
    151.     property OnSelect;
    152.     property OnStartDrag;
    153.     property OnMouseWheel;
    154.   end;
    155.  
    156.   TERDBooleanComboValueChangeEvent = procedure(Sender: TObject; Value: Boolean) of object;
    157.  
    158.   TERDBooleanCombobox = class(TERDCustomCombo)
    159.   private
    160.     { Private declarations }
    161.     FOnValue     : TERDBooleanComboValueChangeEvent;
    162.  
    163.     FTrueString  : string;
    164.     FFalseString : string;
    165.  
    166.     procedure SetTrueString(const S: string);
    167.     procedure SetFalseString(const S: string);
    168.  
    169.     procedure SetValue(const B: Boolean);
    170.     function GetValue : Boolean;
    171.   protected
    172.     { Protected declarations }
    173.     procedure CreateWnd; override;
    174.     procedure Select; override;
    175.     procedure DrawItemX(Index: Integer; ItemRect: TRect; State: TOwnerDrawState; Themed: Boolean); override;
    176.   public
    177.     { Public declarations }
    178.     constructor Create(AOwner: TComponent); override;
    179.   published
    180.     property TrueString: string read FTrueString write SetTrueString;
    181.     property FalseString: string read FFalseString write SetFalseString;
    182.  
    183.     property Value: Boolean read GetValue write SetValue default True;
    184.     property OnValue: TERDBooleanComboValueChangeEvent read FOnValue write FOnValue;
    185.  
    186.     property Anchors;
    187.     property Constraints;
    188.     property DragKind;
    189.     property Align;
    190.     property Color;
    191.     property Ctl3D;
    192.     property Cursor;
    193.     property DragCursor;
    194.     property DragMode;
    195.     property DoubleBuffered;
    196.     property Enabled;
    197.     property Font;
    198.     property FocusRect;
    199.     property ImeMode;
    200.     property ImeName;
    201.     property ParentColor;
    202.     property ParentCtl3D;
    203.     property ParentFont;
    204.     property ParentShowHint;
    205.     property PopupMenu;
    206.     property ShowHint;
    207.     property TabOrder;
    208.     property TabStop;
    209.     property Visible;
    210.     property OnClick;
    211.     property OnDblClick;
    212.     property OnDragDrop;
    213.     property OnDragOver;
    214.     property OnDropDown;
    215.     property OnEndDrag;
    216.     property OnEnter;
    217.     property OnExit;
    218.     property OnKeyDown;
    219.     property OnKeyPress;
    220.     property OnKeyUp;
    221.     property OnStartDrag;
    222.     property OnMouseWheel;
    223.   end;
    224.  
    225. implementation
    226.  
    227. uses Winapi.UxTheme, Vcl.Themes;
    228.  
    229. (******************************************************************************)
    230. (*
    231. (*  ERD Custom Combobox (TERDCustomCombo)
    232. (*
    233. (******************************************************************************)
    234. constructor TERDCustomCombo.Create(AOwner: TComponent);
    235. begin
    236.   inherited Create(AOwner);
    237.  
    238.   if Style = csFixedItemSize then ControlStyle := ControlStyle + [csFixedHeight];
    239.   FFocusRect  := True;
    240.  
    241.   FBufferedPaintInitialized := Succeeded(BufferedPaintInit);
    242. end;
    243.  
    244. destructor TERDCustomCombo.Destroy;
    245. begin
    246.   if FBufferedPaintInitialized then BufferedPaintUnInit;
    247.  
    248.   inherited Destroy;
    249. end;
    250.  
    251. procedure TERDCustomCombo.SetItemHeight(const I: Integer);
    252. begin
    253.   if ItemHeight <> I then
    254.   begin
    255.     FItemHeight := I;
    256.     RecreateWnd;
    257.   end;
    258. end;
    259.  
    260. procedure TERDCustomCombo.CNCommand(var Message: TWmCommand);
    261. begin
    262.   inherited;
    263.   case Message.NotifyCode of
    264.     CBN_DROPDOWN:
    265.     begin
    266.       StartAnimation(CBRO_PRESSED);
    267.     end;
    268.  
    269.     CBN_CLOSEUP:
    270.     begin
    271.       if (ItemIndex > -1) then
    272.       begin
    273.         Text := Items[ItemIndex];
    274.         Invalidate;
    275.       end;
    276.     end;
    277.   end;
    278. end;
    279.  
    280. procedure TERDCustomCombo.CNCtlColorEdit(var Message: TMessage);
    281. begin
    282.   if StyleServices.Enabled then
    283.   Message.Result := GetStockObject(NULL_BRUSH)
    284. end;
    285.  
    286. procedure TERDCustomCombo.WMKillFocus(var Msg : TWMKillFocus);
    287. begin
    288.   FKillFocus := True;
    289.   inherited;
    290.   FKillFocus := False;
    291.   PostMessage(Handle, OM_AFTEREXIT, 0, 0);
    292. end;
    293.  
    294. procedure TERDCustomCombo.WMSetFocus(var Msg : TWMSetFocus);
    295. begin
    296.   inherited;
    297.   PostMessage(Handle, OM_AFTERENTER, 0, 0);
    298. end;
    299.  
    300. procedure TERDCustomCombo.WMSize(var Message: TMessage);
    301. begin
    302.   if StyleServices.Enabled then BufferedPaintStopAllAnimations(Handle);
    303.   inherited;
    304. end;
    305.  
    306. procedure TERDCustomCombo.WMPaint(var Msg : TWMPaint);
    307. begin
    308.   ControlState := ControlState + [csCustomPaint];
    309.   inherited;
    310.   ControlState := ControlState - [csCustomPaint];
    311. end;
    312.  
    313. procedure TERDCustomCombo.CMMouseEnter(var Message: TMessage);
    314. begin
    315.   if Enabled then StartAnimation(CBRO_HOT);
    316.   Invalidate;
    317.   inherited;
    318. end;
    319.  
    320. procedure TERDCustomCombo.CMMouseLeave(var Message: TMessage);
    321. begin
    322.   if not DroppedDown and Enabled then StartAnimation(CBRO_NORMAL);
    323.   Invalidate;
    324.   inherited;
    325. end;
    326.  
    327. procedure TERDCustomCombo.CMEnabledchanged(var Message: TMessage);
    328. begin
    329.   inherited;
    330.   if not (csDesigning in ComponentState) then
    331.   begin
    332.     if Enabled then
    333.       StartAnimation(CBRO_NORMAL)
    334.     else
    335.       StartAnimation(CBRO_DISABLED);
    336.   end else
    337.     Invalidate;
    338. end;
    339.  
    340. procedure TERDCustomCombo.CMFontChanged(var Message: TMessage);
    341. begin
    342.   inherited;
    343.   if (Items.Count > 0) then
    344.   begin
    345.     ItemIndex := Items.IndexOf(Font.Name);
    346.     Invalidate;
    347.   end;
    348. end;
    349.  
    350. procedure TERDCustomCombo.CMFocusChanged(var Message: TCMFocusChanged);
    351. begin
    352.   //Repaint;
    353.   //Invalidate;
    354. end;
    355.  
    356. procedure TERDCustomCombo.DrawItem(Index : Integer; ItemRect: TRect; State : TOwnerDrawState);
    357. var
    358.   BkColor : TColor;
    359.   BkMode  : Integer;
    360. begin
    361.   if FKillFocus then Exit;
    362.   with Canvas do
    363.   begin
    364.     if (StyleServices.Enabled) then
    365.       BKColor := StyleServices.GetSystemColor(clWindow)
    366.     else
    367.       BkColor := Color;
    368.     if odSelected in State then
    369.     begin
    370.       if StyleServices.Enabled then
    371.         Brush.Color := StyleServices.GetSystemColor(clHighlight);
    372.     end else
    373.       Brush.Color := BkColor;
    374.     FillRect(ItemRect);
    375.     BkMode := GetBkMode(Canvas.Handle);
    376.     SetBkMode(Canvas.Handle, TRANSPARENT);
    377.     DrawItemX(Index, ItemRect, State, False);
    378.     SetBkMode(Canvas.Handle, BkMode);
    379.     Brush.Color := clBlack;
    380.   end;
    381. end;
    382.  
    383. procedure TERDCustomCombo.CreateParams(var Params : TCreateParams);
    384. begin
    385.   inherited CreateParams(Params);
    386.  
    387.   Params.Style := Params.Style or (WS_VSCROLL or CBS_HASSTRINGS or CBS_AUTOHSCROLL);
    388.   Params.Style := Params.Style or CBS_DROPDOWNLIST;
    389.   if Style = csVariableItemSize then
    390.   begin
    391.     Params.Style := Params.Style - CBS_OWNERDRAWFIXED;
    392.     Params.Style := Params.Style + CBS_OWNERDRAWVARIABLE;
    393.   end else
    394.   begin
    395.     Params.Style := Params.Style - CBS_OWNERDRAWVARIABLE;
    396.     Params.Style := Params.Style + CBS_OWNERDRAWFIXED;
    397.   end;
    398.  
    399.   if NewStyleControls and Ctl3D then
    400.     Params.ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
    401. end;
    402.  
    403. procedure TERDCustomCombo.SetStyle(const S : TERDCustomComboStyle);
    404. begin
    405.   if Style <> S then
    406.   begin
    407.     FComboStyle := S;
    408.     if S = csFixedItemSize then
    409.       ControlStyle := ControlStyle + [csFixedHeight]
    410.     else
    411.       ControlStyle := ControlStyle - [csFixedHeight];
    412.     RecreateWnd;
    413.   end;
    414. end;
    415.  
    416. procedure TERDCustomCombo.Select;
    417. begin
    418.   inherited;
    419.   Invalidate;
    420. end;
    421.  
    422. procedure TERDCustomCombo.SetItemIndex(const Value: Integer);
    423. begin
    424.   inherited;
    425.   Invalidate;
    426. end;
    427.  
    428. procedure TERDCustomCombo.PaintWindow(DC : HDC);
    429. var
    430.   animParams     : BP_ANIMATIONPARAMS;
    431.   CR             : TRect;
    432.   hbpAnimation   : HANIMATIONBUFFER;
    433.   hdcFrom, hdcTo : HDC;
    434. begin
    435.   if (not HandleAllocated) then Exit;
    436.   if StyleServices.Enabled then
    437.   begin
    438.     TControlCanvas(Canvas).UpdateTextFlags;
    439.     if not BufferedPaintRenderAnimation(Handle, Canvas.Handle) then
    440.     begin
    441.       FillChar(animParams, sizeof(animParams), 0);
    442.       animParams.cbSize := sizeof(BP_ANIMATIONPARAMS);
    443.       animParams.style := BPAS_LINEAR;
    444.       GetThemeTransitionDuration(StyleServices.Theme[teComboBox], CP_READONLY, FCurrentState, FNewState, TMT_TRANSITIONDURATIONS, animParams.dwDuration);
    445.       CR := ClientRect;
    446.       hbpAnimation := BeginBufferedAnimation(Handle, DC, CR, BPBF_COMPATIBLEBITMAP, nil, &animParams, &hdcFrom, &hdcTo);
    447.       if hbpAnimation <> 0 then
    448.       begin
    449.         if hdcFrom <> 0 then PaintState(hdcFrom, FCurrentState);
    450.         if hdcTo <> 0 then PaintState(hdcTo, FNewState);
    451.         FCurrentState := FNewState;
    452.         EndBufferedAnimation(hbpAnimation, TRUE);
    453.       end;
    454.     end;
    455.   end else
    456.   begin
    457.     inherited PaintWindow(DC);
    458.     Canvas.Handle := DC;
    459.     try
    460.       //
    461.     finally
    462.       Canvas.Handle := 0;
    463.     end;
    464.   end;
    465. end;
    466.  
    467. procedure TERDCustomCombo.PaintState(DC: HDC; State: Cardinal);
    468. var
    469.   Details  : TThemedElementDetails;
    470.   R        : TRect;
    471.   Original : HGDIOBJ;
    472.   PCBI     : TComboBoxInfo;
    473. begin
    474.   if (not HandleAllocated) then Exit;
    475.  
    476.   Details.Element := teComboBox;
    477.   Details.Part := CP_READONLY;
    478.   Details.State := State;
    479.   R := ClientRect;
    480.  
    481.   FillChar(PCBI, SizeOf(PCBI), 0);
    482.   PCBI.cbSize := SizeOf(PCBI);
    483.   GetComboBoxInfo(Handle, PCBI);
    484.  
    485.   StyleServices.DrawParentBackground(Handle, DC, Details, True, @R);
    486.   StyleServices.DrawElement(DC, Details, ClientRect);
    487.   R := PCBI.rcItem;
    488.   Inc(R.Left, 1);
    489.   Canvas.Font := Font;
    490.   Original := SelectObject(DC, Font.Handle);
    491.  
    492.   if Focused and (not DroppedDown) and not (csDesigning in ComponentState) then
    493.   begin
    494.     if FocusRect then DrawFocusRect(DC, pcbi.rcItem);
    495.   end;
    496.  
    497.   Canvas.Handle := DC;
    498.   try
    499.     DrawItemX(ItemIndex, R, [], True);
    500.   finally
    501.     Canvas.Handle := 0;
    502.   end;
    503.   SelectObject(DC, Original);
    504.  
    505.   Details.Part := CP_DROPDOWNBUTTONRIGHT;
    506.   Details.State := 0;
    507.   if Enabled then
    508.     Details.State := 0
    509.   else
    510.     Details.State := CBRO_DISABLED;
    511.   StyleServices.DrawElement(DC, Details, PCBI.rcButton);
    512. end;
    513.  
    514. procedure TERDCustomCombo.StartAnimation(NewState: Cardinal);
    515. begin
    516.   FNewState := NewState;
    517.   if StyleServices.Enabled then InvalidateRect(Handle, nil, True);
    518. end;
    519.  
    520. procedure TERDCustomCombo.CloseUp;
    521. begin
    522.   inherited;
    523.   StartAnimation(CBRO_NORMAL);
    524. end;
    525.  
    526. procedure TERDCustomCombo.DrawItemX(Index: Integer; ItemRect: TRect; State: TOwnerDrawState; Themed: Boolean);
    527. begin
    528. end;
    529.  
    530. (******************************************************************************)
    531. (*
    532. (*  ERD Combobox (TERDCombobox)
    533. (*
    534. (******************************************************************************)
    535. procedure TERDCombobox.SetImages(const I: TImageList);
    536. begin
    537.   FImages := I;
    538.   Invalidate;
    539. end;
    540.  
    541. procedure TERDCombobox.DrawItemX(Index: Integer; ItemRect: TRect; State: TOwnerDrawState; Themed: Boolean);
    542. var
    543.   R : TRect;
    544. begin
    545.   if (Items.Count <= 0) or (Index = -1) then Exit;
    546.   { Clear brush }
    547.   Canvas.Brush.Style := bsClear;
    548.   { Set Rect }
    549.   R := ItemRect;
    550.   if Themed then
    551.     R.Left := 4
    552.   else
    553.     R.Left := 2;
    554.   { Draw Image }
    555.   if Assigned(FImages) then
    556.   begin
    557.     if (Index < FImages.Count) then
    558.       FImages.Draw(Canvas, R.Left, R.Top + ((R.Height div 2) - (FImages.Height div 2)), Index);
    559.     R.Left := R.Left + FImages.Width + 2;
    560.   end;
    561.   { Draw text }
    562.   DrawText(Canvas.Handle, Items[Index], Length(Items[Index]), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_END_ELLIPSIS);
    563. end;
    564.  
    565. (******************************************************************************)
    566. (*
    567. (*  ERD Boolean Combobox (TERDBooleanCombobox)
    568. (*
    569. (******************************************************************************)
    570. constructor TERDBooleanCombobox.Create(AOwner: TComponent);
    571. begin
    572.   inherited Create(AOwner);
    573.  
    574.   FTrueString  := 'True';
    575.   FFalseString := 'False';
    576. end;
    577.  
    578. procedure TERDBooleanCombobox.SetTrueString(const S: string);
    579. begin
    580.   if TrueString <> S then
    581.   begin
    582.     FTrueString := S;
    583.     Items[0] := S;
    584.     Invalidate;
    585.   end;
    586. end;
    587.  
    588. procedure TERDBooleanCombobox.SetFalseString(const S: string);
    589. begin
    590.   if FalseString <> S then
    591.   begin
    592.     FFalseString := S;
    593.     Items[1] := S;
    594.     Invalidate;
    595.   end;
    596. end;
    597.  
    598. procedure TERDBooleanCombobox.SetValue(const B: Boolean);
    599. begin
    600.   if Value <> B then
    601.   begin
    602.     if B then
    603.       ItemIndex := 0
    604.     else
    605.       ItemIndex := 1;
    606.   end;
    607. end;
    608.  
    609. function TERDBooleanCombobox.GetValue : Boolean;
    610. begin
    611.   Result := ItemIndex = 0;
    612. end;
    613.  
    614. procedure TERDBooleanCombobox.CreateWnd;
    615. begin
    616.   inherited CreateWnd;
    617.   Items.Clear;
    618.   Items.Add(TrueString);
    619.   Items.Add(FalseString);
    620.   ItemIndex := 0;
    621.   Invalidate;
    622. end;
    623.  
    624. procedure TERDBooleanCombobox.Select;
    625. begin
    626.   inherited;
    627.   if Assigned(FOnValue) then FOnValue(Self, ItemIndex = 0);
    628. end;
    629.  
    630. procedure TERDBooleanCombobox.DrawItemX(Index: Integer; ItemRect: TRect; State: TOwnerDrawState; Themed: Boolean);
    631. var
    632.   R : TRect;
    633. begin
    634.   if (not HandleAllocated) then Exit;
    635.   if (Items.Count <= 0) or (Index = -1) or (not HandleAllocated) then Exit;
    636.   { Clear brush }
    637.   Canvas.Brush.Style := bsClear;
    638.   { Set Rect }
    639.   R := ItemRect;
    640.   if Themed then
    641.     R.Left := 22
    642.   else
    643.     R.Left := 20;
    644.   { Draw the text before we draw the checkbox - because else our brush is not clear and will draw a background color }
    645.   DrawText(Canvas.Handle, Items[Index], Length(Items[Index]), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_END_ELLIPSIS);
    646.   { Draw Check/Radio }
    647.   R := ItemRect;
    648.   if Themed then
    649.     R.Left := 4
    650.   else
    651.     R.Left := 2;
    652.   R.Right := R.Left + 16;
    653.   if StyleServices.Enabled then
    654.   begin
    655.    if Enabled then
    656.     case Index of
    657.      0: StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(tbCheckBoxCheckedNormal), R);
    658.      1: StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(tbCheckBoxUncheckedNormal), R);
    659.     end
    660.    else
    661.     StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(tbCheckBoxUncheckedNormal), R);
    662.   end
    663.  else
    664.   if Enabled then
    665.     case Index of
    666.      0: DrawFrameControl(Canvas.Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_CHECKED);
    667.      1: DrawFrameControl(Canvas.Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK);
    668.     end
    669.    else
    670.     DrawFrameControl(Canvas.Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_INACTIVE);
    671. end;
    672.  
    673. end.

  7. #7
    Quote Originally Posted by develyoy View Post
    Ik vind het ook gek. Ik was ook al aan het denken dat dat animatietje geen Windows-ding is maar een VCL-ding, en dan moet ik even gaan afdalen tot in de VCL code... (Alleen krijg ik op dit project 'Use debug DCUs' niet aan, vreemd).
    Nog even terugkomend hierop... (en voor compleetheid van het archief)... het is geen VCL dingentje hoor. Zoals Jos al aan heeft gegeven is het de SPI_SETCOMBOBOXANIMATION system setting die hier voor zorgt.

    Dit kun je ook heel makkelijk zelf testen:
    Delphi Code:
    1. var B: BOOL;
    2. begin
    3.   B := false;
    4.   Win32Check(SystemParametersInfo(SPI_SETCOMBOBOXANIMATION, 0, Pointer(B), 0));
    5. end;

    Het is dan alleen wel netjes als je hem ook weer terugzet (uitlezen met SPI_GETCOMBOBOXANIMATION) als je je applicatie weer afsluit.

    Info:
    Dropdown simuleren: https://stackoverflow.com/questions/...elphi/29553376
    (hier kun je vinden of er wel animatie voor dropdown in systemsetting staat en dit b.v. simuleren met eigen form)

    https://docs.microsoft.com/en-us/win...arametersinfoa
    Waar de info over de SPI_GETCOMBOBOXANIMATION en SPI_SETCOMBOBOXANIMATION staat.

    Andere discussie hierover: http://www.delphigroups.info/2/19/412778.html

  8. #8
    Het is dan alleen wel netjes als je hem ook weer terugzet (uitlezen met SPI_GETCOMBOBOXANIMATION) als je je applicatie weer afsluit.
    Het is vooral wel netjes als je 'm niet aanpast. Je beïnvloedt het gedrag van andere applicaties zolang jouw applicatie draait.
    Als je het toch doet, zou je het terug moeten zetten zodra je applicatie de focus verliest, zodat een ander applicatie als vanouds reageert als je daarheen alt-tabt.

    Maar hou er ook rekening mee, dat het aanpassen van zo'n systeeminstelling resulteert in een message naar alle applicaties, zodat ze hun eigen UI en andere instellingen eventueel kunnen bijwerken. Dat resulteert dus mogelijk weer in geknipper, vertragingen of andere onvoorspelbare bijwerkingen in andere applicaties.

    Dus echt, tenzij je wizards maakt om mensen te helpen dit soort systeeminstellingen te veranderen, moet je er gewoon afblijven. Als je echt wil dat je dropdown er anders uitziet, kan je beter een custom control gebruiken dan TComboBox.
    1+1=b

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •