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

📄 common.cs

📁 以前做NOKIA手机与PC通信时所参考的源代码,里面包括两个程序,一个是手机文件夹浏览源码,另一个手机SIS安装程序.
💻 CS
字号:
//Filename    : Common.CS
//Part of     : Phone Navigator C# example
//Description : Main module of CSFileBrowser.NET example application
//Version     : 3.2
//
//This example is only to be used with PC Connectivity API version 3.2.
//Compability ("as is") with future versions is not quaranteed.
//
//Copyright (c) 2007 Nokia Corporation.
//
//This material, including but not limited to documentation and any related
//computer programs, is protected by intellectual property rights of Nokia
//Corporation and/or its licensors.
//All rights are reserved. Reproducing, modifying, translating, or
//distributing any or all of this material requires the prior written consent
//of Nokia Corporation. Nokia Corporation retains the right to make changes
//to this material at any time without notice. A copyright license is hereby
//granted to download and print a copy of this material for personal use only.
//No other license to any other intellectual property rights is granted. The
//material is provided "as is" without warranty of any kind, either express or
//implied, including without limitation, any warranty of non-infringement,
//merchantability and fitness for a particular purpose. In no event shall
//Nokia Corporation be liable for any direct, indirect, special, incidental,
//or consequential loss or damages, including but not limited to, lost profits
//or revenue,loss of use, cost of substitute program, or loss of data or
//equipment arising out of the use or inability to use the material, even if
//Nokia Corporation has been advised of the likelihood of such damages occurring.
using System;
using System.Runtime.InteropServices;
namespace CSFileBrowser.NET
{
    using PCCSErrors;
    using CONADefinitions;
    class Common
    {
        public const short PHONELIST_STATE_PHONELIST = 1;
        public const short PHONELIST_STATE_PHONECONTENT = 2;

        public static FileBrowser MainForm;
        public static CONADefinitions.DeviceNotifyCallbackDelegate pDeviceCallBack;

        public struct SYSTEMTIME {
            public UInt16 wYear;
            public UInt16 wMonth;
            public UInt16 wDayOfWeek;
            public UInt16 wDay;
            public UInt16 wHour;
            public UInt16 wMinute;
            public UInt16 wSecond;
            public UInt16 wMilliseconds;
        }

        [DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        public static extern int FileTimeToSystemTime(
            ref System.Runtime.InteropServices.ComTypes.FILETIME ft,
            ref SYSTEMTIME st
            );

        public static string GetLocalFormattedDate(System.Runtime.InteropServices.ComTypes.FILETIME dwTime) {
            string strRetval = "";
            if ((dwTime.dwHighDateTime != 0) & (dwTime.dwLowDateTime != 0 )) {
                SYSTEMTIME st= new SYSTEMTIME();
                FileTimeToSystemTime(ref dwTime, ref st);
                DateTime dt = new DateTime(st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, DateTimeKind.Local);
                strRetval = dt.ToString();
            } 
            return strRetval;
        }

        public static string StrFormatByteSize(long lSize)
        {
            float dlSize = 0.0F;
            string strRetval = "";
            if (lSize < 1000)
                strRetval = lSize.ToString() + " bytes";
            else if (lSize < 1000000)
            {
                dlSize = lSize / 1000;
                strRetval = String.Format("{0:0.0}", dlSize) + "KB";
            }
            else if (lSize < 1000000000)
            {
                dlSize = lSize / 1000000;
                strRetval = String.Format("{0:0.0}", dlSize) + "MB";
            }
            else if (lSize < 1000000000000)
            {
                dlSize = lSize / 1000000000;
                strRetval = String.Format("{0:0.0}", dlSize) + "GB";
            }
            else
            {
                dlSize = lSize / 1000000000000;
                strRetval = String.Format("{0:0.0}", dlSize) + "TB";
            }
            return strRetval;
        }

        //===================================================================
        // DeviceNotifyCallback
        //
        // Callback function for device connection notifications
        //
        //===================================================================
        public static int DeviceNotifyCallback(
           int iStatus, 
            [MarshalAs(UnmanagedType.LPWStr)] string pstrSerialNumber)
        {
            int functionReturnValue = 0;
            try
            {
                if (MainForm.LBX_PhoneFiles.GetState() == PHONELIST_STATE_PHONELIST)
                {
                    MainForm.bRefreshPhoneListBox = true;
                }
                else
                {
                    if (CONADefinitions.GET_CONAPI_CB_STATUS(iStatus) == CONADefinitions.CONAPI_DEVICE_REMOVED)
                    {
                        MainForm.bRefreshPhoneListBox = (pstrSerialNumber == MainForm.LBX_PhoneFiles.GetCurrentSN());
                    }
                }
                functionReturnValue = PCCSErrors.CONA_OK;
            }
            catch (Exception e) 
            {
                MainForm.bRefreshPhoneListBox = true;
            }
            return functionReturnValue;
        }
    }
}

⌨️ 快捷键说明

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