In the project I am working on, there is a few buttons acting as menus and submenus. So, when I click on one menu item, the submenus will be updated to reflect the selection. At that point the software will display text from a database. Now when I move from one menu to the next, I have to update all the menus and selection. Unfortunately, I see some flickering where the items just flash for a fraction of a second but it is still annoying… Is there a way to freeze the refresh and update the screen when I am done?
I am using Labels and rectangles.
here’s what I use for win32. h is window.handle
[code]Private Sub SetRedraw(h as integer,RedrawOn As boolean)
dim WM_SETREDRAW As Int32 = &HB
Soft Declare Function SendMessageA Lib “user32” Alias “SendMessageA” ( hwnd As int32, wMsg As int32, ByVal wParam As boolean, lParam As int32) As int32
Soft Declare Function SendMessageW Lib “user32” Alias “SendMessageW” ( hwnd As int32, wMsg As int32, ByVal wParam As boolean, lParam As int32) As int32
if System.IsFunctionAvailable(“SendMessageA”,“user32”) then
dim ok as integer=sendmessageA(h,WM_SETREDRAW,RedrawOn,0)
dim ok as integer=sendmessageW(h,WM_SETREDRAW,RedrawOn,0)
Thanks, being an amateur programmer, it seems a little complicated but I will try to learn from it.
Ooops, forgot to tell you how to use it!
Just add the above method to a module or the window and call SetRedraw(self.handle,false) to stop the window from drawing and SetRedraw(self.handle,true) to resume drawing.
How is that any different from using the INVALIDATE function?
Invalidate sets an area, control or window as needing to be redrawn. The above will prevent redrawing in a window. So for example, you have several items that need to be updated and each time you change the text of a label, other controls are redrawn (this also depends on your layout and other factors). This can lead to all of the controls flickering. If you stop redraws, change the text of all of the labels needing changes, and then restart redraws, you can then call invalidate once and hopefully eliminate the flickering or at least reduce it to a less annoying level. I’m only talking about Windows apps here. Another thing to look for is checking that none of your controls overlap other controls.
Interested, I just tried this out, wrapping all the code in my redraw stuff up.
I found that some static texts on the window simply didn’t appear afterwards.
But if I apply the principle to individual controls, especially while filling list boxes, the flickering (which Id already done a lot to counter over the years) is definitely reduced.