Recent

Author Topic: [SOLVED] [HINT] TWinControl.CreateWnd...  (Read 903 times)

Espectr0

  • Full Member
  • ***
  • Posts: 221
[SOLVED] [HINT] TWinControl.CreateWnd...
« on: March 03, 2023, 10:56:26 pm »
Hello,

Why suddenly all these "Hint" appear in the console?

Code: Pascal  [Select][+][-]
  1. [HINT] TWinControl.CreateWnd creating Handle during loading frmMain:TfrmMain csDesigning=False
  2. [HINT] TWinControl.CreateWnd creating Handle during loading ToolBarMain:TToolBar csDesigning=False
  3. [HINT] TWinControl.CreateWnd creating Handle during loading cboFPS:TComboBox csDesigning=False
  4. [HINT] TWinControl.CreateWnd creating Handle during loading cboFormat:TComboBox csDesigning=False
  5. [HINT] TWinControl.CreateWnd creating Handle during loading cboEncoding:TComboBox csDesigning=False
  6. [HINT] TWinControl.CreateWnd creating Handle during loading LayoutWaveform:TUWLayout csDesigning=False
  7. [HINT] TWinControl.CreateWnd creating Handle during loading WAVE:TUWWaveformDisplayer csDesigning=False
  8. [HINT] TWinControl.CreateWnd creating Handle during loading ToolBarWaveform:TToolBar csDesigning=False
  9. [HINT] TWinControl.CreateWnd creating Handle during loading LayoutVideo:TUWLayout csDesigning=False
  10. [HINT] TWinControl.CreateWnd creating Handle during loading LayoutVideoControls:TUWLayout csDesigning=False
  11. [HINT] TWinControl.CreateWnd creating Handle during loading ToolBarVideo:TToolBar csDesigning=False
  12. [HINT] TWinControl.CreateWnd creating Handle during loading MPV:TMPVPlayer csDesigning=False
  13. [HINT] TWinControl.CreateWnd creating Handle during loading StatusBar:TStatusBar csDesigning=False
  14. [HINT] TWinControl.CreateWnd creating Handle during loading SplitterWaveform:TSplitter csDesigning=False
  15. [HINT] TWinControl.CreateWnd creating Handle during loading SplitterVideo:TSplitter csDesigning=False
  16. [HINT] TWinControl.CreateWnd creating Handle during loading LayoutSubtitles:TUWLayout csDesigning=False
  17. [HINT] TWinControl.CreateWnd creating Handle during loading LayoutVST:TUWLayout csDesigning=False
  18. [HINT] TWinControl.CreateWnd creating Handle during loading VST:TVirtualStringTree csDesigning=False
  19. [HINT] TWinControl.CreateWnd creating Handle during loading LayoutEditor:TUWLayout csDesigning=False
  20. [HINT] TWinControl.CreateWnd creating Handle during loading LayoutEditorPanel:TUWLayout csDesigning=False
  21. [HINT] TWinControl.CreateWnd creating Handle during loading tedInitial:TUWTimeEdit csDesigning=False
  22. [HINT] TWinControl.CreateWnd creating Handle during loading :TUpDown csDesigning=False

Gracias.
« Last Edit: March 04, 2023, 09:16:43 pm by Espectr0 »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: [HINT] TWinControl.CreateWnd...
« Reply #1 on: March 03, 2023, 11:20:26 pm »
This happens when you perform some Handle-dependent code too early, i.e. you - for example - change height or width in constructor.
I usually solved it by moving such code from constructor to overriden InitializeWnd method.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Espectr0

  • Full Member
  • ***
  • Posts: 221
Re: [HINT] TWinControl.CreateWnd...
« Reply #2 on: March 04, 2023, 11:21:27 am »
Is it possible that it is because of this component so many "hints"?

Code: Pascal  [Select][+][-]
  1. unit UWFlatButton;
  2.  
  3. //------------------------------------------------------------------------------
  4.  
  5. {$mode ObjFPC}{$H+}
  6.  
  7. interface
  8.  
  9. uses
  10.   Classes, Controls, SysUtils, Graphics, LCLType, LazarusPackageIntf,
  11.   BGRABitmap, BGRABitmapTypes, ImgList, UWSystem.SysUtils;
  12.  
  13. type
  14.  
  15.   { UWFlatButton }
  16.  
  17.   TUWFlatButton = class(TGraphicControl)
  18.   private
  19.     FBMP             : TBGRABitmap;
  20.     FHightlightColor : TColor;
  21.     FBorderColor     : TColor;
  22.     FCheckedColor    : TColor;
  23.     FIsOver          : Boolean;
  24.     FMouseIsDown     : Boolean;
  25.     FImageIndex      : TImageIndex;
  26.     FImages          : TCustomImageList;
  27.     procedure SetImageIndex(const AIndex: TImageIndex);
  28.   public
  29.     constructor Create(AOwner: TComponent); override;
  30.     destructor Destroy; override;
  31.     procedure DrawBuffer;
  32.   protected
  33.     procedure Paint; override;
  34.     procedure Loaded; override;
  35.     procedure MouseLeave; override;
  36.     procedure MouseEnter; override;
  37.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  38.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  39.   published
  40.     property HightlightColor : TColor read FHightlightColor write FHightlightColor;
  41.     property BorderColor     : TColor read FBorderColor     write FBorderColor;
  42.     property CheckedColor    : TColor read FCheckedColor    write FCheckedColor;
  43.  
  44.     property Images: TCustomImageList read FImages write FImages;
  45.     property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
  46.  
  47.     property Align;
  48.     property Anchors;
  49.     property Color;
  50.     property Cursor;
  51.     property Enabled;
  52.     property Width default 23;
  53.     property Height default 23;
  54.     property PopupMenu;
  55.     property OnClick;
  56.     property OnMouseDown;
  57.     property OnMouseMove;
  58.     property OnMouseUp;
  59.   end;
  60.  
  61. // -----------------------------------------------------------------------------
  62.  
  63. implementation
  64.  
  65. //------------------------------------------------------------------------------
  66.  
  67. { UWFlatButton }
  68.  
  69. // -----------------------------------------------------------------------------
  70.  
  71. constructor TUWFlatButton.Create(AOwner: TComponent);
  72. begin
  73.   inherited Create(AOwner);
  74.  
  75.   SetBounds(Left, Top, 23, 23);
  76.  
  77.   FHightlightColor := clBtnHighlight;
  78.   FBorderColor     := clActiveCaption;
  79.   FCheckedColor    := clInactiveBorder;
  80.   FIsOver          := False;
  81.   FMouseIsDown     := False;
  82.   FImageIndex      := -1;
  83.   Color            := clBtnFace;
  84.  
  85.   FBMP := TBGRABitmap.Create(Width, Height, ColorToBGRA(Color));
  86. end;
  87.  
  88. // -----------------------------------------------------------------------------
  89.  
  90. destructor TUWFlatButton.Destroy;
  91. begin
  92.   FBMP.Free;
  93.  
  94.   inherited;
  95. end;
  96.  
  97. // -----------------------------------------------------------------------------
  98.  
  99. procedure TUWFlatButton.DrawBuffer;
  100. begin
  101.   FBMP.Fill(Color);
  102.  
  103.   if FIsOver and not FMouseIsDown then
  104.     FBMP.RoundRect(0, 0, Width, Height, 8, 8, FBorderColor, FHightlightColor)
  105.   else if FMouseIsDown then
  106.     FBMP.RoundRect(0, 0, Width, Height, 8, 8, FBorderColor, FCheckedColor);
  107.  
  108.   if Assigned(FImages) and (FImageIndex >= 0) then
  109.     FImages.Draw(FBMP.Canvas, (Width - (FImages.Width)) div 2, (Height - (FImages.Height)) div 2, FImageIndex, Enabled);
  110.  
  111.   FBMP.Draw(Canvas, 0, 0);
  112. end;
  113.  
  114. // -----------------------------------------------------------------------------
  115.  
  116. procedure TUWFlatButton.Paint;
  117. begin
  118.   Canvas.Lock;
  119.   try
  120.     FBMP.Draw(Canvas, 0, 0);
  121.     if csDesigning in ComponentState then Canvas.DrawFocusRect(ClientRect);
  122.   finally
  123.     Canvas.Unlock;
  124.   end;
  125. end;
  126.  
  127. // -----------------------------------------------------------------------------
  128.  
  129. procedure TUWFlatButton.Loaded;
  130. begin
  131.   inherited Loaded;
  132.  
  133.   DrawBuffer;
  134. end;
  135.  
  136. // -----------------------------------------------------------------------------
  137.  
  138. procedure TUWFlatButton.MouseLeave;
  139. begin
  140.   inherited MouseLeave;
  141.  
  142.   FIsOver := False;
  143.   DrawBuffer;
  144. end;
  145.  
  146. // -----------------------------------------------------------------------------
  147.  
  148. procedure TUWFlatButton.MouseEnter;
  149. begin
  150.   inherited MouseEnter;
  151.  
  152.   FIsOver := True;
  153.   DrawBuffer;
  154. end;
  155.  
  156. // -----------------------------------------------------------------------------
  157.  
  158. procedure TUWFlatButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  159. begin
  160.   inherited MouseDown(Button, Shift, X, Y);
  161.  
  162.   if (ssLeft in Shift) then
  163.   begin
  164.     FMouseIsDown := True;
  165.     DrawBuffer;
  166.   end;
  167. end;
  168.  
  169. //------------------------------------------------------------------------------
  170.  
  171. procedure TUWFlatButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  172. begin
  173.   inherited MouseUp(Button, Shift, X, Y);
  174.  
  175.   if FMouseIsDown then
  176.   begin
  177.     FMouseIsDown := False;
  178.     DrawBuffer;
  179.   end;
  180. end;
  181.  
  182. //------------------------------------------------------------------------------
  183.  
  184. procedure TUWFlatButton.SetImageIndex(const AIndex: TImageIndex);
  185. begin
  186.   if FImageIndex <> AIndex then
  187.   begin
  188.     FImageIndex := AIndex;
  189.     DrawBuffer;
  190.   end;
  191. end;
  192.  
  193. //------------------------------------------------------------------------------
  194.  
  195.  

 :-[

zeljko

  • Hero Member
  • *****
  • Posts: 1736
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: [HINT] TWinControl.CreateWnd...
« Reply #3 on: March 04, 2023, 12:23:26 pm »
You are calling DrawBuffer() out of paint event, calling FBMP.Draw(Canvas, 0, 0) inside DrawBuffer() provokes HandleNeeded for parent control, so that's why you have such hints. eg. calling DrawBuffer() in Loaded;.

Espectr0

  • Full Member
  • ***
  • Posts: 221
Re: [HINT] TWinControl.CreateWnd...
« Reply #4 on: March 04, 2023, 12:30:17 pm »
@zeljko:

I understand, and where should it be called when creating the component?

jamie

  • Hero Member
  • *****
  • Posts: 6880
Re: [HINT] TWinControl.CreateWnd...
« Reply #5 on: March 04, 2023, 02:45:25 pm »
don't draw to the canvas of the parent while in the drawbuffer ?

the Paint event will do that for you and at that point you will have a valid parent canvas.
The only true wisdom is knowing you know nothing

Espectr0

  • Full Member
  • ***
  • Posts: 221
Re: [HINT] TWinControl.CreateWnd...
« Reply #6 on: March 04, 2023, 09:16:17 pm »
@jamie, @zeljko fixed, Thanks!


 

TinyPortal © 2005-2018