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

📄 btpairingdlg.cs

📁 以前做NOKIA手机与PC通信时所参考的源代码,里面包括两个程序,一个是手机文件夹浏览源码,另一个手机SIS安装程序.
💻 CS
📖 第 1 页 / 共 2 页
字号:
//Filename    : BTPairingDlg.cs
//Part of     : Phone Navigator C# example
//Description : Dialog for pairing Bluetooth devices
//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) 2005-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.Runtime.InteropServices;
namespace CSPhoneNavigator.NET
{
    using PCCSErrors;
    using PCCAPIUtils;
    using CONADefinitions;
    using CONADeviceManagement;
    using System.Windows.Forms;
    public class FRM_BTPairing : System.Windows.Forms.Form
    {

        private struct BTDevice
        {
            public string strName;
            public string strAddress;
            public int iDeviceID;
            public int iStatus;
        }

        private bool m_bDisposed = false;
        // Device management handle
        private int m_hDMHandle;
        private BTDevice[] m_pDevices;
        private CONADefinitions.SearchCallbackDelegate m_pfnSearchNotify;
        private FRM_ProgressDlg m_pProgressDlg;

        #region " Windows Form Designer generated code "

        //===================================================================
        // Constructor
        //
        //===================================================================
        public FRM_BTPairing()
            : base()
        {

            //This call is required by the Windows Form Designer.
            InitializeComponent();

            //Add any initialization after the InitializeComponent() call

            // Get Device management handle
            int iRet = CONADeviceManagement.CONAOpenDM(ref m_hDMHandle);
            if (iRet != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONAOpenDM", iRet);
        }

        //Form overrides dispose to clean up the component list.
        protected override void Dispose(bool disposing)
        {
            if (!m_bDisposed)
            {
                base.Dispose(disposing);
            }
            m_bDisposed = true;
        }

        //Required by the Windows Form Designer
        private System.ComponentModel.IContainer components;

        //NOTE: The following procedure is required by the Windows Form Designer
        //It can be modified using the Windows Form Designer.  
        //Do not modify it using the code editor.
        internal System.Windows.Forms.Button BTN_Close;
        internal System.Windows.Forms.Button BTN_Search;
        internal System.Windows.Forms.Button BTN_Pair;
        internal System.Windows.Forms.Button BTN_Unpair;
        internal System.Windows.Forms.Button BTN_SetTrusted;
        internal System.Windows.Forms.Button BTN_SetUnTrusted;
        internal System.Windows.Forms.ListView LVW_PhoneList;
        internal System.Windows.Forms.ColumnHeader ColumnHeader1;
        internal System.Windows.Forms.ColumnHeader ColumnHeader2;
        [System.Diagnostics.DebuggerStepThrough()]
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FRM_BTPairing));
            this.LVW_PhoneList = new System.Windows.Forms.ListView();
            this.ColumnHeader1 = new System.Windows.Forms.ColumnHeader();
            this.ColumnHeader2 = new System.Windows.Forms.ColumnHeader();
            this.BTN_Close = new System.Windows.Forms.Button();
            this.BTN_Search = new System.Windows.Forms.Button();
            this.BTN_Pair = new System.Windows.Forms.Button();
            this.BTN_Unpair = new System.Windows.Forms.Button();
            this.BTN_SetTrusted = new System.Windows.Forms.Button();
            this.BTN_SetUnTrusted = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // LVW_PhoneList
            // 
            this.LVW_PhoneList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.ColumnHeader1,
            this.ColumnHeader2});
            this.LVW_PhoneList.FullRowSelect = true;
            this.LVW_PhoneList.Location = new System.Drawing.Point(8, 8);
            this.LVW_PhoneList.Name = "LVW_PhoneList";
            this.LVW_PhoneList.Size = new System.Drawing.Size(272, 136);
            this.LVW_PhoneList.TabIndex = 0;
            this.LVW_PhoneList.UseCompatibleStateImageBehavior = false;
            this.LVW_PhoneList.View = System.Windows.Forms.View.Details;
            // 
            // ColumnHeader1
            // 
            this.ColumnHeader1.Text = "Phone name";
            this.ColumnHeader1.Width = 134;
            // 
            // ColumnHeader2
            // 
            this.ColumnHeader2.Text = "Status";
            this.ColumnHeader2.Width = 134;
            // 
            // BTN_Close
            // 
            this.BTN_Close.Location = new System.Drawing.Point(288, 8);
            this.BTN_Close.Name = "BTN_Close";
            this.BTN_Close.Size = new System.Drawing.Size(80, 24);
            this.BTN_Close.TabIndex = 7;
            this.BTN_Close.Text = "Close";
            this.BTN_Close.Click += new System.EventHandler(this.BTN_Close_Click);
            // 
            // BTN_Search
            // 
            this.BTN_Search.Location = new System.Drawing.Point(8, 160);
            this.BTN_Search.Name = "BTN_Search";
            this.BTN_Search.Size = new System.Drawing.Size(88, 24);
            this.BTN_Search.TabIndex = 8;
            this.BTN_Search.Text = "Refresh List";
            this.BTN_Search.Click += new System.EventHandler(this.BTN_Search_Click);
            // 
            // BTN_Pair
            // 
            this.BTN_Pair.Location = new System.Drawing.Point(104, 160);
            this.BTN_Pair.Name = "BTN_Pair";
            this.BTN_Pair.Size = new System.Drawing.Size(80, 24);
            this.BTN_Pair.TabIndex = 9;
            this.BTN_Pair.Text = "Pair";
            this.BTN_Pair.Click += new System.EventHandler(this.BTN_Pair_Click);
            // 
            // BTN_Unpair
            // 
            this.BTN_Unpair.Location = new System.Drawing.Point(104, 192);
            this.BTN_Unpair.Name = "BTN_Unpair";
            this.BTN_Unpair.Size = new System.Drawing.Size(80, 24);
            this.BTN_Unpair.TabIndex = 10;
            this.BTN_Unpair.Text = "Unpair";
            this.BTN_Unpair.Click += new System.EventHandler(this.BTN_Unpair_Click);
            // 
            // BTN_SetTrusted
            // 
            this.BTN_SetTrusted.Location = new System.Drawing.Point(192, 160);
            this.BTN_SetTrusted.Name = "BTN_SetTrusted";
            this.BTN_SetTrusted.Size = new System.Drawing.Size(88, 24);
            this.BTN_SetTrusted.TabIndex = 11;
            this.BTN_SetTrusted.Text = "Set Trusted";
            this.BTN_SetTrusted.Click += new System.EventHandler(this.BTN_SetTrusted_Click);
            // 
            // BTN_SetUnTrusted
            // 
            this.BTN_SetUnTrusted.Location = new System.Drawing.Point(192, 192);
            this.BTN_SetUnTrusted.Name = "BTN_SetUnTrusted";
            this.BTN_SetUnTrusted.Size = new System.Drawing.Size(88, 24);
            this.BTN_SetUnTrusted.TabIndex = 12;
            this.BTN_SetUnTrusted.Text = "Set Untrusted";
            this.BTN_SetUnTrusted.Click += new System.EventHandler(this.BTN_SetUnTrusted_Click);
            // 
            // FRM_BTPairing
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(378, 224);
            this.Controls.Add(this.BTN_SetUnTrusted);
            this.Controls.Add(this.BTN_SetTrusted);
            this.Controls.Add(this.BTN_Unpair);
            this.Controls.Add(this.BTN_Pair);
            this.Controls.Add(this.BTN_Search);
            this.Controls.Add(this.BTN_Close);
            this.Controls.Add(this.LVW_PhoneList);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FRM_BTPairing";
            this.Text = "Bluetooth Pairing";
            this.Load += new System.EventHandler(this.FRM_BTPairing_Load);
            this.ResumeLayout(false);

        }

        #endregion

        //===================================================================
        // BTPairingNotifyCallback
        //
        // BT device searching callback funtion. Shows the progress dialog
        // at the beginning of search and sets the progress dialog progress
        // bar to correct position.
        // If function m_pProgressDlg.IsCancelled returns TRUE, this
        // function returns ECONA_CANCELLED, and connectivity API stops
        // the device search.
        // In other situations this function must always return PCCSErrors.CONA_OK.
        //===================================================================
        public int BTPairingNotifyCallback(int iState, System.IntPtr pConnInfoStructure)
        {
            int functionReturnValue = 0;
            functionReturnValue = PCCSErrors.CONA_OK;
            // iState value grows from 0 to 100
            if (iState < 100)
            {
                if (m_pProgressDlg == null)
                {
                    // Start progress dialog
                    m_pProgressDlg = new FRM_ProgressDlg();
                    m_pProgressDlg.Show();
                }
                // Update progress bar
                m_pProgressDlg.SetProgress(iState);
            }
            if (m_pProgressDlg.IsCancelled())
            {
                // If user has clicked Cancel, return ECONA_CANCELLED
                functionReturnValue = PCCSErrors.ECONA_CANCELLED;
            }
            Application.DoEvents();
            return functionReturnValue;

⌨️ 快捷键说明

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