'获取窗口名称或控件内容
'可以远程获取其它进程的内容
Function GetWindowName(sHWnd as HWnd ) as  CWSTR   '
  Dim nSize as Long ,sSave as wString Ptr,by() as Byte
  If IsWindow(sHWnd) Then
      nSize = GetWindowTextLengthW(sHWnd)
      If nSize Then '先用本地获取
          ReDim by(nSize*2+2)
          sSave= Cast(WString ptr, @by(0) )
          GetWindowText sHWnd,sSave,nSize+1
          Function=*sSave
      Else '用远程获取  用 SendMessage 遇到被挂起的进程出问题，所以用超时的
          If SendMessageTimeoutW ( sHWnd , WM_GETTEXTLENGTH , 0 , 0 ,SMTO_ABORTIFHUNG,10,cast(any ptr, @nSize)) Then
              If nSize Then
                  ReDim by(nSize*2+2)
                  sSave=Cast(WString ptr, @by(0) )
                  SendMessageTimeoutW ( sHWnd , WM_GETTEXT ,nSize+1 ,Cast( lPARAM, sSave),SMTO_ABORTIFHUNG,10,Null )
                  Function=*sSave
              End If
          End If
      End If
  End If
End Function