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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WPF
  4. Avoid flicker

Avoid flicker

Scheduled Pinned Locked Moved WPF
graphicsquestion
10 Posts 3 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
    Member 2965471
    wrote on last edited by
    #1

    Hi all, I've a transparent topmost window, I need on mouse move to highlight the window under the cursor I tried so in mouse_move_handler:

    ...
    this.Hide();
    hWnd = Win32.WindowFromPoint(p);
    this.Show();
    ...
    Win32.GetWindowRect(hWnd, ref rc);
    and so on drawing rectangle
    ...

    this code works, but I can't avoid flicker. There is some alternative way to do this?

    P 1 Reply Last reply
    0
    • M Member 2965471

      Hi all, I've a transparent topmost window, I need on mouse move to highlight the window under the cursor I tried so in mouse_move_handler:

      ...
      this.Hide();
      hWnd = Win32.WindowFromPoint(p);
      this.Show();
      ...
      Win32.GetWindowRect(hWnd, ref rc);
      and so on drawing rectangle
      ...

      this code works, but I can't avoid flicker. There is some alternative way to do this?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      I'm not surprised you've got flickering. You keep showing and hiding a window in there, and it looks as though you are calling this on every mouse move - that's a lot of event updates you're calling this code in. You also haven't shown the code where you're highlighting, this will also be called a lot of times. What is the purpose of the Hide/Show code? What are you changing the visibility of? Are you tracking to see if the window that was last updated matches the one retrieved in WindowFromPoint? If not, that's an obvious optimisation.

      Forgive your enemies - it messes with their heads

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      M 1 Reply Last reply
      0
      • P Pete OHanlon

        I'm not surprised you've got flickering. You keep showing and hiding a window in there, and it looks as though you are calling this on every mouse move - that's a lot of event updates you're calling this code in. You also haven't shown the code where you're highlighting, this will also be called a lot of times. What is the purpose of the Hide/Show code? What are you changing the visibility of? Are you tracking to see if the window that was last updated matches the one retrieved in WindowFromPoint? If not, that's an obvious optimisation.

        Forgive your enemies - it messes with their heads

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        M Offline
        M Offline
        Member 2965471
        wrote on last edited by
        #3

        The main problem is to get the hwnd of the window immediately under my wpf topmost Window.

        P 1 Reply Last reply
        0
        • M Member 2965471

          The main problem is to get the hwnd of the window immediately under my wpf topmost Window.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          To be honest, I'm not sure why you're dropping down to GDI to achieve this. There are ways to get the positions of windows that do not rely on dropping down to interop to retrieve these items. You can use the Visual tree and perform your calculations based off that.

          Forgive your enemies - it messes with their heads

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          M 1 Reply Last reply
          0
          • P Pete OHanlon

            To be honest, I'm not sure why you're dropping down to GDI to achieve this. There are ways to get the positions of windows that do not rely on dropping down to interop to retrieve these items. You can use the Visual tree and perform your calculations based off that.

            Forgive your enemies - it messes with their heads

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            M Offline
            M Offline
            Member 2965471
            wrote on last edited by
            #5

            because with visual tree I can handle only the windows that own to my application, but under the mouse cursor there may be a window of any application running on desktop.

            P 1 Reply Last reply
            0
            • M Member 2965471

              because with visual tree I can handle only the windows that own to my application, but under the mouse cursor there may be a window of any application running on desktop.

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Ah, I see. So you're evaluating ALL windows then. Well, you're going to have to optimise your hit tests then I'm afraid.

              Forgive your enemies - it messes with their heads

              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

              My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

              M 1 Reply Last reply
              0
              • P Pete OHanlon

                Ah, I see. So you're evaluating ALL windows then. Well, you're going to have to optimise your hit tests then I'm afraid.

                Forgive your enemies - it messes with their heads

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                M Offline
                M Offline
                Member 2965471
                wrote on last edited by
                #7

                I don't know how perform hit test without hiding my window...

                P 1 Reply Last reply
                0
                • M Member 2965471

                  I don't know how perform hit test without hiding my window...

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  Probably the easiest way to code this is to enumerate all the windows using EnumDesktopWindows[^]. You can use this to iterate over and do your point in rectangle tests. That way, you aren't relying on showing/hiding windows.

                  Forgive your enemies - it messes with their heads

                  "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  M 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    Probably the easiest way to code this is to enumerate all the windows using EnumDesktopWindows[^]. You can use this to iterate over and do your point in rectangle tests. That way, you aren't relying on showing/hiding windows.

                    Forgive your enemies - it messes with their heads

                    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                    My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                    M Offline
                    M Offline
                    Member 2965471
                    wrote on last edited by
                    #9

                    I use EnumWindows, the problem is that more than one windows pass the check(point in rect). How can I determine the right window on which lies the mouse?

                    S 1 Reply Last reply
                    0
                    • M Member 2965471

                      I use EnumWindows, the problem is that more than one windows pass the check(point in rect). How can I determine the right window on which lies the mouse?

                      S Offline
                      S Offline
                      SledgeHammer01
                      wrote on last edited by
                      #10

                      I would guess the top most window (not counting your own).

                      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