Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Get Current Desktop Name

Get Current Desktop Name

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MohammadAmiry
    wrote on last edited by
    #1

    Hi, I need to know the name od the current windows desktop in vb6. I use the following code. l which is the lenght of the string of desktop name, is filled but, the strig s would not be filled. I would like to ask why this happens, and if there are any other methods to get current desktop name?

    Option Explicit
    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_NAME        As Long = 2
    
    Private Function GetCurrentDesktopName() As String
        Dim s As String, l As Long
        Const MAX As Long = 500
        s = String(65355, vbNullChar)
        If GetUserObjectInformation(GetThreadDesktop(GetCurrentThreadId), UOI_NAME, VarPtr(s), MAX) Then
            GetCurrentDesktopName = Left(s, l - 1)
        End If
    End Function
    
    Private Sub Command1_Click()
        MsgBox GetCurrentDesktopName
    End Sub
    
    P 1 Reply Last reply
    0
    • M MohammadAmiry

      Hi, I need to know the name od the current windows desktop in vb6. I use the following code. l which is the lenght of the string of desktop name, is filled but, the strig s would not be filled. I would like to ask why this happens, and if there are any other methods to get current desktop name?

      Option Explicit
      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_NAME        As Long = 2
      
      Private Function GetCurrentDesktopName() As String
          Dim s As String, l As Long
          Const MAX As Long = 500
          s = String(65355, vbNullChar)
          If GetUserObjectInformation(GetThreadDesktop(GetCurrentThreadId), UOI_NAME, VarPtr(s), MAX) Then
              GetCurrentDesktopName = Left(s, l - 1)
          End If
      End Function
      
      Private Sub Command1_Click()
          MsgBox GetCurrentDesktopName
      End Sub
      
      P Offline
      P Offline
      progload
      wrote on last edited by
      #2

      The 'default' desktop has No Name...and returns an empty string. See this article and the source code, there is a sample project also: http://www.vbaccelerator.com/home/vb/code/Libraries/Windows/Creating_New_Desktops/article.asp[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups