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. Want my form to permit focus to "penetrate" to whatever window is under

Want my form to permit focus to "penetrate" to whatever window is under

Scheduled Pinned Locked Moved C#
question
9 Posts 4 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.
  • F Offline
    F Offline
    FocusedWolf
    wrote on last edited by
    #1

    So if i had my form open, and i click, the click will fall to the desktop, or other forms... any easy way to do this?

    C G M 3 Replies Last reply
    0
    • F FocusedWolf

      So if i had my form open, and i click, the click will fall to the desktop, or other forms... any easy way to do this?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Not a trivial way, no.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      F 1 Reply Last reply
      0
      • C Christian Graus

        Not a trivial way, no.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        F Offline
        F Offline
        FocusedWolf
        wrote on last edited by
        #3

        hmm so does the hard way involve wndproc in some fashion, or are we talking harder :P

        C 1 Reply Last reply
        0
        • F FocusedWolf

          hmm so does the hard way involve wndproc in some fashion, or are we talking harder :P

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          You can actually call an API called WindowFromPoint. So, hide your window, call that API on the screen point you clicked, convert to a point relative to the window and send it a WM_CLICK message. And a WM_LBUTTONDOWN and WM_LBUTTONUP. FIddly, more than anything.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          F 2 Replies Last reply
          0
          • F FocusedWolf

            So if i had my form open, and i click, the click will fall to the desktop, or other forms... any easy way to do this?

            G Offline
            G Offline
            Giorgi Dalakishvili
            wrote on last edited by
            #5

            Did you use search? There are several articles at codeproject showing how to achieve it.

            Giorgi Dalakishvili #region signature my articles #endregion

            1 Reply Last reply
            0
            • F FocusedWolf

              So if i had my form open, and i click, the click will fall to the desktop, or other forms... any easy way to do this?

              M Offline
              M Offline
              Muammar
              wrote on last edited by
              #6

              Try searching for "hooks"


              All generalizations are wrong, including this one! (\ /) (O.o) (><)

              1 Reply Last reply
              0
              • C Christian Graus

                You can actually call an API called WindowFromPoint. So, hide your window, call that API on the screen point you clicked, convert to a point relative to the window and send it a WM_CLICK message. And a WM_LBUTTONDOWN and WM_LBUTTONUP. FIddly, more than anything.

                Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                F Offline
                F Offline
                FocusedWolf
                wrote on last edited by
                #7

                Ya no luck with WindowFromPoint (in vista) so far... Also how do i "hide" a form from WindowFromPoint but keep it visible?, i tried making it not enabled, and some ShowWindowAsync(shades.Handle, SW_HIDE) which definatally hides it from view, but i want it visible still... Also i tried with one of those lowlevel-ish hooks to watch the mouse when it's off my form, and so far WindowFromPoint returns 0 regardless... something that caught my eye though was:

                    private const int WM\_NCHITTEST = 0x0084;
                    private const int HTTRANSPARENT = (-1);
                
                    /// <summary>
                    /// Overrides the standard Window Procedure to ensure the
                    /// window is transparent to all mouse events.
                    /// </summary>
                    /// <param name="m">Windows message to process.</param>
                    protected override void WndProc(ref Message m)
                    {
                        if (m.Msg == WM\_NCHITTEST)
                        {
                            m.Result = (IntPtr)HTTRANSPARENT;
                        }
                        else
                        {
                            base.WndProc(ref m);
                        }
                    }
                

                but it doesn't work for other threads... else it'd be very good solution :P

                F 1 Reply Last reply
                0
                • F FocusedWolf

                  Ya no luck with WindowFromPoint (in vista) so far... Also how do i "hide" a form from WindowFromPoint but keep it visible?, i tried making it not enabled, and some ShowWindowAsync(shades.Handle, SW_HIDE) which definatally hides it from view, but i want it visible still... Also i tried with one of those lowlevel-ish hooks to watch the mouse when it's off my form, and so far WindowFromPoint returns 0 regardless... something that caught my eye though was:

                      private const int WM\_NCHITTEST = 0x0084;
                      private const int HTTRANSPARENT = (-1);
                  
                      /// <summary>
                      /// Overrides the standard Window Procedure to ensure the
                      /// window is transparent to all mouse events.
                      /// </summary>
                      /// <param name="m">Windows message to process.</param>
                      protected override void WndProc(ref Message m)
                      {
                          if (m.Msg == WM\_NCHITTEST)
                          {
                              m.Result = (IntPtr)HTTRANSPARENT;
                          }
                          else
                          {
                              base.WndProc(ref m);
                          }
                      }
                  

                  but it doesn't work for other threads... else it'd be very good solution :P

                  F Offline
                  F Offline
                  FocusedWolf
                  wrote on last edited by
                  #8

                  Ok no idea why but now i'm seeing WindowFromPoint working now... i'll see now if i can get this to work.

                  1 Reply Last reply
                  0
                  • C Christian Graus

                    You can actually call an API called WindowFromPoint. So, hide your window, call that API on the screen point you clicked, convert to a point relative to the window and send it a WM_CLICK message. And a WM_LBUTTONDOWN and WM_LBUTTONUP. FIddly, more than anything.

                    Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                    F Offline
                    F Offline
                    FocusedWolf
                    wrote on last edited by
                    #9

                    Ok been through hell with this, and starting to show progress: 1. i made a new WindowFromPoint function that effectively finds the window underneath. to do this i had to use api:enumWindows... whichs gives a list of windows in the correct z-order, and just filter the results to visible windows that don't match my programs handle... then just check which rectangle the mouse is within and there you go... it works 100% 2. sendmessage to relay messages is no joke as it would appear... pain in the ass would best describe it... apparently something is blocking any messages from getting through! my guess = vista lol. i tried using microsof spy to watch for any messages in a test program, and i placed my window above it... and spy showed no messages getting through... that's not to say "some" messages don't get through... i did notice doubleclicking on the taskmanager through my form did infact do what double clicking would do to it... but nothing in way of rightclick, or highlights... and the code that sends these messages is same... basically catch alot of mouse messages in my wndproc, and send them to another window... so i'm not sure what to do next. i need another way to send mouse messages :P

                    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