Lock the cursor type
-
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
-
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
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
-
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
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.
-
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.
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
-
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
Thank you for the reply and all of your help.