No announcement yet.

Why desktop icons flicker

  • Filter
  • Time
  • Show
Clear All
new posts

  • Why desktop icons flicker

    When a PowerBASIC app I wrote starts, all of the icons on the desktop flicker. The same thing happens when I start it on my wife's PC. I can't say that I noticed it before - at some point I seem to have added something to cause it.

    My simpler PowerBASIC apps don't exhibit the problem.

    I've done some looking but haven't found any good leads.

    Is there known PowerBASIC code that is likely to do this?

    My app is a somewhat long or I'd post it here - so I'm just looking for some possibly well-known "gotcha" before I start piecemeal disabling sections of the program to help figure out where the effect is coming from.

  • #2
    Had trouble setting time and needed to use broadcast.
    User to user discussions about the PB/Win (formerly PB/DLL) product line. Discussion topics include PowerBASIC Forms, PowerGEN and PowerTree for Windows.


    • #3
      Hi Mike,

      In my case, I'm simply creating equates, controls and displaying the dialog. There's also some initializing code, but nothing that seems to be system-wide in nature.

      But - I'll take a closer look with your experience in mind. Thanks for the comment.

      As a test, I've since deleted everything stating with the code in %WM_INIT and the flickering was still there.

      If I can get it down to a minimal code, I'll post it here.


      • #4
        Might try putting a global like gcounter in the paint and resize events and see if the code might be executing multiple times at startup by checking gcounter after the dialog is created.


        • #5
          Gary, my main app does that on WinME the first time you go to desktop and call it up. If you then close it and call it up again, the icon flicker does not seem to happen.

          On Vista, didnt notice any flicker at all with the same app. It's a faster computer, of course.

          I hadn't really noticed the flicker until you mentioned it.

          I do get the client area in the program and the dialog is based on that to try to make the initial dialog the same percentage of the screen on different resolutions.
          Last edited by Fred Buffington; 10 May 2009, 12:51 AM.
          Client Writeup for the CPA

          Links Page


          • #6

            In my case, I have no paint code.

            I tested setting my WM_Size code to "Exit Sub", and the flicker still happens.

            I guess I'll need to walk through the startup code line by line, disabling until I find what's causing it.

            Thanks for your comments.


            • #7
              Hi Fred,

              My flicker is rock solid - every time, no matter how many times I try it.

              Since it happens on my wife's PC too (both have XP), I'm assuming the slow approach (disable code till I find the offending lines) will work.

              I'll try it out.

              Thanks, too, for your comment.


              • #8
                You are using somewhere in your code a null DC, causing the invalidation of the desktop (NULL DC = Desktop).

                Patrice Terrier
                Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).


                • #9
                  Yes, I feel Patrice is right.

                  OS desktop has its own window handler: zero. Check inside WIN32API.INC you will find:
                  %HWND_DESKTOP   = 0
                  So if you are sending a DIALOG REDRAW ... command to zero window handler you are sending the command to the desktop. The same if you are using a null DC.

                  Check your handlers before using them and see if any of them is null.


                  • #10
                    Thanks Patrice/Eros,

                    You've given me something to look for.

                    I've only used Redraw with hDlg, but I commented them out just for grins - no change.

                    I'll have to work through all the startup lines to see if I can find an API or DDT command that fit the description. I don't recall using any command that needed a DC, but since the screen is definitely blinking I've certainly done something.

                    Thanks for the advice and I'll let you know if I find the offending line(s) of code!


                    • #11
                      Does this flash?
                      Using DDT? What does the DIALOG NEW statement look like?
                      Any functions exiting with FUNCTION = 0 that should be 1?
                      Just fishing.

                      #PBFORMS CREATED V1.51
                      #COMPILE EXE
                      #DIM ALL
                      '   ** Includes **
                      #PBFORMS BEGIN INCLUDES 
                      #IF NOT %DEF(%WINAPI)
                          #INCLUDE "WIN32API.INC"
                      #PBFORMS END INCLUDES
                      '   ** Constants **
                      #PBFORMS BEGIN CONSTANTS 
                      %IDD_DIALOG1 =  101
                      %IDC_BUTTON1 = 1001
                      #PBFORMS END CONSTANTS
                      '   ** Declarations **
                      DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                      DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                      #PBFORMS DECLARATIONS
                      '   ** Main Application Entry Point **
                      FUNCTION PBMAIN()
                          ShowDIALOG1 %HWND_DESKTOP
                      END FUNCTION
                      '   ** CallBacks **
                      CALLBACK FUNCTION ShowDIALOG1Proc()
                          LOCAL s AS STRING
                          SELECT CASE AS LONG CBMSG
                              CASE %WM_INITDIALOG
                                  ' Initialization handler
                              CASE %WM_NCACTIVATE
                                  STATIC hWndSaveFocus AS DWORD
                                  IF ISFALSE CBWPARAM THEN
                                      ' Save control focus
                                      hWndSaveFocus = GetFocus()
                                  ELSEIF hWndSaveFocus THEN
                                      ' Restore control focus
                                      hWndSaveFocus = 0
                                  END IF
                              CASE %WM_COMMAND
                                  ' Process control notifications
                                  SELECT CASE AS LONG CBCTL
                                      CASE %IDC_BUTTON1
                                          IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                             'DIALOG REDRAW 0      'flash
                                             DIALOG REDRAW CBHNDL
                                          END IF
                                  END SELECT
                          END SELECT
                      END FUNCTION
                      '   ** Dialogs **
                      FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                          LOCAL lRslt AS LONG
                      #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
                          LOCAL hDlg  AS DWORD
                          DIALOG NEW PIXELS, hParent, "Written in PowerBASIC by Gary Beene", 300, _
                              300, 410, 340, %WS_OVERLAPPEDWINDOW OR %WS_CLIPCHILDREN OR _
                              %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
                              %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR _
                              %WS_EX_CONTROLPARENT, TO hDlg
                          CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Test CBHNDL", 160, 152, 82, 24
                      #PBFORMS END DIALOG
                          DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                      #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
                      #PBFORMS END CLEANUP
                          FUNCTION = lRslt
                      END FUNCTION
                      Last edited by Mike Doty; 11 May 2009, 02:31 PM. Reason: Matching DIALOG NEW


                      • #12
                        Hi Mike,

                        No, the code you sent does NOT cause the icons to flicker.

                        Here's my Dialog New line.

                        Dialog New Pixels, 0, "Written in PowerBASIC by Gary Beene",300,300,410,340, %WS_OverlappedWindow Or %WS_ClipChildren To hDlg
                        I haven't done more tests (Mother's Day party - can you imagine?), but I'll be working on it this evening.

                        Thanks for your persistence.


                        • #13
                          Add to Mike's example the following code in Dialog Callback and you will see desktop icons flickering:
                                  Case %WM_SIZE
                                    Dialog ReDraw %Null
                          That is one of the many possible reasons mentioned by what Patrice.

                          Also this can do the job:
                                  Case %WM_SIZE
                                    InvalidateRect 0&, ByVal 0&, 0&
                          Last edited by Eros Olmi; 11 May 2009, 01:49 AM.


                          • #14
                            Hi Eros,

                            I have a few
                            Dialog Redraw hDlg
                            statements, but none with %NULL

                            I also have one statement of
                              InvalidateRect hTextBox, ByVal %NULL, 0 : UpdateWindow hTextBox
                            but I commented it out and flickering still occurred.


                            • #15
                              Yes, of course you will not have exactly
                              Dialog Redraw %NULL
                              InvalidateRect 0&, ...
                              but check that "hDlg" and/or "hTextBox" (or other pirce of code) are not null (for some reasons) at some point of your program execution.

                              Without having the sources one can just guess



                              • #16

                                I got side-tracked near the end of this post and only today revisited the responses y'all gave me.

                                The problem is solved.

                                In my startup code, I had used handles that had been dimensioned, but had no assigned values - pretty much like you had suggested was the case. I moved the offending code to later in the startup cycle and all was well.

                                I can make it flicker, or stop, on demand now.

                                Thanks again for the help!


                                • #17
                                  New PB statement...

                                  #FLICKER OFF


                                  • #18
                                    For those tough days...

                                    # OFF
                                    Michael Mattias
                                    Tal Systems (retired)
                                    Port Washington WI USA
                                    [email protected]