Results 1 to 5 of 5

Thread: Windows10: Is the window under Mouse Cursor = Desktop?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2016
    Posts
    80

    Windows10: Is the window under Mouse Cursor = Desktop?

    Hi,
    I'm using Win10. I have two Virtual Desktops open.
    In Win10 I can switch between the two desktops with (Ctrl + Win + rightArrow) and (Ctrl + Win + leftArrow)

    I want to check if the window under the mouse cursor is the
    DesktopWindow. -Unfortunely the following Code does not work, because
    the WindowFromPoint function returns: 65852
    and the GetDesktopWindow function returns 65552
    (The two values do not match). How can I fix this ?

    Code:
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    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
        Dim Pt As POINTAPI
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    
    Private Sub Form_Load()
        Timer1.Interval = 999
        Form1.AutoRedraw = True
        Move 0, 0
    End Sub
    
    Private Sub Timer1_Timer()
        GetCursorPos Pt
        If CurrentY > 2500 Then Cls: CurrentY = 0
        Print WindowFromPoint(Pt.x, Pt.y) & Space(11) & GetDesktopWindow & Space(11) & Time
    End Sub
    Last edited by vb_elmar; Jan 16th, 2020 at 11:10 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Sep 2016
    Posts
    80

    Re: Windows10: Is the window under Mouse Cursor = Desktop?

    any idea?

  3. #3
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: Windows10: Is the window under Mouse Cursor = Desktop?

    I suspect your getting the handle to a listview thats on the desktop (SysListView32). You can check this by using a tool called Spy++ (And if i'm correct that was aready there in vb6)
    Any way if so, you will have to track down the parent of it to find the desktop handle.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  4. #4
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Windows10: Is the window under Mouse Cursor = Desktop?

    what about GetParent?

  5. #5
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Windows10: Is the window under Mouse Cursor = Desktop?

    There is a new shell interface in Windows 10 called IVirtualDesktopManager. It provides helpful methods like "GetWindowDesktopId" and "IsWindowOnCurrentVirtualDesktop".

    I first read about it here, where there's a nice C# walkthrough. Someone would need to hack together a TLB to make it easily usable in VB. (Unfortunately, I don't know of any API fallbacks that provide the same feature, at least not in the current Windows 10 builds.)
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width