
 ////////////
 //
FUNCTION ApiLoadDll_(cDll)
 //      Returns the <cDll> handle or 0
 //
 /////
STATIC aDllLoaded := {}                  // Loaded Dlls: {{Lower(cDll), nDllHandle}, ...}
LOCAL  nDllHandle

cDll := Lower(AllTrim(cDll))
if Right(cDll, 4) <> '.dll'
   cDll           += '.dll'
endif

nDllHandle    := AScan(aDllLoaded, {|x| x[01] == cDll})
if nDllHandle  > 0
   nDllHandle := aDllLoaded[nDllHandle, 02]
else
   nDllHandle := DllLoad(cDll)
   AAdd(aDllLoaded, {cDll, nDllHandle})
endif
RETURN nDllHandle


                  //
                  //    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

 ////////////
 //
FUNCTION ApiInvalidateDesktopRect_(nHWND, nLeft,nTop, nBottom,nRight)
 //      Returns .t. if the area was redrawn
 /////
STATIC  cInvalidate, cUpdate, cRedraw
LOCAL  nDll, cRect, lOk

if cInvalidate == NIL
   nDll        := ApiLoadDll_('User32.dll')
                 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd183326(v=vs.85).aspx
   cInvalidate := DllPrepareCall(nDll, DLL_STDCALL, 'InvalidateRect')
                 // https://msdn.microsoft.com/pt-br/library/windows/desktop/dd145167(v=vs.85).aspx
   cUpdate     := DllPrepareCall(nDll, DLL_STDCALL, 'UpdateWindow')
                 // https://msdn.microsoft.com/pt-br/library/windows/desktop/dd162911(v=vs.85).aspx
   cRedraw     := DllPrepareCall(nDll, DLL_STDCALL, 'RedrawWindow')
endif
cRect := (L2Bin(nLeft)    +;
          L2Bin(nTop)     +;
          L2Bin(nBottom)  +;
          L2Bin(nRight))
lOk   := (DllExecuteCall(cInvalidate, nHWND,;
                                      cRect,;
                                      1) <> 0)
if lOk
   lOk := (DllExecuteCall(cUpdate, nHWND) <> 0)
endif

if lOk
   lOk := (DllExecuteCall(cRedraw, nHWND, cRect,;
                                          0,;
                                          RDW_INVALIDATE) <> 0)
   if lOk
      lOk := (DllExecuteCall(cRedraw, nHWND, cRect,;
                                             0,;
                                             (RDW_VALIDATE    +;
                                              RDW_UPDATENOW   +;
                                              RDW_ALLCHILDREN)) <> 0)
   endif
   if lOk
      lOk := (DllExecuteCall(cRedraw, nHWND, cRect,;
                                             0,;
                                             (RDW_UPDATENOW   +;
                                              RDW_ALLCHILDREN)) <> 0)
   endif
endif
RETURN lOk