コード例 #1
0
        /// <summary>
        /// Specifies a common dialog box.
        /// </summary>
        /// <param name="hwndOwner">A value that represents the window handle of the owner window for the common dialog box.</param>
        /// <returns>true if the dialog box was successfully run; otherwise, false.</returns>
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            AssertWindowsFormsThread();
            if (this._ShowDiscoverableOnly) {
                // ShowDiscoverableOnly is not supported by the Microsoft stack on desktop Windows.
                return false;
            }
            //
            if ((object)dialogWin32 != (object)dialog) {
                dialogWin32 = (BLUETOOTH_SELECT_DEVICE_PARAMS)dialog;
            }
            //set parent window
            dialogWin32.hwndParent = hwndOwner;

            //set class of device filters
            dialogWin32.SetClassOfDevices(ClassOfDevices.ToArray());

            bool success = NativeMethods.BluetoothSelectDevices(ref dialogWin32);

            if (success) {
                if (dialogWin32.cNumDevices > 0) {
                    device = new BluetoothDeviceInfo(new WindowsBluetoothDeviceInfo(dialogWin32.Device));
                }

                bool freed = NativeMethods.BluetoothSelectDevicesFree(ref dialogWin32);
            }

            return success;
        }
コード例 #2
0
        public Task <BluetoothDeviceInfo> PickSingleDeviceAsync()
        {
            BluetoothDeviceInfo info = null;

            BLUETOOTH_SELECT_DEVICE_PARAMS p = new BLUETOOTH_SELECT_DEVICE_PARAMS();

            p.Reset();
            p.SetClassOfDevices(ClassOfDevices.ToArray());
            p.fForceAuthentication = RequireAuthentication;
            p.hwndParent           = NativeMethods.GetActiveWindow();
            if (NativeMethods.BluetoothSelectDevices(ref p))
            {
                info = new BluetoothDeviceInfo(p.Device);
            }

            return(Task.FromResult(info));
        }
コード例 #3
0
        private async Task <BluetoothDeviceInfo> DoPickSingleDeviceAsync()
        {
            BLUETOOTH_SELECT_DEVICE_PARAMS p = new BLUETOOTH_SELECT_DEVICE_PARAMS();

            p.Reset();
            p.SetClassOfDevices(ClassOfDevices.ToArray());
            p.fForceAuthentication = RequireAuthentication;

            bool success = NativeMethods.BluetoothSelectDevices(ref p);

            if (success)
            {
                return(new BluetoothDeviceInfo(p.Device));
            }

            return(null);
        }