현재 Desktop 이름을 알고 싶을때 아래 코드를 참고하자.

GetDesktopName와 같이 함수형태로 만들어 놓으면 호출시 문자열값을 리턴한다.



Private Declare Function GetUserObjectInformation Lib "user32" _

                  Alias "GetUserObjectInformationA" _

                        (ByVal hObj As Long, _

                         ByVal nIndex As Long, _

                         pvInfo As Any, _

                         ByVal nLength As Long, _

                         lpnLengthNeeded As Long) As Long


Private Declare Function GetThreadDesktop Lib "user32" _

                        (ByVal dwThread As Long) As Long


Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long


Private Const UOI_FLAGS     As Long = 1

Private Const UOI_NAME      As Long = 2

Private Const UOI_TYPE      As Long = 3

Private Const UOI_USER_SID  As Long = 4



Private Function GetDesktopName() As String


  Dim hDesktop    As Long

  Dim sBuffer     As String

  Dim lLength     As Long

  

  hDesktop = GetThreadDesktop(GetCurrentThreadId)


  If hDesktop = 0 Then Exit Function


  GetUserObjectInformation hDesktop, UOI_NAME, ByVal vbNullString, 0&, lLength


  sBuffer = Space(lLength)


  GetUserObjectInformation hDesktop, UOI_NAME, ByVal sBuffer, lLength, lLength


  If InStr(sBuffer, Chr(0)) Then

    GetDesktopName = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)

  End If

  

End Function



'VB6 > Function' 카테고리의 다른 글

마우스커서가 위치한 윈도우 핸들 구하기  (0) 2013.03.27
대기시간 함수  (0) 2013.03.27

+ Recent posts