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. Lock the cursor type

Lock the cursor type

Scheduled Pinned Locked Moved C#
question
5 Posts 2 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.
  • K Offline
    K Offline
    Kalvin Work
    wrote on last edited by
    #1

    In an application I set the windows cursor to a WaitCursor, but other components within the same application set it back to Default. Is there a way to set the cursor type, and prevent other areas of the same application from changing it? Thank you in advance. Kalvin

    S 1 Reply Last reply
    0
    • K Kalvin Work

      In an application I set the windows cursor to a WaitCursor, but other components within the same application set it back to Default. Is there a way to set the cursor type, and prevent other areas of the same application from changing it? Thank you in advance. Kalvin

      S Offline
      S Offline
      Skippums
      wrote on last edited by
      #2

      You can set the UseWaitCursor property to force the WaitCursor to be the one used when the mouse is within the bounds of an object with that property set to "true". I don't think that there is any way to prevent another app from changing it unless you are coding the app. If you are coding it, then look into thread synchronization techniques. The method I would try to implement would be to acquire a named mutex (or static variable) anytime you want to change the cursor. Then, if you want to prevent others within your app from changing it, just hold the mutex (static variable). Hope this helps,

      Sounds like somebody's got a case of the Mondays -Jeff

      K 1 Reply Last reply
      0
      • S Skippums

        You can set the UseWaitCursor property to force the WaitCursor to be the one used when the mouse is within the bounds of an object with that property set to "true". I don't think that there is any way to prevent another app from changing it unless you are coding the app. If you are coding it, then look into thread synchronization techniques. The method I would try to implement would be to acquire a named mutex (or static variable) anytime you want to change the cursor. Then, if you want to prevent others within your app from changing it, just hold the mutex (static variable). Hope this helps,

        Sounds like somebody's got a case of the Mondays -Jeff

        K Offline
        K Offline
        Kalvin Work
        wrote on last edited by
        #3

        Thanks a lot for your reply. The cursor is being changed from different components that together make an application. Some components I have access to change, and others I can't access or modify the code. I also should have stated that this is in VS 2003 and the WaitCursor isn't available. I can't access other components to make them use a mutex. If those are the only options in C#, is there a way to use an API to do this or is doing this just not the way windows works? Thanks again.

        S 1 Reply Last reply
        0
        • K Kalvin Work

          Thanks a lot for your reply. The cursor is being changed from different components that together make an application. Some components I have access to change, and others I can't access or modify the code. I also should have stated that this is in VS 2003 and the WaitCursor isn't available. I can't access other components to make them use a mutex. If those are the only options in C#, is there a way to use an API to do this or is doing this just not the way windows works? Thanks again.

          S Offline
          S Offline
          Skippums
          wrote on last edited by
          #4

          I'm not really certain if the following would lock only a local copy of the cursor, or if it would lock the cursor resource for all applications, but you could try to use the WinAPI calls LoadCursor[^] followed by a LockResource[^]. Again, I don't have time to experiment with these, but they would be worth looking into. Another idea would be to implement a timer that continuously checks the cursor, and sets it back if it is changed (this method scores a 9/10 on the hack scale). A better idea would be to listen to the windows events (like Spy++ does) and block any attempt at sending a WM_SETCURSOR (I assume this is the message being sent) message. I've never tried to intercept windows messages, but I'm sure you can google to discover how to go about this (perhaps look at overriding DefaultWndProc and WndProc methods on Control objects?). Please post results if you get it working.

          Sounds like somebody's got a case of the Mondays -Jeff

          K 1 Reply Last reply
          0
          • S Skippums

            I'm not really certain if the following would lock only a local copy of the cursor, or if it would lock the cursor resource for all applications, but you could try to use the WinAPI calls LoadCursor[^] followed by a LockResource[^]. Again, I don't have time to experiment with these, but they would be worth looking into. Another idea would be to implement a timer that continuously checks the cursor, and sets it back if it is changed (this method scores a 9/10 on the hack scale). A better idea would be to listen to the windows events (like Spy++ does) and block any attempt at sending a WM_SETCURSOR (I assume this is the message being sent) message. I've never tried to intercept windows messages, but I'm sure you can google to discover how to go about this (perhaps look at overriding DefaultWndProc and WndProc methods on Control objects?). Please post results if you get it working.

            Sounds like somebody's got a case of the Mondays -Jeff

            K Offline
            K Offline
            Kalvin Work
            wrote on last edited by
            #5

            Thank you for the reply and all of your help.

            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