Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
LoadCursor (user32)
.
C# Signature:
[DllImport("user32.dll")]
static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
VB Signature:
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function LoadCursor( _
ByVal hInstance As IntPtr, _
ByVal lpCursorName As String) As IntPtr
End Function
Common VB Overloads:
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function LoadCursor( _
ByVal hInstance As IntPtr, _
ByVal lpCursorName As Integer) As IntPtr
End Function
This function may not solve your problems when trying to load animated or colored cursors stored as embedded resources. I've wasted hours trying to get it to work to no avail. The LoadCursorFromFile method however works perfectly, so you might want to extract your cursor resource to a temp file and use the P/Invoke for that function.
Well, there is actually a way to do it!!! See VS2010 VB Sample code.
Tips & Tricks:
If you specify the hInstance as IntPtr.Zero, then you can specify one of the constants in IDC_ as the CursorName to utilize system defined cursors.
Dim HighlightPointer as Cursor = ColorCursor.LoadCursor(101)
''' <summary>
''' Provides ability to load color and/or animated cursor for the form or control.
''' Note: cursor must be embedded as native win32 resource in the assembly.
''' </summary>
Private Class ColorCursor
Private Declare Function LoadCursorAPI Lib "user32.dll" Alias "LoadCursorA" (ByVal hInstance As IntPtr, ByVal lpCursorName As String) As IntPtr
Public Shared Function LoadCursor(ByVal embededWin32ResourceID As Integer) As Cursor
Dim cursor As Cursor = TryLoadCursor(embededWin32ResourceID)
If cursor Is Nothing Then
Throw New System.ComponentModel.Win32Exception(Err.LastDllError)
Else
Return cursor
End If
End Function
Public Shared Function TryLoadCursor(ByVal embededWin32ResourceID As Integer) As Cursor
Dim hInstance As IntPtr = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0))
Dim cPtr As IntPtr = LoadCursorAPI(hInstance, embededWin32ResourceID)
cPtr = LoadCursorAPI(hInstance, "#" & embededWin32ResourceID)
If cPtr = IntPtr.Zero Then
Return Nothing
Else
Return New Cursor(cPtr)
End If
End Function
End Class
How to Embed Multiple Icons and Color/Animated Cursors in VS2010 VB project as Native Win32 Resources:
This is useful if you need your EXE or DLL to provide multiple icons for documents associated with your application. It also provides a way to load color and animated cursors for your forms and/or controls. Note: even .NET 4.0 does not support this natively, it can only load black and while cursors.
Method 1 (simple, but requires repeating following steps after every build):
1. Open your EXE or DLL in Visual Studio (either File->Open File or just drag and drop it into IDE).
2. Add icons and/or cursors to the EXE or DLL
3. Save file.
Method 2 (more involved, but done only once):
1. Find native win32 resource file (*.res) on the web. Google “Embedding Multiple Icons into .NET Executables” and download the sample project which contains *.res file. VS2010 does not have the template to create this file; however the editor is still there.
2. Rename file to assemblyWin32.res, include it in your project, and compile it as content in Build Action.
3. Add icons and/or cursors to the assemblyWin32.res file.
4. Open your project file in notepad (*.vbProj) and add the following block:
5. If you have included icons in the Win32 resource file for your EXE then remove application icon in project properties->Application Tab (this icon will no longer be used).
6. Build the project
Alternative Managed API:
Do you know one? Please contribute it!
The LoadCursor API
9/21/2019 11:44:03 AM - 185.15.81.195
Defines some of the default system cursors.
5/15/2017 4:40:59 AM - -94.229.131.27
The LoadCursorFromFile API
3/16/2007 8:28:05 AM - Conipto-24.4.218.70
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
Defines some of the default system cursors.
5/15/2017 4:40:59 AM - -94.229.131.27
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).