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. C#
  4. Subclassing The Desktop

Subclassing The Desktop

Scheduled Pinned Locked Moved C#
question
14 Posts 6 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.
  • N Offline
    N Offline
    Nicholas Cardi
    wrote on last edited by
    #1

    Has anyone been sucessful in subclassing the desktop on Windows 2k. I have been trying this private void Form1_Load(object sender, System.EventArgs e) { DskPaint = new Subclass(GetDesktopWindow()); } public class Subclass : System.Windows.Forms.NativeWindow { private const int WM_PAINT = 0x000F; public Subclass(IntPtr handle) { //base.AssignHandle(handle); AssignHandle(handle); } protected override void WndProc(ref Message m) { MessageBox.Show("Meesage"); switch(m.Msg) { case WM_PAINT: MessageBox.Show("Paint Called"); break; default: base.WndProc(ref m); break; } } } The WndProc never gets hit? Any ideas? Thanks Forever Developing

    J 1 Reply Last reply
    0
    • N Nicholas Cardi

      Has anyone been sucessful in subclassing the desktop on Windows 2k. I have been trying this private void Form1_Load(object sender, System.EventArgs e) { DskPaint = new Subclass(GetDesktopWindow()); } public class Subclass : System.Windows.Forms.NativeWindow { private const int WM_PAINT = 0x000F; public Subclass(IntPtr handle) { //base.AssignHandle(handle); AssignHandle(handle); } protected override void WndProc(ref Message m) { MessageBox.Show("Meesage"); switch(m.Msg) { case WM_PAINT: MessageBox.Show("Paint Called"); break; default: base.WndProc(ref m); break; } } } The WndProc never gets hit? Any ideas? Thanks Forever Developing

      J Offline
      J Offline
      J Dunlap
      wrote on last edited by
      #2

      Simple - the desktop is not in your process space, so you can't subclass it.

      "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
      "You must be the change you wish to see in the world." - Mahatma Gandhi

      N 1 Reply Last reply
      0
      • J J Dunlap

        Simple - the desktop is not in your process space, so you can't subclass it.

        "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
        "You must be the change you wish to see in the world." - Mahatma Gandhi

        N Offline
        N Offline
        Nicholas Cardi
        wrote on last edited by
        #3

        Then how does spy++ tool do it? Is this a dot net rule? Forever Developing

        J 1 Reply Last reply
        0
        • N Nicholas Cardi

          Then how does spy++ tool do it? Is this a dot net rule? Forever Developing

          J Offline
          J Offline
          J Dunlap
          wrote on last edited by
          #4

          This isn't a .NET rule - it's a Windows rule. ;) What are you trying to accomplish? It's likely there is another way to do it.

          "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
          "You must be the change you wish to see in the world." - Mahatma Gandhi

          N 1 Reply Last reply
          0
          • J J Dunlap

            This isn't a .NET rule - it's a Windows rule. ;) What are you trying to accomplish? It's likely there is another way to do it.

            "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
            "You must be the change you wish to see in the world." - Mahatma Gandhi

            N Offline
            N Offline
            Nicholas Cardi
            wrote on last edited by
            #5

            I am trying to draw on the desktop. I need to be notified of the WM_Paint message for the desktop otherwise what I draw is erased on the next WM_Paint. Thanks for your help Forever Developing

            J R 2 Replies Last reply
            0
            • N Nicholas Cardi

              I am trying to draw on the desktop. I need to be notified of the WM_Paint message for the desktop otherwise what I draw is erased on the next WM_Paint. Thanks for your help Forever Developing

              J Offline
              J Offline
              J Dunlap
              wrote on last edited by
              #6

              And why do you need to draw on the desktop? ;)

              "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
              "You must be the change you wish to see in the world." - Mahatma Gandhi

              N 1 Reply Last reply
              0
              • J J Dunlap

                And why do you need to draw on the desktop? ;)

                "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                "You must be the change you wish to see in the world." - Mahatma Gandhi

                N Offline
                N Offline
                Nicholas Cardi
                wrote on last edited by
                #7

                Just for fun. Forever Developing

                A 1 Reply Last reply
                0
                • N Nicholas Cardi

                  Just for fun. Forever Developing

                  A Offline
                  A Offline
                  Arun Bhalla
                  wrote on last edited by
                  #8

                  It might not be what you want to do, but check out the ControlPaint class.

                  1 Reply Last reply
                  0
                  • N Nicholas Cardi

                    I am trying to draw on the desktop. I need to be notified of the WM_Paint message for the desktop otherwise what I draw is erased on the next WM_Paint. Thanks for your help Forever Developing

                    R Offline
                    R Offline
                    Rocky Moore
                    wrote on last edited by
                    #9

                    I do not know of a way in .NET but in Win32 you can probably do it with a DLL and HookProc. It will map your DLL into the system memory space were you can trap the messages. I used this method in the old days to communicate with the AOL software and capture its messages. Rocky Moore <><

                    J 1 Reply Last reply
                    0
                    • R Rocky Moore

                      I do not know of a way in .NET but in Win32 you can probably do it with a DLL and HookProc. It will map your DLL into the system memory space were you can trap the messages. I used this method in the old days to communicate with the AOL software and capture its messages. Rocky Moore <><

                      J Offline
                      J Offline
                      J Dunlap
                      wrote on last edited by
                      #10

                      It's best not to deal with system-wide hooks, but it can be done. The main thing is that if your DLL hangs, the system hangs. (I've had experience with that! :( ) You might also look into a journal hook, although it may not work for paint messages.

                      "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                      "You must be the change you wish to see in the world." - Mahatma Gandhi

                      R N 2 Replies Last reply
                      0
                      • J J Dunlap

                        It's best not to deal with system-wide hooks, but it can be done. The main thing is that if your DLL hangs, the system hangs. (I've had experience with that! :( ) You might also look into a journal hook, although it may not work for paint messages.

                        "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                        "You must be the change you wish to see in the world." - Mahatma Gandhi

                        R Offline
                        R Offline
                        Rocky Moore
                        wrote on last edited by
                        #11

                        jdunlap wrote: The main thing is that if your DLL hangs, the system hangs. Makes debugging interesting ;) Actually, I never had any problems with System Wide Hooks. The code required to implement them is not complex and as long as you keep to only what is required and do not pile a lot into the DLL, things should be fine. You need to watch when you attach and detach from different applications, a goof in there can cause strange things to happen ;) Thre are not anything to be afriad of though, I used them for years with the application I mentioned and never recieved on issue about it crashing their system. Rocky Moore <><

                        1 Reply Last reply
                        0
                        • J J Dunlap

                          It's best not to deal with system-wide hooks, but it can be done. The main thing is that if your DLL hangs, the system hangs. (I've had experience with that! :( ) You might also look into a journal hook, although it may not work for paint messages.

                          "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                          "You must be the change you wish to see in the world." - Mahatma Gandhi

                          N Offline
                          N Offline
                          Nick Parker
                          wrote on last edited by
                          #12

                          jdunlap wrote: It's best not to deal with system-wide hooks, but it can be done. FYI: According to MSDN you can't perform a global hook under the .NET Framework : Knowledge Base Article - 318804[^] -Nick Parker

                          L 1 Reply Last reply
                          0
                          • N Nick Parker

                            jdunlap wrote: It's best not to deal with system-wide hooks, but it can be done. FYI: According to MSDN you can't perform a global hook under the .NET Framework : Knowledge Base Article - 318804[^] -Nick Parker

                            L Offline
                            L Offline
                            leppie
                            wrote on last edited by
                            #13

                            "To install a global hook, a hook must have a native dynamic-link library (DLL) export to inject itself in another process that requires a valid, consistent function to call into. This requires a DLL export, which .NET Framework does not support. " But this supported by MC++. I have a single dll with exports and a manifest ad can be used by bith managed and unmanaged apps, just as long as you have .NET installed, the process is transparent to unmanaged code. So IMO its should be a trivial task to make an interface for a global hook. I havent done anything like this, am I correct? leppie::AllocCPArticle(Generic DFA State Machine for .NET);

                            N 1 Reply Last reply
                            0
                            • L leppie

                              "To install a global hook, a hook must have a native dynamic-link library (DLL) export to inject itself in another process that requires a valid, consistent function to call into. This requires a DLL export, which .NET Framework does not support. " But this supported by MC++. I have a single dll with exports and a manifest ad can be used by bith managed and unmanaged apps, just as long as you have .NET installed, the process is transparent to unmanaged code. So IMO its should be a trivial task to make an interface for a global hook. I havent done anything like this, am I correct? leppie::AllocCPArticle(Generic DFA State Machine for .NET);

                              N Offline
                              N Offline
                              Nick Parker
                              wrote on last edited by
                              #14

                              leppie wrote: But this supported by MC++. I have a single dll with exports and a manifest ad can be used by bith managed and unmanaged apps, just as long as you have .NET installed, the process is transparent to unmanaged code. I guess what they mean is that the .NET Framework doesn't natively support this type of functionality (strictly within the Framework itself), I believe what you have is a "work-around". Then again, I could be completely wrong. :-D -Nick Parker

                              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