////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Registers an MTAPI raw data client over the entire tablet surface
        /// (no hitrect or HWND required).
        /// </summary>
        /// <param name="deviceID_I">touch device identifier</param>
        /// <param name="callback_I">callback function used by MTAPI to send touch data</param>
        /// <param name="userData_I">custom user data</param>
        public void RegisterClient(Int32 deviceID_I,
                                   ref WacomMTCallback callback_I, IntPtr userData_I)
        {
            try
            {
                InitWacomMTClientParams(deviceID_I, ref callback_I, userData_I);

                WacomMTError res = CWacomMTInterface.WacomMTRegisterRawReadCallback(
                    mDeviceID, mClientMode, mTouchCallback, mUserData);

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed WacomMTRegisterRawReadCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }

#if TRACE_CLIENT
                DumpClient("RegisterClient");
#endif //TRACE_CLIENT
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            WacomMTError status = WacomMTError.WMTErrorSuccess;

            IntPtr userDataBuf = IntPtr.Zero;

            try
            {
                mWacomMTConfig.Init();

                //Delegate called when events come to tablet
                mUpdateRealTimeLabel  = new UpdateDelegate(this.DoUpdateGraphicsControl);
                mUpdateRealTimeLabel += this.DoSendMidiMessage;

                // crée un nouveau callback attach et abonne a ce callback
                mAttachCallback = new WacomMTAttachCallback(this.DoAttachWindowClientCallback);
                status          = CWacomMTInterface.WacomMTRegisterAttachCallback(this.mAttachCallback, IntPtr.Zero);

                if (status != WacomMTError.WMTErrorSuccess)
                {
                    throw new Exception("Failed to register for device attaches - err: " + status.ToString());
                }

                // crée un nouveau callback detack et abonne a ce callback
                mDetachCallback = new WacomMTDetachCallback(this.DoDetachWindowClientCallback);
                status          = CWacomMTInterface.WacomMTRegisterDetachCallback(this.mDetachCallback, IntPtr.Zero);

                if (status != WacomMTError.WMTErrorSuccess)
                {
                    throw new Exception("Failed to register for device detaches - err: " + status.ToString());
                }

                //crée un nouveau callback de type Finger Read et abonne a celui-ci
                WacomMTHitRect HR = new WacomMTHitRect(0, 0, 0, 0);
                mTouchDataCallback = new WacomMTCallback(this.DoFingerDataUpdateCallback);
                status             = CWacomMTInterface.WacomMTRegisterFingerReadCallback(0, ref HR, _processingMode,
                                                                                         mTouchDataCallback, IntPtr.Zero);

                UpdateLabelText();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.ToString());
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Unregisters an MTAPI HWND client.
        /// </summary>
        public void UnregisterHWNDClient()
        {
            try
            {
                ThrowIfInvalidHWND(mHwnd);

                WacomMTError res = DoUnregisterHwndCallback();

                ClearWacomMTWindowClientParams();

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed DoUnregisterHwndCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        // -------------------------------------------------------------------------
        // Hwnd methods
        // -------------------------------------------------------------------------

        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Register an MTAPI client by its window handle.
        /// </summary>
        /// <param name="deviceID_I">touch device identifier</param>
        /// <param name="hwnd_I">window handle tracked by MTAPI for touch contacts</param>
        /// <param bufferDepth_I="userData_I">number of callback buffers that MTAPI creates</param>
        public void RegisterHWNDClient(Int32 deviceID_I, HWND hwnd_I,
                                       Int32 bufferDepth_I = 1)
        {
            try
            {
                InitWacomMTHwndClientParams(deviceID_I, hwnd_I, bufferDepth_I);

                WacomMTError res = DoRegisterHwndCallback();

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed DoRegisterHwndCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Changes a hitrect client's current hitrect.
        /// </summary>
        /// <param name="newHitRect_I">rectangle tracked by MTAPI for touch contacts</param>
        /// <param name="userData_I">custom user data</param>
        public void MoveHitRectClient(WacomMTHitRect newHitRect_I, IntPtr userData_I)
        {
            try
            {
                WacomMTError   res        = WacomMTError.WMTErrorSuccess;
                WacomMTHitRect oldHitRect = mHitRect;
                WacomMTHitRect newHitRect = newHitRect_I;

                ThrowIfInvalidDeviceID(mDeviceID);
                ThrowIfInvalidHitRect(ref oldHitRect);
                ThrowIfInvalidHitRect(ref newHitRect);

                res = DoMoveHitRectCallback(newHitRect, userData_I);

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed DoMoveHitRectCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }

                mHitRect  = newHitRect;
                mUserData = userData_I;

#if TRACE_CLIENT
                DumpClient("MoveHitRectClient");
#endif //TRACE_CLIENT
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Unregisters an MTAPI hitrect client
        /// </summary>
        public void UnregisterHitRectClient()
        {
            try
            {
                ThrowIfInvalidDeviceID(mDeviceID);
                ThrowIfInvalidHitRect(ref mHitRect);

#if TRACE_CLIENT
                DumpClient("UnregisterHitRectClient");
#endif //TRACE_CLIENT

                WacomMTError res = DoUnregisterHitRectCallback();

                ClearWacomMTWindowClientParams();

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed to unregister a hitrect client with error: " + res.ToString();
                    throw new Exception(errMsg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        // -------------------------------------------------------------------------
        // HitRect methods
        // -------------------------------------------------------------------------

        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Registers an MTAPI windowed client using a hitrect.
        /// </summary>
        /// <param name="deviceID_I">touch device identifier</param>
        /// <param name="hitrect_I">rectangle tracked by MTAPI for touch contacts</param>
        /// <param name="callback_I">callback function used by MTAPI to send touch data</param>
        /// <param name="userData_I">custom user data</param>
        public void RegisterHitRectClient(Int32 deviceID_I, WacomMTHitRect hitrect_I,
                                          ref WacomMTCallback callback_I, IntPtr userData_I)
        {
            try
            {
                InitWacomMTHitRectClientParams(deviceID_I, hitrect_I, ref callback_I, userData_I);

                WacomMTError res = DoRegisterHitRectCallback();

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed DoRegisterHitRectCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }

#if TRACE_CLIENT
                DumpClient("RegisterHitRectClient");
#endif //TRACE_CLIENT
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }