Main menu flickers badly in IDE and apps generated by it. lazarus / 34-Windows ---------------------------------------------------------------------- jamie · 2022-12-09 02:45 Apps with a Main Menu and a few items will flicker badly in some cases while moving the form around.  Seen with the IDE and many apps generated by it.  Is there some sort of redundant refresh being done? ---------------------------------------------------------------------- dbannon · 2022-12-09 03:56 What is flickering ?  The Main menu "button" (for lack of a better word) or the menu contents ? I cannot move the application while menu contents is displayed so must be first choice ? OS, widget set ? Davo ---------------------------------------------------------------------- jamie · 2022-12-09 14:43 U don't need to drop a menu. Just simply move a form around that has a list of headings This is windows . Moving it back to left is very noticeable and moving it to right is just random in flicker . This problem has been there on all versions of laz since started using it back before 1.64 ---------------------------------------------------------------------- dbannon · 2022-12-09 22:57 I only have two apps supported on Windows and neither has a conventional main menu so I cannot comment. Strange that no one else has commented .... Might be useful to move this thread to under a Windows heading ? Davo ---------------------------------------------------------------------- wp · 2022-12-09 23:16 Cannot confirm any flicker on Win 11 when I drag the IDE's main form with the menu left and right with IDE (Laz/main, Laz 1.4.4). ---------------------------------------------------------------------- Martin_fr · 2022-12-10 00:10 Well I do vaguely recall that a similar report had been around ages ago. Not sure what the outcome was, i.e. if it ever was even reproduced. I take it, it must be pretty noticeable the way you describe it? And then given that the IDE itself has a main menu, anyone (on Win) who ever moved the IDE-main-bar should have noticed it? So I would guess there must be more to what causes it. Sofar, I know "Windows" as you mention that. Which version of Windows, bitness? Potentially some interaction between LCL and Graphics card or driver - or even monitor? You have carefully tried with various other apps, and none had the issue (sorry for asking, but I don't always take the obvious for granted)? Define "move" - So does the speed of moving has an impact? - You said left / right / what about up down? - What about moving with the keyboard? Alt-space to open the "app-icon menu", select move, and use cursor keys. Define "flicker" - I guess some form of quick switching between 2 or more visual states. - Does it affect text (only menu, or also labels, toolbars, buttons...?)   Does it affect icons?   Does it affect frame/edges - Do they disappear and then are redrawn - Do they change color, thickness(boldness), or relative location? So I did a test myself. And the below applies to the "ide main bar" and in the exact same way to "notepad" (the one that comes with Windows) and Firefox. It also happens to some text content, but not all text in the windows (depending in what kind of control the text was / or maybe font used....) Only app I could not notice it was the windows file explorer. => so this observation is not an LCL issue, but something in Windows or my setup. If I move very slowly the text in the window title-bar and in (to lesser extend) the menu-titles seem to briefly flash bold and return to normal. Though only noticeable, if I look really hard for it. Well to be exact, that happens on 2 out of 4 of my screens. It does not happen on the other ones. (at least one screen that it happens and that it doesn't share the same gfx card). Noteworthy, both of the monitors on which it happens are old (like a decade old).... No idea if that is significant. Just before posting, if the IDE main bar is split across 2 screens that have different ppi scaling, and also at the same time (due to different height of the screens) vertically partly cut off on one of the screens, then I could observe a real bad flicker in the part of the IDE bar on the other screen. And this I have not reproduced with other apps (yet). ---------------------------------------------------------------------- jamie · 2022-12-10 00:49 Its windows 10 Proc,32/64-bit Home etc.  does not matter on the bit- ness. This has been going on since I can remember. The Menu items on the bar are getting redrawn. I can see where the area is getting erased and menu items text redrawn.  I find it hard to believe that nobody in the community has never noticed this.   In one app a secondary form with a menu and a page control will flicker the menu while changing tabs. And also, when you first focus it, you will see a flashy redraw.  It's very noticeable when dragging the form around left to right.  Delphi tools has never done this, nor has other DEV tools for GUI building does this that I use. ---------------------------------------------------------------------- lainz · 2022-12-10 01:02 Do you have Double Buffered set to true for the form? ---------------------------------------------------------------------- jamie · 2022-12-10 01:08 unbelievable. ---------------------------------------------------------------------- 440bx · 2022-12-10 01:23 Quote from: jamie on December 09, 2022, 03:45:22 amApps with a Main Menu and a few items will flicker badly in some cases while moving the form around.  Seen with the IDE and many apps generated by it.  Is there some sort of redundant refresh being done? can you post a very short (as simple as possible) project that exhibits the problem ?  along with whatever steps must be followed to make the menu flicker ?  it would be very nice if you could identify in which cases the menu flickers and, at least some, in which it doesn't flicker. ---------------------------------------------------------------------- jamie · 2022-12-10 01:47 Really? The IDE itself isn't evidence enough?  I am sure someone will come around when they figure out what it is I am talking about.  Don't worry about, I'll look at the source code myself. I just thought by now that someone would have made a comment about it. I believe others have but they ended here like I am now. ---------------------------------------------------------------------- 440bx · 2022-12-10 01:58 Quote from: jamie on December 10, 2022, 02:47:48 amReally? The IDE itself isn't evidence enough? This has nothing to do with "evidence", this is not an episode of Perry Mason, Sherlock Holmes or Hercule Poirot.  Really!! A very simple project that exhibits the problem you've mentioned can be used to determine the cause of the problem and fix it, which I presume is something you should be interested in and, it is significantly simpler to pinpoint the problem in a small project than in a rather large one such as the Lazarus IDE. Post the shortest, simplest project possible that exhibits the problem and I am fairly sure I won't be the only one that will try to determine what causes it. You might even get the problem solved. ---------------------------------------------------------------------- balazsszekely · 2022-12-10 07:26 The IDE does flicker if AnchordockingDsg/DockedFormEditor is installed. Grab the IDE and move it slowly up and left. Actually it does flicker a lot. I cannot reproduce the flickering with a regular application. ---------------------------------------------------------------------- 440bx · 2022-12-10 08:26 Quote from: GetMem on December 10, 2022, 08:26:19 amThe IDE does flicker if AnchordockingDsg/DockedFormEditor is installed. Grab the IDE and move it slowly up and left. Actually it does flicker a lot. I cannot reproduce the flickering with a regular application. that gives the impression that the code responsible for the flicker is most likely in the AnchordockingDsg/DockedFormEditor component. Originally, if @Jamie had posted a simple project exhibiting the problem, I was going to use Rohitab's API spy to see what API calls may be causing it.  Since I don't use AnchordockingDsg/DockedFormEditor hopefully someone who does is interested in finding the cause of the flicker. My _guess_ is that the component messes around with the window class styles, possibly activating CS_HREDRAW and CS_VREDRAW, which are the most common reasons for abundant flicker. ---------------------------------------------------------------------- balazsszekely · 2022-12-10 08:39 @440bx Quotethat gives the impression that the code responsible for the flicker is most likely in the AnchordockingDsg/DockedFormEditor component.Yes, I agree. I found a way to reproduce it with the undocked IDE too(Lazarus trunk/Windows10). Drag the IDE down(200-300 px or so), then move it up until the mouse "touch" the upper part of the screen(Mouse.PY = 0), then make a small circle with the mouse. I know this is an extreme case, but I believe this is the kind of flickering @Jamie saw. ---------------------------------------------------------------------- 440bx · 2022-12-10 10:36 Quote from: GetMem on December 10, 2022, 09:39:50 amI found a way to reproduce it with the undocked IDE too(Lazarus trunk/Windows10). Drag the IDE down(200-300 px or so), then move it up until the mouse "touch" the upper part of the screen(Mouse.PY = 0), then make a small circle with the mouse. I know this is an extreme case, but I believe this is the kind of flickering @Jamie saw. Following those steps I was also able to reproduce it in Windows 10. Strangely, following the same steps but on Windows 7 produced no flicker at all.  I'm inclined to believe that MS changed a few "minor" details in how windows are updated in Windows 10 that cause unexpected side effects in some cases, such as menu flicker.  This is just a guess but, older programs I use work fine in Win 7 but behave strangely in Win 10, reinforce that belief. ---------------------------------------------------------------------- wp · 2022-12-10 11:22 Quote from: GetMem on December 10, 2022, 09:39:50 amI found a way to reproduce it with the undocked IDE too(Lazarus trunk/Windows10). Drag the IDE down(200-300 px or so), then move it up until the mouse "touch" the upper part of the screen(Mouse.PY = 0), then make a small circle with the mouse. I know this is an extreme case, but I believe this is the kind of flickering @Jamie saw. Without having read this I would not have noticed this kind of flicker at all. The main distraction is the Windows feature that the dragged form suddenly extends over the full screen width when the mouse touches the top of the screen. ---------------------------------------------------------------------- howardpc · 2022-12-10 11:55 Windows 11 shows the same behaviour following GetMem's steps. ---------------------------------------------------------------------- Martin_fr · 2022-12-10 14:11 It also can be seen, if the right or left half of the main-ide-bar is off screen, and the window is circled... (that gives room for a bit bigger circles) Then it happens especially when moving the window "into the screen" (reducing the off screen portion). I guess this does require repaints, because the parts that where off screen become visible and must be painted. For anyone who will go looking, this is usually an issue with "EraseBackground". Afaik (but thats a far stretch afaik), EraseBackground is needed, when you don't double buffer. Afaik, in case of a double buffer, it's the buffer that needs to be cleared (initialized with the background buffer) The other question is where the paint request originates from... And why it isn't clipped to the "newly moved in rect". As I said there had been prior issues. The bug tracker has at least a closed issue (sounding alike) for page controls or tab sheets. May be good to check what was done for that. There may also be old discussions on the mail list (not checked). ---------------------------------------------------------------------- jamie · 2022-12-10 15:16 I could be wrong here, but I believe the LCL has the menus in OWNER draw at all times and when user code elects to use OWNER draw it simply passes it to user code but in short it still is always in OWNER draw state at all times. This accounts for the act of using themes etc. But in short, it most likely does not know the difference between a Text draw and a total refresh.  Also, the LCL ignores the windows standard messages of WM_MOVING and WM_SIZING. It only uses WM_MOVE and WM_SIZE and the WM_WindowPOSChanging and Changed is always sent during all phases which of course can trigger lots of redraw events.   Maybe some how the LCL needs to ignore the EraseBkGrd message when the WM_MOVING is in the mix ?   Or simply draw the whole menu top bar to a bitmap and paint that instead? ---------------------------------------------------------------------- Hansvb · 2022-12-10 15:20 Hi, I also see the screen flicker. But I hadn't really noticed until I read this post. I use Windows 10. What I have more trouble with is that the main screen disappears behind the taskbar when you maximize the screen. Is that a known issue? ---------------------------------------------------------------------- jamie · 2022-12-10 17:21 I just did a local owner draw within a test app and directed it all to a temp Bitmap of the requested size per call and then use the Canvas.DRAW to the destination canvas and it works perfectly. There is no flickering.  So, I believe the issue is up in the Win32 code where the menus are currently being drawn instead of allowing the OS to do it. This accounts for Themes activity.  Maybe a Temp Bitmap needs to be drawn on to build the final mosaic and paint that to the surface.    I don't think much would need to be changed other than creating the bitmap and directing all the canvas work to that instead of the final one.  Free the bitmap at the end of course. ---------------------------------------------------------------------- lainz · 2022-12-10 22:58 Quote from: jamie on December 10, 2022, 02:08:06 amunbelievable. Why? I remember having flickering issues on windows and was solved enabling double buffer Edit: Tested with a fresh project with double buffered enabled and still there's flickering on the main menu, Windows 11. ---------------------------------------------------------------------- 440bx · 2022-12-10 23:12 I suspect the problem resides somewhere inside Windows 10/11 because on Win 7 there does not seem to be a way to make the menu flicker. ---------------------------------------------------------------------- jamie · 2022-12-10 23:37 If you have Delphi around, put together a simple Menu program and play with that one. You will find that it works perfectly.  I have some older apps that have menus compiled with MS tools and Delphi of course and they work.   My Windows 7 box with the I7, 12G memory and lots of HD space flickers, too. ---------------------------------------------------------------------- lainz · 2022-12-10 23:38 Quote from: 440bx on December 11, 2022, 12:12:26 amI suspect the problem resides somewhere inside Windows 10/11 because on Win 7 there does not seem to be a way to make the menu flicker. On Windows 11 there's like a black popup in top of the screen that shows where to position the form, maybe that causes the flickering... ---------------------------------------------------------------------- 440bx · 2022-12-10 23:55 Quote from: jamie on December 11, 2022, 12:37:55 amMy Windows 7 box with the I7, 12G memory and lots of HD space flickers, too. On my Win7  VM, I cannot make the menu flicker.  On the Win10 VM, it flickers plenty.  Exactly why the difference ?... no idea, other than the different version of Windows. ---------------------------------------------------------------------- balazsszekely · 2022-12-11 10:51 From Win32WSMenus.pp: 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   // draw backgound  // This is a hackish way to draw. Seems windows itself draws this in WM_PAINT or another paint handler?  AWnd := TCustomForm(AMenuItem.GetMergedParentMenu.Parent).Handle;  if (AMenuItem.MergedParent.VisibleIndexOf(AMenuItem) = 0) then  begin    /// if we are painting the first item then request full repaint to draw the bg correctly    if (GetProp(AWnd, 'LCL_MENUREDRAW') = 0) then    begin      SetProp(AWnd, 'LCL_MENUREDRAW', 1);      DrawMenuBar(AWnd);      Exit;    end    else      SetProp(AWnd, 'LCL_MENUREDRAW', 0);    // repainting menu bar bg    Info := Default(tagMENUBARINFO);    Info.cbSize := SizeOf(Info);    GetMenuBarInfo(AWnd, OBJID_MENU, 0, @Info);    GetWindowRect(AWnd, @WndRect);    OffsetRect(Info.rcBar, -WndRect.Left, -WndRect.Top);    Tmp := ThemeServices.GetElementDetails(BarState[(ItemState and ODS_INACTIVE) = 0]);    ThemeDrawElement(AHDC, Tmp, DPI, Info.rcBar, nil); ---------------------------------------------------------------------- jamie · 2022-12-11 15:26 That would explain why I couldn't get one of my Delphi apps to work properly because there I had a little status display in the menu bar and it wouldn't show using Lazarus, but I would notice once in a while I could see a glimpse of it.   I don't know why or who put that code in there like that but it's true that windows does draw its own menu bar unless you have it in Owner Draw mode.  It seems here that attempts are being made to overwrite what would possibly be there so that the LCL could use its own menu bar.  I was under the impression the LCL always creates the menu bar in owner Draw mode and simply passes it to user code if the user wants to draw it instead?  In Owner mode there is no need to attempt overwriting an existing menu bar. ---------------------------------------------------------------------- jamie · 2022-12-16 19:57 Any headway on this? ---------------------------------------------------------------------- ASBzone · 2023-04-02 20:02 Quote from: howardpc on December 10, 2022, 12:55:30 pmWindows 11 shows the same behaviour following GetMem's steps. So far, I haven't gotten my Win11 instance to replicate this with the latest FPC/Lazarus fixes 2.2.7