Results 1 to 6 of 6

Thread: Applying Registry Settings In VB.Net

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Red face Applying Registry Settings In VB.Net

    I am working on an application that allows the user to change the Mouse Properties Pointer Scheme to custom designed mouse pointers.

    I have found a way to write the new mouse cursors to the registry using VB.Net and the registry location of HKEY_CURRENT_USER\Control Panel\Cursors.

    The problem that I am having is that I do not know how to get Windows to re-read and apply these new registry settings without logging off and then back on or re-starting the computer.

    If anyone know how to do this, I would really appreciate the advice.

    Thanks
    Mike

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Applying Registry Settings In VB.Net

    I figured there was a way to do it in API, and after working with it, found out how to do it...
    VB Code:
    1. 'API declarations (form level in test)
    2.     Declare Function SetSystemCursor Lib "user32.dll" ( _
    3.             ByVal hcur As Int32, _
    4.             ByVal id As Int32) As Int32
    5.     Declare Function LoadCursorFromFile Lib "user32.dll" Alias "LoadCursorFromFileA" ( _
    6.            ByVal lpFileName As String) As Int32
    7.     'constant for the "normal" cursor (main arrow graphic)
    8.     Private Const OCR_NORMAL As Int32 = 32512
    9.  
    10. 'now in a sub, like button click...
    11. SetSystemCursor((LoadCursorFromFile("C:\WINDOWS\Cursors\3dgarro.cur")), OCR_NORMAL)
    This successfully changed my main arrow cursor to a bronze arrow (which is what 3dgarro is).

    Notice the path to the file, that is the cursor directory on my machine, hard coded, used as a test. For your app I believe that you would have to get the windows folder path, since it wont always be "c:\windows". Also, this was tested on my XP machine, win2k might be different...

    Also note that there are other "states" other than "OCR_NORMAL" that would have to be changed with other graphics as well if you wish to change all the states of the cursor. The one in this example was just the main arrow cursor.
    Last edited by gigemboy; Dec 30th, 2005 at 05:11 PM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Re: Applying Registry Settings In VB.Net

    Thank you!

    That is a big help. But I am very new to VB.Net and don't understand how to change each of the 14 cursors that the system uses.

    I have tried changing the path to the graphic to be used as the mouse icon, and that works with no problem. But when I try changing the type of mouse cursor, say I want to change the i-beam icon to a diffrent one.

    I do a;
    Private Const OCR_IBEAM As Int32 = 32512

    And then place the IBEAM at the end of the line;
    SetSystemCursor((LoadCursorFromFile("C:\WINDOWS\Cursors\3dgarro.cur")), OCR_IBEAM)

    But each time it only changes the main cursor and the text (IBEAM) cursor which sould come up when I place the cursor over text, stays the same.

    I know I must be missing something that is obviuos to an experienced programmer.

    Your help is appreceiated.
    Mike

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Applying Registry Settings In VB.Net

    The value 32512 specifically indicates the OCR_NORMAL cursor. If you want to specify the other cursors then you need to find the constant values that correspond to them. I'd suggest that you do a Google search for each of the constant names listed on MSDN in the help topic for SetSystemCursor. You're almost certain to find some pages that will give you the appropriate values for each, probably all on one page.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Applying Registry Settings In VB.Net

    Here's the rest of the OCR_ constants, as listed in "ApiViewer 2004" (my choice of API lookup program, as it has a .NET mode with the .NET function declaration changes )
    VB Code:
    1. Const OCR_APPSTARTING As Int32 = 32650
    2. Const OCR_CROSS As Int32 = 32515
    3. Const OCR_HAND As Int32 = 32649
    4. Const OCR_IBEAM As Int32 = 32513
    5. Const OCR_ICOCUR As Int32 = 32647
    6. Const OCR_ICON As Int32 = 32641
    7. Const OCR_NO As Int32 = 32648
    8. Const OCR_SIZE As Int32 = 32640
    9. Const OCR_SIZEALL As Int32 = 32646
    10. Const OCR_SIZENESW As Int32 = 32643
    11. Const OCR_SIZENS As Int32 = 32645
    12. Const OCR_SIZENWSE As Int32 = 32642
    13. Const OCR_SIZEWE As Int32 = 32644
    14. Const OCR_UP As Int32 = 32516
    15. Const OCR_WAIT As Int32 = 32514
    Last edited by gigemboy; Jan 1st, 2006 at 04:06 PM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Re: Applying Registry Settings In VB.Net

    Fantastic! I have them all working now.

    Can’t thank you enough for the help, this has been driving me nuts for weeks now. I will combine this with writing the information to the registry, to update the Mouse Properties, Pointers and Schemes in case the user looks at the settings there, and I have a good portion of what I needed!

    Would you have any idea how to change the text cursor throughout the system?

    Thanks again and have a good New Year.
    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width