Changing the Mouse Cursor
| Summary: | Programming example that illustrates how to change IC Imaging Control's mouse cursor. |
| Language: | .NET C#/Visual Basic |
| Released on: | July 05, 2007 |
| Author: | IC Imaging Control Support Department |
| Requirements: | IC Imaging Control >2.1 Camera, converter or grabber with WDM Stream Class drivers. |
| Download C# sample Download VB.NET sample | |
This sample shows how to change the mouse cursor in IC Imaging Control. The window of the resulting application looks as follows:

In order to change the mouse cursor in IC Imaging Control, an extra DLL needs to be used. The DLL icsetcursor.dll exports the function FindICWindow, receives the application's window handle and the file name of the cursor.
First of all the function FindICWindow must be declared in the application:
[C#] [System.Runtime.InteropServices.DllImport ("icsetcursor.dll")] private extern static long FindICWindow(IntPtr ParentWindow, string szCursorName);
[VB.NET] Declare Ansi Function FindICWindow Lib "icsetcursor.dll" (ByVal hWnd As IntPtr, _ ByVal CursorFile As String) As Long
The declaration must use Ansi in Visual Basic, because the DLL does not support unicode file names.
After the application has been compiled for the first time, the files icsetcursor.dll and cross.cur must be copied into the directories bin\debug and bin\release for C# and bin for Visual Basic projects. The "DLL not found" exception is thrown, if the files could not be copied.
In the Form_load functions, the cursor is set for the first time:
[C#] try { // Set the cursor. FindICWindow(this.Handle,"cross.cur"); } catch { // In order to avoid the application stops in case the "icsetcursor.dll" is // missing, the application catches the "DLL not found" exception. MessageBox.Show("The DLL \"icsetcursor.dll\" was not found.\nPlease make sure it is saved in your working directory!","Set Cursor"); }
[VB.NET]
Try
' Set the cursor.
FindICWindow(Me.Handle, "cross.cur")
Catch
' In order to avoid the application stops in case the "icsetcursor.dll" is
' missing, the application catches the "DLL not found" exception.
MessageBox.Show("The DLL 'icsetcursor.dll' was not found.Please make sure it is saved in your working directory!", "Set Cursor")
End Try
For convenience, the call to FindICWindow is encapsulated in a try - catch block in order to catch the "DLL not found" exception in case the icsetcursor.dll is not in the application's working directory.
After the live video has been started, the new cursor must be set again, because a new internal window was opened. Thus, FindICWindow must be called again to set the mouse cursor.
[C#] private void StartLiveVideo() { icImagingControl1.LiveStart(); menuItemLiveStart.Enabled = false; menuItemLiveStop.Enabled = true; tbStartLive.Enabled = false; tbStopLive.Enabled = true; // Set the cursor to the live video's display window. FindICWindow(this.Handle,"cross.cur"); }
[VB.NET] 'Start the live video. Private Sub StartLiveVideo() With IcImagingControl1 If (.DeviceValid) Then .LiveStart() FindICWindow(Me.Handle, "cross.cur") EnableControlls() End If End With End Sub
Related Source Code Samples
The following source code samples are related to Changing the Mouse Cursor:
Disclaimer
The source code that appears in the IC Imaging Control Source Code Library is indented for educational purposes only. The Imaging Source Europe GmbH, the manufacturer of IC Imaging Control, does not assume any kind of warranty expressed or implied, resulting from the use of the content of this page.
