Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Are on form not refreshing properly
Message
De
07/12/2020 10:28:24
 
 
À
07/08/2020 19:01:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
01675612
Message ID:
01677462
Vues:
128
Hi all,

Thought I would follow up with my solution for this problem in case anyone else runs into it.

Solution A:
- loop through the newly added controls that are below the "fold" of the window (it is a scrollable window) and Setfocus() to each one momentarily. Then I put the focus back where I really want it to be. The newly added objects are all in a container (which is my "lastblock" below):
FOR EACH loObject IN loLastBlock.Objects FOXOBJECT

   IF PEMSTATUS(loObject,"SetFocus",5) = .T.
       loObject.SetFocus()
       loObject.Refresh()
   ENDIF

ENDFOR
That actually worked. It seems as though VFP is "lazy" at refreshing objects that are off screen even if in a scrollable window.

Solution B:
- but then I ran into another problem and in this case, I was going to need to refresh a lot more controls and it just seemed like it was going to be pretty "intense" to .SetFocus() to all of them. So digging around in the framework (VMP), I found the framework actually has a method that calls an Win API function to force a window redraw. Here it is below including their comments so you can see this is not particular to my code:
*  X7RedrawWindow.PRG
*  Wrapper for the RedrawWindow() API function, this
*  routine IMMEDIATELY repaints the passed form
*  or _Screen -- at times, VFP can take its good 
*  sweet time refreshing/repainting a form
*
*  Copyright (c) 2004-2005 Visionpace   All Rights Reserved
*                17501 East 40 Hwy., Suite 218
*                Independence, MO 64055
*                816-350-7900 
*                http://www.visionpace.com
*                http://vmpdiscussion.visionpace.com
*  Author:  Drew Speedie
*           Special thanks to Peter Crabtree
*  
*  lParameters
*   toForm (R) Object reference to a specific form or _Screen,
*                to be redrawn/repainted 
*
LPARAMETERS toForm

IF PCOUNT() = 0 ;
     OR NOT VARTYPE(m.toForm) = "O" ;
     OR NOT PEMSTATUS(m.toForm,"hWnd",5) 
  RETURN .f.
ENDIF

LOCAL lnHWnd, loException
DO CASE
  CASE (m.toForm = _VFP OR m.toForm = _Screen) ;
       AND NOT _Screen.Visible
    RETURN .f.       
  CASE m.toForm = _VFP
    lnHWnd = _Screen.HWnd
  CASE m.toForm = _Screen
    lnHWnd = _Screen.HWnd
  CASE NOT UPPER(toForm.BaseClass) == "FORM"
    *  probably ActiveX control, which has an hWnd
    RETURN .f.
  OTHERWISE
    lnHWnd = toForm.hWnd
ENDCASE

*
* RedrawWindow() flags
*
#DEFINE RDW_INVALIDATE          0x0001
#DEFINE RDW_INTERNALPAINT       0x0002
#DEFINE RDW_ERASE               0x0004
 
#DEFINE RDW_VALIDATE            0x0008
#DEFINE RDW_NOINTERNALPAINT     0x0010
#DEFINE RDW_NOERASE             0x0020
 
#DEFINE RDW_NOCHILDREN          0x0040
#DEFINE RDW_ALLCHILDREN         0x0080
 
#DEFINE RDW_UPDATENOW           0x0100
#DEFINE RDW_ERASENOW            0x0200
 
#DEFINE RDW_FRAME               0x0400
#DEFINE RDW_NOFRAME             0x0800
 
IF NOT X7ISAPIF("RedrawWindow")
*!*  BOOL RedrawWindow( 
*!*   HWND hWnd, // handle to window 
*!*   CONST RECT *lprcUpdate, // update rectangle 
*!*   HRGN hrgnUpdate, // handle to update region 
*!*   UINT flags // array of redraw flags 
*!*   )
  TRY
  DECLARE INTEGER RedrawWindow IN WIN32API ;
    INTEGER hWnd, ;
    INTEGER nUpdateRect, ;
    INTEGER nUpdateRegion, ;
    INTEGER nFlags 
  CATCH TO loException
  ENDTRY
ENDIF

IF NOT VARTYPE(m.loException) = "O"
  TRY
  RedrawWindow(m.lnHWnd, 0, 0, RDW_INTERNALPAINT + RDW_UPDATENOW)
  CATCH TO loException
  ENDTRY
ENDIF
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform