Jump to content
Clément

Toolbar + ToolButton + TitleBar flicking

Recommended Posts

Hi,

I'm using D12 for this project. I'm using VCL Styles, but the same behavior happens without styles.


The first icon will call TFileOpenDialog.Execute. During this call, both TitleBarPanel.Caption and the button.caption icon "blink".

Why is that?

 

 

Here's the code:

 

procedure TfrmMain.btnLoadFolderClick(Sender: TObject);
begin
  FileOpenDialog1.Options := [fdoPickFolders];
  fLogFiles.edtLogFiles.BeginUpdate;
  try
    // Flicking starts
    if FileOpenDialog1.Execute then begin
    // Flicking ends
       var lEncoding := fEncodingList[fCurrentEncodingIndex];
       {...}
 finally
 end;
end;

 

Share this post


Link to post

Style sludge and shadow it's hard to know which window is showmodal.  I like to move the cursor to control being surfaced to help end user know which window has focus. Windows is flashing the active window though the smoke to alert you pushing buttons on inactive window. :classic_ninja:   

Share this post


Link to post
12 hours ago, Clément said:

Hi,

I'm using D12 for this project. I'm using VCL Styles, but the same behavior happens without styles.


The first icon will call TFileOpenDialog.Execute. During this call, both TitleBarPanel.Caption and the button.caption icon "blink".

Why is that?

 

 

Here's the code:

 


procedure TfrmMain.btnLoadFolderClick(Sender: TObject);
begin
  FileOpenDialog1.Options := [fdoPickFolders];
  fLogFiles.edtLogFiles.BeginUpdate;
  try
    // Flicking starts
    if FileOpenDialog1.Execute then begin
    // Flicking ends
       var lEncoding := fEncodingList[fCurrentEncodingIndex];
       {...}
 finally
 end;
end;

 

You should not show a dialog inside a BeginUpdate/EndUpdate block in my opinion. That may be the source of your problem and it also serves no purpose i can see here.

Share this post


Link to post

I modified my code completely, but still the same behavior persists:

 

function TfrmMain.DoGetFolder( var aFoldername : String ) : Boolean;
begin
  FileOpenDialog1.Options := [fdoPickFolders];
  try
     Result := FileOpenDialog1.Execute;
     if Result then
        aFoldername := FileOpenDialog1.FileName
     else
        aFoldername := '';

     DoUpdateStatusBar([sabasePath],[aFoldername] );
  finally
     FileOpenDialog1.Options := FileOpenDialog1.Options - [fdoPickFolders];
  end;
end;

procedure TfrmMain.DoLoadLogFilesFromBaseFolder;
var
  lBaseFolder : String;
begin
  if DoGetFolder( lBaseFolder) then
  begin
     DoReadFolders( lBaseFolder, fEncodingList[fCurrentEncodingIndex] );
     DoUpdateLogFilesBrowser(lBaseFolder);
     DoReloadLogFiles;
  end;
end;

procedure TfrmMain.btnLoadFolderClick(Sender: TObject);
begin
  PostMessage(Handle, _UM_MAINFORM_DELAYEVENT , 0 , _UP_MAINFORM_LOADFOLDER);
end;

procedure TfrmMain.btnLoadFilesClick(Sender: TObject);
begin
  PostMessage(Handle, _UM_MAINFORM_DELAYEVENT , 0 , _UP_MAINFORM_LOADFILES);
end;

procedure TfrmMain.msg_MAINFORM_DELAYEVENT(var aMsg: TMessage);
begin
   aMsg.Result := 1;
   case aMsg.LParam of
      _UP_MAINFORM_LOADFOLDER : DoLoadLogFilesFromBaseFolder;
      _UP_MAINFORM_LOADFILES  : DoLoadLogFilesFromFileList;
   else
     aMsg.Result := 0;
   end;
end;

The idea here is to let the button animation happen, and then execute TFileOpenDialog.Execute. But still, when TFileOpenDialog.Execute is called, both titlebar and Toolbutton flickers.

 

Share this post


Link to post
Posted (edited)

I'm debugging VCL.Dialogs and the components flickers in the line below:

 

{$IFDEF CLR}[UIPermission(SecurityAction.LinkDemand, Window=UIPermissionWindow.SafeSubWindows)]{$ENDIF}
function TCustomFileDialog.Execute(ParentWnd: HWND): Boolean;
const
  CDialogOptions: array[TFileDialogOption] of DWORD = ({... });
var
  LWindowList: TTaskWindowList;
  {... }
begin
  if Win32MajorVersion < 6 then
    raise EPlatformVersionException.CreateResFmt({$IFNDEF CLR}@{$ENDIF}SWindowsVistaRequired, [ClassName]);

  Result := False;
  {...}

        // Show dialog and get results
        DoOnExecute;
        LWindowList := DisableTaskWindows(ParentWnd);
        LFocusState := SaveFocusState;
        SaveHooks := TStyleManager.SystemHooks;
        TStyleManager.SystemHooks := [];
        try
          LDialogEvents := TFileDialogEvents.Create(Self);
          Advise(LDialogEvents, LAdviseCookie);
          if (fdoPickFolders in FOptions) and (Win32MajorVersion = 6) and (Win32MinorVersion = 0) then // Vista and Windows Server 2008 bug
            OnFolderChange := SaveActualFolder;
          try
            Result := Succeeded(Show(ParentWnd));  // ## Line 4941 caption goes bananas
            if Result then
              Result := Succeeded(GetResults);
          finally
            Unadvise(LAdviseCookie);
          end;
        finally
          EnableTaskWindows(LWindowList);
          SetActiveWindow(ParentWnd);
          RestoreFocusState(LFocusState);
          TStyleManager.SystemHooks := SaveHooks;
        end;
      end;
    finally
      FDialog := nil;
    end;
end;

If I remove Titlebar component, only the Toolbutton flicks...

Should I drop TToolbar / TToolbutton for a Tpanel / TSpeedButton ? 😞
(It's easier to replace those two then create a new file dialog from scratch)

 

Edit:

I just tested with Tpanel/TSpeedButton and the button icon also disappears.

 

 

Edited by Clément

Share this post


Link to post

I tested once more  removing VCL Styles with the new code ( using postmessage) and the flick stopped completely. :classic_blink:

Going native!

 

Share this post


Link to post
Posted (edited)
51 minutes ago, Attila Kovacs said:

Create an MCVE.

I'm using the VCL Style in this sample. As is, you click the open folder button (first one) to see the blink.
If you change the VCL Style to "Windows" and recompile, the button will no longer blink, only the Titlebar.
If you remove VCL Styles and titlebar, it behaves as expected.

Blink_Sample.zip

Edited by Clément

Share this post


Link to post

Okay, apparently you are on windows 11 because on W10 I can't even see what this style does. This TitleBarPanel is also new for me, so I'm out sorry. 

But it looks interesting. I'm curious what the problem is.

Share this post


Link to post

Title bar panel is effectively VCL styles because theres no api for that, I think. So you probably just have to suck it up. 

Share this post


Link to post
1 hour ago, Attila Kovacs said:

Okay, apparently you are on windows 11 because on W10 I can't even see what this style does. This TitleBarPanel is also new for me, so I'm out sorry. 

But it looks interesting. I'm curious what the problem is.

yes. I'm windows 11

Share this post


Link to post

Is there a way to file a Bug report so Embo can take a look at it? This bug is duplicated and might solve other problems with VCL Styles in windows 11.

Share this post


Link to post
Posted (edited)
10 minutes ago, Clément said:

Is there a way to file a Bug report so Embo can take a look at it? This bug is duplicated and might solve other problems with VCL Styles in windows 11.

According to Nostradamus, not anymore this year.

 

Edited by Attila Kovacs

Share this post


Link to post

"In the realm of coding, a tempest shall brew a buggy IDE, causing much ado.
Programmers´ patience tested, their sanity tried, as they navigate errors,

with nowhere to hide."

               -- NostraGPTamus

 

 

 

Share this post


Link to post

Not tested for your example but I have been trying to get TTitlebar to draw and behave correctly for a few days.

What I found was if I had any VCL style set and any window is brought in front of the application and I moved my mouse around its titlebar area it would all revert to the VCL style and not use the custom color in my case black black.

I was using TToolbar and its associated buttons with text and icons.

What I had to do was turn on the default windows setting and then make sure the TToolbar was not transparent.

It would then repaint correctly in terms of the buttons and icons set.

Share this post


Link to post

Actually I should also say Win10 mostly worked from memory but Windows Server 2022 was playing up which was was being used by Citrix and RDP.

Share this post


Link to post
5 minutes ago, bdw_nz20 said:

What I had to do was turn on the default windows setting and then make sure the TToolbar was not transparent.

Thanks for your suggestion. Unfortunately toggling properties "Transparent", "Flat", "Ctl3D", "HideClippedBUttons" lead to the same behavior.

Even tried "StyleELements := []; "  with no luck.

I set Toolbar.Stylename := 'Windows'  to use both styles, but sill no joy.

 

Under Windows 11 the only way is 100% native.

Share this post


Link to post

okay, how about setting DoubBuffered:=true ?  That is used to stop flicker in most controls and I've used this feature for many years, since Delphi 6.

 

The following may work: 

 

form1.doublebuffered := true;
toolbar1.doublebuffered := true;
titlebarpanel1.doublebuffered := true;

 

You can add that in the form's Create of Activate event.  This should work.

Share this post


Link to post

Yes I have the DoubleBuffered to True, the Transparent is False.

I forgot to say DrawStyle := dsGradient and in my case I set the GradientEndColor and GradientStartColor in the OnActivate Form function.

I got that from the EMB example code in Getit.

void __fastcall TFormMain::FormActivate(TObject *Sender)
{
    TColor LBackgroundColor;
    if (FormMain->Active) {
      LBackgroundColor = FormMain->CustomTitleBar->ButtonBackgroundColor;
    } else {
      LBackgroundColor = FormMain->CustomTitleBar->ButtonInactiveBackgroundColor;
    }
    ToolBarTitleMain->HotTrackColor = FormMain->CustomTitleBar->ButtonHoverBackgroundColor;
    ToolBarTitleMain->GradientStartColor = LBackgroundColor;
    ToolBarTitleMain->GradientEndColor = LBackgroundColor;
    ToolBarTitleTabs->HotTrackColor = FormMain->CustomTitleBar->ButtonHoverBackgroundColor;
    ToolBarTitleTabs->GradientStartColor = LBackgroundColor;
    ToolBarTitleTabs->GradientEndColor = LBackgroundColor;
    ToolBarTitleRight->HotTrackColor = FormMain->CustomTitleBar->ButtonHoverBackgroundColor;
    ToolBarTitleRight->GradientStartColor = LBackgroundColor;
    ToolBarTitleRight->GradientEndColor = LBackgroundColor;
}

 

Share this post


Link to post
Posted (edited)

Hi..

 

I added those lines to the main form constructor:
 

constructor TfrmMain.Create(AOwner: TComponent);
begin
  inherited;
  fLogEngine := TdhsLogViewerEngine.Create;
  fLogEngine.OnRefreshLines := event_refreshlines;
  fLogEngine.OnEngineStatus := event_engineStatus;
  fShowLongField := false;
  Caption := Application.Title+' v'+strBuildInfoEx+' Beta ';
  fSearchTextCount := 0;
  fUpdate := TApplicationUpdate.Create;
  fEncodingList[1] := TEncoding.ANSI;
  fEncodingList[2] := TEncoding.UTF8;
  fEncodingList[3] := TEncoding.ASCII;
  fEncodingList[4] := TEncoding.Unicode;
  fEncodingList[5] := TEncoding.BigEndianUnicode;

  fCurrentEncodingIndex := 2;

  DoShowStatusBarSearchCount;
  DoConfigProgressBar;

  // Bug fixing attempts
  DoubleBufferedMode := dbmRequested;
  DoubleBuffered     := true;
  ToolBar1.Transparent := false;
  Toolbar1.Flat        := true;
  ToolBar1.DoubleBufferedMode := dbmRequested;
  Toolbar1.DoubleBuffered := true;



end;

I manually checked that every property is assigned properly. Still no joy

 

Edited by Clément

Share this post


Link to post

In 2147 people will still be suggesting setting DoubleBuffered true to solve flicker problems rather than fixing the actual problem 

Share this post


Link to post
Posted (edited)

I'm a lot closer to what I want using VCL Styles. The form is a lot cleaner.
I will have to implement a "Style ON / Style Off" for PITA customers.
I took 2 screen shots to show you the difference between them.
Without styles I would have to handle a lot more "design issues"

 

 

Using VCL_Style.png

No Style.png

Edited by Clément

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×