Beispiel #1
0
        /// <summary>
        /// Sets an extension control property image (if supported by tablet).
        /// </summary>
        /// <param name="context_I">wintab context</param>
        /// <param name="extTagIndex_I">which extension tag we're setting</param>
        /// <param name="tabletIndex_I">index of the tablet being set</param>
        /// <param name="controlIndex_I">the index of the control being set</param>
        /// <param name="functionIndex_I">the index of the control function being set</param>
        /// <param name="propertyID_I">ID of the property being set</param>
        /// <param name="value_I">value of the property being set (a string)</param>
        /// <returns>true if successful</returns>
        public static bool ControlPropertySetImage(
            HCTX context_I,
            byte extTagIndex_I,
            byte tabletIndex_I,
            byte controlIndex_I,
            byte functionIndex_I,
            ushort propertyID_I,
            String imageFilePath_I
            )
        {
            bool retStatus = false;
            WTExtensionImageProperty extProperty = new WTExtensionImageProperty();
            IntPtr buf = CMemUtils.AllocUnmanagedBuf(extProperty);

            try
            {
                byte[] imageBytes             = null;
                System.Drawing.Image newImage = Image.FromFile(imageFilePath_I);

                if (newImage == null)
                {
                    MessageBox.Show("Oops - couldn't find/read image: " + imageFilePath_I);
                    return(false);
                }

                using (MemoryStream ms = new MemoryStream())
                {
                    newImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    imageBytes = ms.ToArray();
                }

                extProperty.extBase.version       = 0;
                extProperty.extBase.tabletIndex   = tabletIndex_I;
                extProperty.extBase.controlIndex  = controlIndex_I;
                extProperty.extBase.functionIndex = functionIndex_I;
                extProperty.extBase.propertyID    = propertyID_I;
                extProperty.extBase.reserved      = 0;
                extProperty.extBase.dataSize      = (uint)imageBytes.Length;
                extProperty.data = new byte[WTExtensionsGlobal.WTExtensionPropertyImageMaxDataBytes];

                // Send image as an array of bytes.
                System.Buffer.BlockCopy(imageBytes, 0, extProperty.data, 0, (int)extProperty.extBase.dataSize);

                Marshal.StructureToPtr(extProperty, buf, false);

                retStatus = CWintabFuncs.WTExtSet((UInt32)context_I, (UInt32)extTagIndex_I, buf);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(retStatus);
        }
Beispiel #2
0
        /// <summary>
        /// Sets an extension control property string.
        /// </summary>
        /// <param name="context_I">wintab context</param>
        /// <param name="extTagIndex_I">which extension tag we're setting</param>
        /// <param name="tabletIndex_I">index of the tablet being set</param>
        /// <param name="controlIndex_I">the index of the control being set</param>
        /// <param name="functionIndex_I">the index of the control function being set</param>
        /// <param name="propertyID_I">ID of the property being set</param>
        /// <param name="value_I">value of the property being set (a string)</param>
        /// <returns>true if successful</returns>
        public static bool ControlPropertySet(
            HCTX context_I,
            byte extTagIndex_I,
            byte tabletIndex_I,
            byte controlIndex_I,
            byte functionIndex_I,
            ushort propertyID_I,
            String value_I
            )
        {
            bool retStatus = false;
            WTExtensionProperty extProperty = new WTExtensionProperty();
            IntPtr buf = CMemUtils.AllocUnmanagedBuf(extProperty);

            try
            {
                // Convert unicode string value_I to UTF8-encoded bytes
                byte[] utf8Bytes = System.Text.Encoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(value_I));

                extProperty.extBase.version       = 0;
                extProperty.extBase.tabletIndex   = tabletIndex_I;
                extProperty.extBase.controlIndex  = controlIndex_I;
                extProperty.extBase.functionIndex = functionIndex_I;
                extProperty.extBase.propertyID    = propertyID_I;
                extProperty.extBase.reserved      = 0;
                extProperty.extBase.dataSize      = (uint)utf8Bytes.Length;
                extProperty.data = new byte[WTExtensionsGlobal.WTExtensionPropertyMaxDataBytes];

                // Send input value as an array of UTF8-encoded bytes.
                System.Buffer.BlockCopy(utf8Bytes, 0, extProperty.data, 0, (int)extProperty.extBase.dataSize);

                Marshal.StructureToPtr(extProperty, buf, false);

                retStatus = CWintabFuncs.WTExtSet((UInt32)context_I, (UInt32)extTagIndex_I, buf);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(retStatus);
        }
Beispiel #3
0
        /// <summary>
        /// Sets an extension control property value.
        /// </summary>
        /// <param name="context_I">wintab context</param>
        /// <param name="extTagIndex_I">which extension tag we're setting</param>
        /// <param name="tabletIndex_I">index of the tablet being set</param>
        /// <param name="controlIndex_I">the index of the control being set</param>
        /// <param name="functionIndex_I">the index of the control function being set</param>
        /// <param name="propertyID_I">ID of the property being set</param>
        /// <param name="value_I">value of the property being set</param>
        /// <returns>true if successful</returns>
        public static bool ControlPropertySet(
            HCTX context_I,
            byte extTagIndex_I,
            byte tabletIndex_I,
            byte controlIndex_I,
            byte functionIndex_I,
            ushort propertyID_I,
            UInt32 value_I
            )
        {
            bool retStatus = false;
            WTExtensionProperty extProperty = new WTExtensionProperty();
            IntPtr buf = CMemUtils.AllocUnmanagedBuf(extProperty);

            try
            {
                byte[] valueBytes = BitConverter.GetBytes(value_I);

                extProperty.extBase.version       = 0;
                extProperty.extBase.tabletIndex   = tabletIndex_I;
                extProperty.extBase.controlIndex  = controlIndex_I;
                extProperty.extBase.functionIndex = functionIndex_I;
                extProperty.extBase.propertyID    = propertyID_I;
                extProperty.extBase.reserved      = 0;
                extProperty.extBase.dataSize      = (uint)System.Runtime.InteropServices.Marshal.SizeOf(value_I);
                extProperty.data = new byte[WTExtensionsGlobal.WTExtensionPropertyMaxDataBytes];

                // Send input value as an array of bytes.
                System.Buffer.BlockCopy(valueBytes, 0, extProperty.data, 0, (int)extProperty.extBase.dataSize);

                Marshal.StructureToPtr(extProperty, buf, false);

                retStatus = CWintabFuncs.WTExtSet((UInt32)context_I, (UInt32)extTagIndex_I, buf);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(retStatus);
        }