How to show form w/out focusing it? lazarus / 31-LCL ---------------------------------------------------------------------- AlexTP · 2022-09-04 15:48 I need to do TForm.Show but w/out focusing the form (my app needs the form acting like a tooltip). How can I do it? Do i need to wait some delay (eg 100ms), and force focus on the main form? (Form will be TopMost.) ---------------------------------------------------------------------- AlexTP · 2022-09-04 18:03 Additional question: how IDE shows its editor tooltips w/o focusing them? Is it enough that tooltip's form don't have focusable controls? So IDE tooltips are not focused. ---------------------------------------------------------------------- BrunoK · 2022-09-04 18:18 Maybe something like in the attached test project ? ---------------------------------------------------------------------- AlexTP · 2022-09-04 18:23 Nope, this project shows focusable form (it gets the focus on showing), while I need to show the form w/o focusing. ---------------------------------------------------------------------- zeljko · 2022-09-04 19:19 Qt/Qt5 have QWidget_setAttribute(Qt_WA_ShowWithoutActivating, True);, don't know for others. ---------------------------------------------------------------------- Arioch · 2022-09-26 13:52 Remember, which form had focus, then show your form, then show that prior form to make it have the focus back ---------------------------------------------------------------------- zamtmn · 2022-09-26 14:04 Quote from: Arioch on September 26, 2022, 03:52:37 pmRemember, which form had focus, then show your form, then show that prior form to make it have the focus back It doesn't work well. Main form title has time to blink due to the loss of focus. I need such forms for toolbars and, for example, TMyComboBox implementations ---------------------------------------------------------------------- Arioch · 2022-09-26 15:03 At least on Windows/Native there is precious little you can do the best would be, in LCL terms, Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     NewForm.PopupMode := pmAuto;    NewForm.Visible := True;    OldForm.SetFocus;  Still flickers with caption, but not for long. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     NewForm.PopupParent := OldForm;    NewForm.WindowState := wsMinimized;    NewForm.Visible := True;    NewForm.WindowState := wsNormal;    OldForm.SetFocus;  This makes new form smoothly slide up, and this animation steald user attentioon, so he does not see the flicker :-) To get it flicker-less LCL (with all the toolkits) has to be refactored so that showing and activating (getting focus) would be decoupled and TWSWinControlClass(WidgetSetClass).ShowHide(Self); either would have some flags, which of the two functions to skip. Or should only do non-activating showing and to have an extra explicit call to SetFocus requires. Which, maybe, would cause new form flickering instead. This probably also makes docking libraries in LCL problematic... At least on Windows/Native the process of showing goes down to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i class procedure TWin32WSCustomForm.ShowHide(const AWinControl: TWinControl);const  WindowStateToFlags: array[TWindowState] of DWord = ( { wsNormal     } SW_SHOWNORMAL, // to restore from minimzed/maximized we need to use SW_SHOWNORMAL instead of SW_SHOW { wsMinimized  } SW_SHOWMINIMIZED, { wsMaximized  } SW_SHOWMAXIMIZED, { wsFullScreen } SW_SHOWMAXIMIZED  // win32 has no fullscreen window state  );var  Flags: DWord;begin  if AWinControl.HandleObjectShouldBeVisible then  begin    Flags := WindowStateToFlags[TCustomForm(AWinControl).WindowState];    Windows.ShowWindow(AWinControl.Handle, Flags);  it gets called from Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TWinControl.CMShowingChanged(var Message: TLMessage);begin  {$IFDEF VerboseShowing}  DebugLn(['TWinControl.CMShowingChanged ',DbgSName(Self),' HandleAllocated=',HandleAllocated,' ',dbgs(ComponentState)]);  {$ENDIF}  if HandleAllocated and ([csDestroying,csLoading]*ComponentState=[]) then    DoSendShowHideToInterface  else    Exclude(FWinControlFlags, wcfHandleVisible);end; .... procedure TWinControl.DoSendShowHideToInterface;...    TWSWinControlClass(WidgetSetClass).ShowHide(Self);  Microsoft: https://learn.microsoft.com/en- us/windows/win32/api/winuser/nf-winuser-showwindow Falgs you need are either SW_SHOWNOACTIVATE or SW_SHOWNA But TWin32WSCustomForm.ShowHide - does not have any, Despite right above there is Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i class procedure TWin32WSCustomForm.SetShowInTaskbar(const AForm: TCustomForm;  const AValue: TShowInTaskbar); .....   // now we need to restore window visibility with saving focus  if Visible then    if Active then      ShowWindow(AForm.Handle, SW_SHOW)    else      ShowWindow(AForm.Handle, SW_SHOWNA);end;  you can not work-arount it bypassing LCL like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i        NeewForm.PopupMode := pmAuto;   Windows.ShowWindow( NewForm.Handle, SW_SHOWNA );  Doing so you would get dead empty window then as LCL only puts behavior and widgets to the window during its first-time showing and activation. On Delphi/VCL/Windows it is not possible normally too, but there is a hack (not working in LCL) https://stackoverflow.com/questions/700698/delphi-show-window-without- activation https://stackoverflow.com/questions/20548321/how-can-i-make-a-form- visible-and-maximize-it-to-fill-a-secondary-monitor-withou ---------------------------------------------------------------------- KodeZwerg · 2022-09-26 15:28 On windows this works. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  Form2.Show;  Self.SetFocus;end; ---------------------------------------------------------------------- Arioch · 2022-09-26 15:31 That's what i told above. Quote from: Arioch on September 26, 2022, 03:52:37 pmRemember, which form had focus, then show your form, then show that prior form to make it have the focus back But this indeed makes Form1 flicker the captionbar. Not sure how much a problem that is. But the Delphi discusisons imply that is indeed. ---------------------------------------------------------------------- KodeZwerg · 2022-09-26 15:36 In my small test (one form with a button and one empty form, both created via lpr) no flicker, no taskbar change, no nothing. It does exact do what the OP was asking for, anyway, good luck. ---------------------------------------------------------------------- Arioch · 2022-09-26 15:47 Quote from: KodeZwerg on September 26, 2022, 05:36:08 pmIn my small test (one form with a button and one empty form, both created via lpr) no flicker, no taskbar change, no nothing. It does exact do what the OP was asking for, anyway, good luck. Maybe you have windows animaitons turned off, or maybe something else. I was checking on a live project (forms from DFM, created on demand, not very complex but having grid and paintbox) on Windows 7 default theme and visuals - and the flicker is noticeable. If i turn Aero off - the animations are much shorter and the flicker gets much faster and really hard to notice. It is annoying, but you rarely sure if you saw it or not. If i additionally go System Properties - performance - visuals and turn all the visual effects off, then without animations the flicker becomes unnoticeable indeed. It is complete before human eyes can notice it. But few run Windows with bare bones visuals today... ---------------------------------------------------------------------- KodeZwerg · 2022-09-26 15:56 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  s : string;  FHintRect: TRect;  FHintWin: THintWindow;begin   FHintWin := THintWindow.Create(Self);   try     s := 'This is a test!'+sLineBreak+'Line #2';     FHintRect := FHintWin.CalcHintRect(200, s, nil);     FHintWin.ActivateHint(FHintRect, s);     FHintWin.Refresh;   finally     // FHintWin.ReleaseHandle;   end;end;Than the only thing that i do know of, is a hintwindow, it can not be focused and just display by default text.