顯示現場視頻: 改變鼠標顯示形狀

演示如何改變 IC Imaging Control 鼠標在屏幕中的圖標形狀。
語言:.NET C#/Visual Basic
版本:3.0.3
发布于:2007年7月5日
作者:IC Imaging Control 技術支持部
需求:IC Imaging Control >2.1
由WDM數據流類驅動程序驅動的相機、視頻轉換器或圖像採集卡

這個例子演示的是如何改變IC Imaging Control中鼠標在屏幕中顯示的形狀。 程序窗體如圖所示:

IC Imaging Control with new cursor

為了改變鼠標形狀,程序還需要一個外部 DLL——icsetcursor.dll,它用於導出函數FindICWindow,接收程序窗口處理和鼠標文件名。

程序首先聲明函數 FindICWindow

[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

在Visual Basic中必須使用Ansi聲明,因為DLL不支持unicode文件名。

在這個程序經過第一次編譯之後, 如使用C#,文件 icsetcursor.dllcross.cur 必須被拷貝至目錄 bin\debugbin\release, 如使用Visual Basic,必須被拷貝至 bin。 如文件沒能被拷貝,則彈出"DLL not found" exception對話框。

在函數 Form_load 中,鼠標被第一次設置:

[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

為方便起見,對FindICWindow的調用被至於try - catch語句中,這樣一來,如果icsetcursor.dll不在工作目錄內,程序就會彈出 "DLL not found" exception 對話框。

開始現場視頻後,因為一個新的內部窗口已被開啟,程序需要設置新的鼠標, 所以再次調用 FindICWindow 設置鼠標。

[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

相關源代碼示例

責任聲明
IC Imaging Control源代碼庫中的所有代碼均只用於教學目的,The Imaging Source Europe GmbH作為IC Imaging Control的開發製造商,不對任何由於使用本文或其中源代碼所產生的後果承擔責任。

该网站为The Imaging Source网络的一部分。其它的站点包括 公司, Imaging, 天文相機, Astronomy Cameras Blog, Blog caméras d'astronomie, 天文相機有獎競答, TX Text Control, LiveDocx, phpLiveDocxForum.