示例#1
0
        /// <summary>
        /// ペンタブレットを初期化します
        /// </summary>
        public static void Initialize()
        {
            if (WintabManager.IsWintabAvailable() == false || Application.Current.MainWindow == null)
            {
                return;
            }

            try
            {
                WintabLogContext context = WintabManager.GetDefaultSystemContext(ECTXOptionValues.CXO_SYSTEM);
                context.lcName = "Wintab sample";

                // ウインドウハンドルの取得
                WindowInteropHelper helper = new WindowInteropHelper(Application.Current.MainWindow);
                IntPtr hWnd = helper.Handle;

                // Wintabハンドル
                IntPtr m_hCtx = IntPtr.Zero;

                // タブレットの受信開始
                m_hCtx = WintabManager.Open(hWnd, context);
                if (m_hCtx != IntPtr.Zero)
                {
                    // ウインドウプロシージャをフックする
                    HwndSource source = HwndSource.FromHwnd(helper.Handle);
                    source.AddHook(new HwndSourceHook(WndProc));
                }

                maxPressure = WintabManager.GetDeviceNPressure().axMax;
                maxZ        = WintabManager.GetTabletAxis(EAxisDimension.AXIS_Z).axMax;
                Enable      = WintabManager.IsWintabAvailable();

                watchDogTimer.Tick += WatchDogTimer_Tick;
                watchDogTimer.Start();
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
示例#2
0
        private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == (int)EWintabEventMessage.WT_PACKET)
            {
                packet   = WintabManager.GetPacket(lParam, (uint)wParam.ToInt32());
                usingPen = true;

                uint button = packet.pkButtons & 0x00000001;
                if (button == 1)
                {
                    uint highWord = (packet.pkButtons & 0xFFFF0000) >> 16;

                    if ((highWord & 2) != 0)
                    {
                        ButtonPressed = true;
                    }
                    else if ((highWord & 1) != 0)
                    {
                        ButtonPressed = false;
                    }
                }
            }
            return(IntPtr.Zero);
        }