⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phonelistbox.vb

📁 以前做NOKIA手机与PC通信时所参考的源代码,里面包括两个程序,一个是手机文件夹浏览源码,另一个手机SIS安装程序.
💻 VB
📖 第 1 页 / 共 2 页
字号:
                GetCurrentSN = m_strSerialNumbers(index)
            End If
        Else
            ' user is browsing phone content
            GetCurrentSN = m_strCurrentSN
        End If
    End Function

    '===================================================================
    ' GetCurrentFriendlyName
    '
    ' Returns friendly name of currently selected phone
    ' 
    '===================================================================
    Function GetCurrentFriendlyName() As String
        GetCurrentFriendlyName = ""
        If m_wState = PHONELIST_STATE_PHONELIST Then
            ' phone list is shown
            Dim index As Integer = SelectedIndex
            If index <> -1 Then
                ' there is a selected item
                GetCurrentFriendlyName = m_strFriendlyNames(index)
            End If
        Else
            ' user is browsing phone content
            GetCurrentFriendlyName = m_strCurrentFriendlyName
        End If
    End Function

    '===================================================================
    ' GetState
    '
    ' Returns current state of listbox 
    ' (PHONELIST_STATE_PHONELIST or PHONELIST_STATE_PHONECONTENT)
    ' 
    '===================================================================
    Public Function GetState() As Integer
        GetState = m_wState
    End Function

    '===================================================================
    ' SetState
    '
    ' Sets current state of listbox 
    ' 
    '===================================================================
    Public Sub SetState(ByVal wState As Integer)
        m_wState = wState
    End Sub

    Private Function GetFreeMemoryString(ByVal pDevice As CONAPI_DEVICE) As String
        Dim hFS As Integer
        Dim iMedia As Integer
        Dim iDeviceID As Integer
        Dim ret As Integer
        Dim iFreeMem As Int64 = -1
        Dim iUsedMem As Int64 = -1
        Dim iTotalMem As Int64 = -1
        Dim dFreeMem As Double
        Dim dUsedMem As Double
        Dim dTotalMem As Double
        GetFreeMemoryString = ""
        ' Create FS connection
        iMedia = API_MEDIA_ALL
        ret = CONAOpenFS(pDevice.pstrSerialNumber, iMedia, hFS, iDeviceID)
        If ret <> CONA_OK Then ShowErrorMessage("CONAOpenFS", ret)
        If ret = CONA_OK Then
            ' refreshing memory values
            ret = CONARefreshDeviceMemoryValues(hFS)
            If ret <> CONA_OK Then ShowErrorMessage("CONARefreshDeviceMemoryValues", ret)

            GetFreeMemoryString &= Long2MediaString(iMedia)
            Dim strMemoryTypes As String = ""
            ret = CONAGetMemoryTypes(hFS, strMemoryTypes)
            If ret = CONA_OK Then
                '
                Dim strMemories As String() = strMemoryTypes.Split(",")
                For Each strType As String In strMemories
                    GetFreeMemoryString &= "; " & strType & ": "
                    ' Getting memory of connected device
                    ret = CONAGetMemoryValues(hFS, strType, iFreeMem, iTotalMem, iUsedMem)
                    If ret <> CONA_OK Then ShowErrorMessage("CONAGetMemoryValues", ret)
                    If ret = CONA_OK Then
                        If iFreeMem <> -1 Then
                            dFreeMem = iFreeMem
                            GetFreeMemoryString &= "Free " & String.Format("{0:0.00}", dFreeMem / 1024 / 1024) & " MB"
                        End If
                        If iTotalMem <> -1 And iFreeMem <> 1 Then
                            dUsedMem = iUsedMem
                            dTotalMem = iTotalMem
                            GetFreeMemoryString &= ", used " & String.Format("{0:0.00}", dUsedMem / 1024 / 1024)
                            GetFreeMemoryString &= "/" & String.Format("{0:0.0}", dTotalMem / 1024 / 1024) & " MB"
                        End If
                    End If
                Next
            Else
                ShowErrorMessage("CONAGetMemoryTypes", ret)
            End If

            ret = CONACloseFS(hFS)
            If ret <> CONA_OK Then ShowErrorMessage("CONACloseFS", ret)
        End If
    End Function

    '===================================================================
    ' ListAllPhones
    '
    ' Adds all connected phones to list box
    ' 
    '===================================================================
    Public Sub ListAllPhones()
        On Error Resume Next

        Dim i As Short
        Dim ret As Integer
        Dim piCount As Integer
        Dim iPtr As Int64
        Dim buffer As IntPtr
        Dim ptr As IntPtr
        Dim strText As String
        Dim pDevices() As CONAPI_DEVICE

        MainForm.Timer1.Enabled = False
        m_wState = PHONELIST_STATE_PHONELIST
        ResetContent()
        m_strCurrentFolder = ""
        ' Querying count of connected devices
        ret = CONAGetDeviceCount(m_hDMHandle, piCount)
        If ret <> CONA_OK Then ShowErrorMessage("CONAGetDeviceCount", ret)
        If ret = CONA_OK And piCount > 0 Then
            ReDim pDevices(piCount)
            ReDim m_strSerialNumbers(piCount)
            ReDim m_strFriendlyNames(piCount)
            ' Allocate memory for buffer
            buffer = Marshal.AllocHGlobal(piCount * Marshal.SizeOf(GetType(CONAPI_DEVICE)))
            ' Get list of currently connected devices
            ret = CONAGetDevices(m_hDMHandle, piCount, buffer)
            If ret <> CONA_OK Then
                ShowErrorMessage("CONAGetDevices", ret)
            Else
                ReDim ItemData(piCount)
                ' Add each device to the phone list box
                For i = 0 To piCount - 1
                    ' Calculate beginning of CONAPI_DEVICE structure of item 'i'
                    iPtr = buffer.ToInt64 + i * Marshal.SizeOf(GetType(CONAPI_DEVICE))
                    ' Convert integer to pointer
                    ptr = IntPtr.op_Explicit(iPtr)
                    ' Copy data from buffer
                    pDevices(i) = Marshal.PtrToStructure(ptr, GetType(CONAPI_DEVICE))
                    ' Add item to list box
                    strText = pDevices(i).pstrFriendlyName & " ("
                    strText &= GetFreeMemoryString(pDevices(i)) & ")"
                    Me.Items.Add(strText)
                    m_strSerialNumbers(i) = pDevices(i).pstrSerialNumber
                    m_strFriendlyNames(i) = pDevices(i).pstrFriendlyName
                Next
                ' CONAGetDevices allocates memory for the member variables in
                ' CONAPI_DEVICE and it is callers responsibility to free it...
                ret = CONAFreeDeviceStructure(piCount, buffer)
                If ret <> CONA_OK Then ShowErrorMessage("CONAFreeDeviceStructure", ret)
            End If
            Marshal.FreeHGlobal(buffer)
        End If
        MainForm.LBL_PhoneFiles.Text = ""
        MainForm.bRefreshPhoneListBox = False
        MainForm.Timer1.Enabled = True
    End Sub

    '===================================================================
    ' ResetContent
    '
    ' Clear contents of list box
    ' 
    '===================================================================
    Public Sub ResetContent()
        Me.Items.Clear()
    End Sub

    '===================================================================
    ' GetSelectedFolder
    '
    ' Returns currently selected folder
    '
    '===================================================================
    Public Function GetSelectedFolder() As String
        GetSelectedFolder = m_strCurrentFolder
        ' Let's check if there is phone folder selected
        Dim index As Integer = SelectedIndex
        If m_wState = PHONELIST_STATE_PHONECONTENT And index <> -1 Then
            ' there is a selected item
            Dim strSelectedTxt As String
            strSelectedTxt = Items(SelectedIndex).ToString()
            If strSelectedTxt.Substring(0, 1) = "[" And strSelectedTxt <> "[..]" Then
                ' folder [directoryname]
                If Not GetSelectedFolder.EndsWith("\") Then GetSelectedFolder &= "\"
                GetSelectedFolder &= ItemData(index)
            End If
        End If
    End Function

    '===================================================================
    ' GetCurrentFolder
    '
    ' Returns folder, the content of which is currently shown 
    ' 
    '===================================================================
    Public Function GetCurrentFolder() As String
        GetCurrentFolder = m_strCurrentFolder
    End Function

    '===================================================================
    ' GetCurrentFile
    '
    ' Returns selected file. Return empty string if no file is selected.
    ' 
    '===================================================================
    Public Function GetCurrentFile() As String
        GetCurrentFile = ""
        Dim index As Integer = SelectedIndex
        If m_wState = PHONELIST_STATE_PHONECONTENT And index <> -1 Then
            ' there is a selected item
            Dim strSelectedTxt As String
            strSelectedTxt = Items(index).ToString()
            If strSelectedTxt.Substring(0, 1) <> "[" Then
                ' selected item is file
                GetCurrentFile = ItemData(index)
            End If
        End If
    End Function

    '===================================================================
    ' PhoneListBox_DoubleClick
    '
    ' Called when user doubleclicks list item
    ' 
    '===================================================================
    Private Sub PhoneListBox_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
        If m_wState = PHONELIST_STATE_PHONELIST Then
            m_strCurrentSN = GetCurrentSN()
            m_strCurrentFriendlyName = GetCurrentFriendlyName()
            If Len(m_strCurrentSN) > 0 Then
                ResetContent() ' removing phones
                m_wState = PHONELIST_STATE_PHONECONTENT
                ShowPhoneFolder(g_strPhoneRoot)
            End If
        ElseIf m_wState = PHONELIST_STATE_PHONECONTENT Then
            PhoneItemDblClicked()
        End If
    End Sub

    '===================================================================
    ' GetItemData
    '
    ' Return item data of list box item
    ' 
    '===================================================================
    Public Function GetItemData(ByVal index As Integer) As String
        GetItemData = ItemData(index)
    End Function

    '===================================================================
    ' GetDMHandle
    '
    ' Return device management handle
    ' 
    '===================================================================
    Public Function GetDMHandle() As Integer
        GetDMHandle = m_hDMHandle
    End Function
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -