현재 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

마우스커서가 현재 위치하고 있는 윈도우 핸들을 알고 싶을때 아래 코드를 참고하자.

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


GetCursorPos는 현재 마우스커서의 위치를 POINTAPI 구조체에 담아주고, WindowFromPoint 를 통해 x좌표, y좌표를 넘겨주면 해당 좌표에 핸들을 리턴한다.


Private Declare Function GetCursorPos Lib "user32" _

                        (lpPoint As POINTAPI) As Long

                        

Private Declare Function WindowFromPoint Lib "user32" _

                        (ByVal xPoint As Long, _

                         ByVal yPoint As Long) As Long

Private Type POINTAPI

        x As Long

        y As Long

End Type


Private Function PointToHandle() As Long

  Dim pt        As POINTAPI

  GetCursorPos pt

  PointToHandle = WindowFromPoint(pt.x, pt.y)

End Function


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

Desktop 이름 구하기  (0) 2013.04.01
대기시간 함수  (0) 2013.03.27

대기시간을 주고자 할때 아래 코드를 참고하자.

Delay 와 같이 함수형태로 만들어 놓고 1/1000초 단위로 인자값을 넘겨주면 된다.


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

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Private Sub Delay (Optional ByVal lDelayTime As Long = 100)

  On Error Resume Next

  lDelayTime = GetTickCount + lDelayTime

  Do Until GetTickCount > lDelayTime

    Sleep 1

    DoEvents

  Loop

End Sub

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

Desktop 이름 구하기  (0) 2013.04.01
마우스커서가 위치한 윈도우 핸들 구하기  (0) 2013.03.27

+ Recent posts