Announcement

Collapse
No announcement yet.

Desktop Trapping

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Desktop Trapping

    I'm responsible for developing an application that needs to be able to distinguish what icon the mouse is over on the desktop.

    Some ideas I've had was:

    1) trapping the tooltips that loads when you hover over an icon

    2) subclassing the desktop and somehow detect what icon is currently being hovered


    These two ideas I don't know if they will work but if they will, how do I start? Any ideas would be greatly appreciated.

    Thanks,

    Greg Engle

    -------------
    -Greg
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

  • #2
    It is possible to get the handle to a window or control that is under the cursor by using the WindowFromPoint() or ChildWindowFromPoint() API's. I do not know if this will work with icons on the desktop though (I've never needed to find this out).

    The easiest way to use this function is to use a timer (SetTimer() API). When the timer event fires (%WM_TIMER), Get the cursor position (GetCursorPos()) and call WindowFromPoint() or ChildWindowFromPoint() API to get the handle of the target Window/Control.

    From there you should be able to query the parent of the window (if applicable) by using GetParent(hWnd) and go from there... you may also need to query the window class using GetClassLong() to verify the type of window that is under the cursor position.

    Another technique could be to use a system-wide hook and intercept messages. This is not my area of expertise so maybe someone else here can provide more information for you on this idea.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      > I do not know if [WindowFromPoint or ChildWindowFromPoint]
      > will work with icons on the desktop

      Nope. At least not on NT.

      -- Eric

      ------------------
      Perfect Sync: Perfect Sync Development Tools
      Email: mailto:[email protected][email protected]</A>

      "Not my circus, not my monkeys."

      Comment


      • #4
        Lance,

        I tried seeing if I could get messages with icons on the desktop and no I can't. I tried it with a simple API spy utility.

        You also said I could trap the messages on the desktop?

        Thanks

        ------------------
        -Greg
        -Greg
        [email protected]
        MCP,MCSA,MCSE,MCSD

        Comment


        • #5
          The desktop window is a ListView control, so maybe a hook or subclass somewhere may help you?

          BTW. I'd also like to know how it is done, but I'm too busy at the moment

          Regards,

          ------------------
          Kev G Peel
          KGP Software
          Bridgwater, UK.
          mailto:[email protected][email protected]</A>

          [This message has been edited by K Peel (edited May 05, 2000).]

          Comment


          • #6
            I would start by looking at SetWindowsHookEx() with the %WH_MOUSE flag. This would need to be implemented in a DLL.

            You may find some relevant code on the BBS if you search for "setwindowshook", but as I said: you'll need to find someone with more experience than I can offer on this subject.

            It may also be worthwhile looking in MSDN for ideas... http://msdn.microsoft.com

            Also try:
            http://msdn.microsoft.com/library/te...dn_hooks32.htm

            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment


            • #7
              Thanks or all your info lance I really appreciate it.

              ------------------
              -Greg
              -Greg
              [email protected]
              MCP,MCSA,MCSE,MCSD

              Comment


              • #8
                What you are trying to do is not difficult. As Kev pointed out the desktop
                is just a listview control. The control has a number of messages that allow you to
                obtain information about the items in its client area. You do not need a
                hook. If you do not have a msdn cd check out the msdn library for a detailed
                description of the listview control.

                ------------------
                Dominic Mitchell
                Phoenix Visual Designer
                http://www.phnxthunder.com

                Comment


                • #9
                  So I gather that you are suggesting some sort of enumeration of the desktop's listview control, which you use to determine if the cursor is over a desktop icon and reach accordingly.

                  That sounds like a good idea, as long as the enumeration is done dynamically or any change of the desktop layout, arrangement or visibility would make the whole thing unreliable. For example, if the taskbar size alters or icons are rearranged, then the "enumeration" process would need to be redone.

                  As an experiment, I enumerated the the child windows of the desktop window, and there can be a large number of SYSLISTVIEW32 controls running (esp if IE is running). The actual desktop listview does not appear to return any "text", whereas most of the others return "TASK" or "EXPLORER", etc. Does anyone know of a way to be 100% sure which listview control is the correct one with out manually counting the desktop icons, and comparing that to the ListView_GetItemCount value?

                  At this point I tried to get the text from each of the items within the listview, but I've become very good at causing EXPLORER (the task bar) to GPF and restart itself.

                  If anyone is interested, I'll post the code I quickly threw together (it's not pretty!) but it may be enough to get Gregery started with this project.


                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    Lance,

                    I would greatly appreciate the code that you have whipped up, it will enlighten me on what road I should take.

                    Thank you

                    ------------------
                    -Greg
                    -Greg
                    [email protected]
                    MCP,MCSA,MCSE,MCSD

                    Comment


                    • #11
                      Code:
                      ' no warranty implied - use at your own risk.
                      #COMPILE EXE
                      #INCLUDE "COMMCTRL.INC"
                        
                      GLOBAL b$
                        
                      FUNCTION ENCW(BYVAL hWnd AS LONG, BYVAL lParam AS LONG) AS LONG
                          DIM a AS ASCIIZ * 64, lCount AS LONG, x AS LONG
                          GetClassName hWnd, a, SIZEOF(a)
                          a = UCASE$(a)
                          IF INSTR(a, "SYSLISTVIEW32") THEN
                              GetWindowText hWnd, a, SIZEOF(a)
                              IF LEN(a) THEN
                                  EXIT IF
                              ELSE
                                  b$ = b$ + a + STR$(hWnd) + " "
                                  lCount = ListView_GetItemCount(hWnd)
                                  b$ = b$ + STR$(lCount) + " ("
                                  b$ = b$ + FORMAT$(ListView_GetTopIndex(hWnd)) + ")"
                                  FOR x = 0 TO lCount - 1
                      '                 ListView_GetItemText hWnd, x, 0, a, SIZEOF(a)
                                      IF LEN(a) THEN b$ = b$ + a + "," 
                                  NEXT x
                                  b$ = b$ + $CR
                              END IF
                          END IF
                          FUNCTION = 1
                      END FUNCTION
                        
                      FUNCTION PBMAIN
                          DIM hWnd AS LONG
                          hWnd = GetDesktopWindow()
                          EnumChildWindows hWnd, CODEPTR(ENCW), 0
                          MSGBOX "Enumerate Desktop results:" & $CR & b$
                      END FUNCTION
                      ------------------
                      Lance
                      PowerBASIC Support
                      mailto:[email protected][email protected]</A>
                      Lance
                      mailto:[email protected]

                      Comment


                      • #12
                        Final suggestion - see Source code, global hook, sample #2

                        [This message has been edited by Semen Matusovski (edited May 07, 2000).]

                        Comment


                        • #13
                          The issue of interprocess addressing could be solved by the use of a system-wide hook, implemented as a DLL - an instance of the DLL would be loaded into the address space of each process as it becomes hooked.

                          As I said, this is not my area of expertise, but it is an interesting project... if anyone solves this, I'd be keen to see the result (and the code!).

                          ------------------
                          Lance
                          PowerBASIC Support
                          mailto:[email protected][email protected]</A>
                          Lance
                          mailto:[email protected]

                          Comment


                          • #14
                            I've tried both the sample code, and I have also tried messing around with SPY++ from Visual Studio and it seems that I never get a message that pertains to the icon name. Do you guys think it is possible to match the x,y with some value in the registry to get the location of the icons on the screen?

                            Basically this is the deal:

                            I want to move the mouse over an icon on the desktop and the program will determine if it is a folder or a program (easy)

                            If it is a folder then it will run some special code (top secret <grin&gt

                            thats it, it seems like a very easy idea, but its starting to seem like its not even worth the time to do it. Basically if there is someway to get a list of all the icons (and names)on the desktop and the x,y cordinates of them then I could probably accomplish this task, any other ideas would be appreciated

                            Thanks

                            ------------------
                            -Greg
                            -Greg
                            [email protected]
                            MCP,MCSA,MCSE,MCSD

                            Comment


                            • #15
                              Making a dummy ComCtl32.Dll is really work that I think would take too long and wouldn't solve what I'm really looking for, anyways how would I get a list of all the functions in the ComCtl32.Dll?

                              ------------------
                              -Greg
                              -Greg
                              [email protected]
                              MCP,MCSA,MCSE,MCSD

                              Comment


                              • #16
                                > how would I get a list of all the
                                > functions in the ComCtl32.Dll?

                                You can see a list of the exported functions in any DLL by using Windows Explorer to find the file, right-clicking on it, and selecting "Quick View". The section of the display called Import Table will show you all of the "dependencies", i.e the DLLs that the DLL uses, and the section called Export Table will show you the functions that are available for your program to call. But it won't show you the required parameters, and using incorrect parameters will usually cause a GPF.

                                -- Eric


                                ------------------
                                Perfect Sync: Perfect Sync Development Tools
                                Email: mailto:[email protected][email protected]</A>

                                "Not my circus, not my monkeys."

                                Comment


                                • #17
                                  Eric,

                                  Ya that is what I figured. Do you know of any other way of getting the x,y and icon names for a listview control?

                                  ------------------
                                  -Greg
                                  -Greg
                                  [email protected]
                                  MCP,MCSA,MCSE,MCSD

                                  Comment


                                  • #18
                                    I have to admit I was a bit hasty when I said this problem is not too difficult.
                                    It actually requires very advanced programming techniques to solve. You will need
                                    to inject a dll into the address space of Explorer.exe via a WH_GETMESSAGE hook to
                                    to monitor the LVM_HITTEST and LVM_GETITEM messages.
                                    See chapter 18(Breaking Through Process Boundary Walls) in Advanced Windows by Jeffrey
                                    Richter for the solution of a problem that is very similar to yours.
                                    One of these days when I find some time I will get around to writing the DLL.

                                    ------------------


                                    [This message has been edited by Dominic Mitchell (edited May 06, 2000).]
                                    Dominic Mitchell
                                    Phoenix Visual Designer
                                    http://www.phnxthunder.com

                                    Comment


                                    • #19
                                      Greg --
                                      See global hook, sample #2 in Source code forum

                                      [This message has been edited by Semen Matusovski (edited May 07, 2000).]

                                      Comment


                                      • #20
                                        All the info about items on the desktop are in the registry under this key, (But use the current_user hive)
                                        [HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\DESKTOP]
                                        "ViewView2"=hex:INFO IS HERE

                                        Will take a hex editor, and some hacking but it is obtainable.
                                        Good luck,

                                        Brad


                                        ------------------
                                        Thanks,

                                        Bradley Callis

                                        Comment

                                        Working...
                                        X