I’ve been trying to reduce windows flicker.
One option I am exploring is to set the window backdrop to be a screenshot of the window at key points, such as on deactivate or when changing view styles and the like.
(I’ve had to revert to Xojo 2015 again after a disasterous attempt to use a Direct2D Xojo)
My code can use two methods:
Either an API call
Dim screenCap As Picture = New Picture(self.Width, self.Height,32)
Dim HWND As Integer
hwnd = self.handle
Dim SourceDC As Integer = GetDC(HWND)
Dim DestDC As Integer = screenCap.Graphics.Handle(screenCap.Graphics.HandleTypeHDC)
Call BitBlt(DestDC, 0, 0, self.Width, self.Height, SourceDC, 0,0, SRCCOPY Or CAPTUREBLT)
Call ReleaseDC(HWND, SourceDC)
or
self.ScreenshotWindowMBS
The API call actually causes the screen to flash while it happens.
I had high hopes of the MBS call, but it always gives me nil
I’ve tried a few sets of plugin versions, the current set I use is dated 2020
Before I spend hours changing the plugins and hoping that those don’t introduce unexpected side effects:
Does self.ScreenshotWindowMBS work for anyone else?
Thanks Christian… I just discovered ScreenshotRectMBS myself.
Sadly, .scalefactor is absent in Xojo 2015, so I get an image that contains (probably) 1/4 of the picture I really want, at the size that I do.
And of course we would appreciate if you could update MBS Plugins to a current one.
If I look right, your license is good for current release, which should work for Xojo 2015 on Windows.
I’ll investigate that, thank you.
My license is good for current - but I’m always wary of changing something that I know works…
(I use the current set for my iOS work)
Sadly, I was hoping that there would be a distinction between LogPixelsX and WidthDPI
but WidthDPI and HeightDPI don’t return anything useful.
I know that asking for something the ‘same size’ as my window, gets me the right number of pixels, but not the entire window. It must be scale factor/retina, something.
If I could work out by how much (reliably, not just on my machine), I could swing it.
Any time the screen is activated, or restored from minimised, the whole window goes briefly white, then my controls appear
They are all set to EraseBackground = false, and shouldn’t do that.
The white is ‘empty window’, and one solution would be setting a backdrop from a screenshot.
(But oddly, taking a screenshot with the API solution, itself, causes a brief flash like taking a photo.
So pointless)
If it were a small project, I probably wouldn’t have the problem.
The main screen is pretty much covered edge to edge with a variety of controls… listboxes, various scrollbars, several (non overlapping) canvases…
I guess I will just buckle down and live with it. After all, I have reluctantly done so for many years.
That is correct as you have prevented all background painting from occurring by consuming the event. In one of our windows we just fill the relevant areas.
Another technique is to use the Win32 SetWindowLong API to enable WS_CLIPCHILDREN on the parent (window). This excludes the areas occupied by controls when a redraw is triggered. However, you are then responsible for triggering a redraw of the controls yourself via the Xojo Paint event on the window.