/// <inheritdoc />
	internal bool Initialize()
	{

		try
		{

			var platform = Application.platform;
			var canRunOnPlatform =
				platform == RuntimePlatform.WindowsPlayer ||
				platform == RuntimePlatform.MetroPlayerARM ||
				platform == RuntimePlatform.MetroPlayerX64 ||
				platform == RuntimePlatform.MetroPlayerX86 ||
				platform == RuntimePlatform.WP8Player;

			if( !canRunOnPlatform )
				return false;

			hMainWindow = GetForegroundWindow();

			newWndProc = new WndProcDelegate( wndProc );
			newWndProcPtr = Marshal.GetFunctionPointerForDelegate( newWndProc );
			oldWndProcPtr = SetWindowLong( hMainWindow, -4, newWndProcPtr );

			isInitialized = true;

			return true;

		}
		catch( Exception err )
		{
			Debug.LogError( err.Message );
			return false;
		}

	}
Example #2
0
        public WndProcReader(WndProcDelegate del)
        {
            this.del = del;

            // Create the actual window
            base.CreateHandle(cp);
        }
Example #3
0
        public Hwnd(WndProcDelegate del)
        {
            this.del = del;

            // Create the actual window
            this.CreateHandle(cp);
        }
	public bool Initialize()
	{

		try
		{

			if( Application.platform != RuntimePlatform.WindowsPlayer )
				return false;

			touchInputSize = Marshal.SizeOf( typeof( TOUCHINPUT ) );

			hMainWindow = GetForegroundWindow();
			if( !RegisterTouchWindow( hMainWindow, 0 ) )
			{
				Debug.LogWarning( "Failed to register Windows 7 touch window" );
				return false;
			}

			newWndProc = new WndProcDelegate( wndProc );
			newWndProcPtr = Marshal.GetFunctionPointerForDelegate( newWndProc );
			oldWndProcPtr = SetWindowLong( hMainWindow, -4, newWndProcPtr );

			isInitialized = true;

			return true;

		}
		catch( Exception err )
		{
			Debug.LogError( err.Message );
			return false;
		}

	}
Example #5
0
        /// <summary>
        /// �R���X�g���N�^
        /// </summary>
        /// <param name="targetTextBox">�����Ώۂ̃e�L�X�g�{�b�N�X</param>
        public TextBoxInputFilter(TextBox targetTextBox)
        {
            targetHandle = targetTextBox.Handle;
            wndProc = new WndProcDelegate(WndProc);
            wndProcPtr = Marshal.GetFunctionPointerForDelegate(wndProc);

            // �T�u�N���X������
            oldWndProc = SetWindowLong(targetHandle, GWL_WNDPROC, wndProcPtr);
        }
Example #6
0
 public WindowSubclassingMessageFilter(IntPtr hWnd)
 {
     if (!Win32.IsWindow(hWnd)) { throw new ArgumentException(); }
     this.procs = new Dictionary<int, MessageProc>();
     this.hWnd = hWnd;
     this.newWndProcDelegate = this.WndProc;
     this.newWndProc = Marshal.GetFunctionPointerForDelegate(newWndProcDelegate);
     this.oldWndProc = Win32.GetWindowLong(hWnd, -4);
     Win32.SetWindowLong(hWnd, -4, newWndProc);
 }
Example #7
0
 void OnDisable()
 {
     Debug.Log("Uninstall Hook");
     if (!isrunning) return;
     SetWindowLong(hMainWindow, -4, oldWndProcPtr);
     hMainWindow = IntPtr.Zero;
     oldWndProcPtr = IntPtr.Zero;
     newWndProcPtr = IntPtr.Zero;
     newWndProc = null;
     isrunning = false;
 }
Example #8
0
        private IntPtr oldWndProcPtr;
        private int touchInputSize;
        private Dictionary<int, int> winToInternalId = new Dictionary<int, int>();

        #endregion Fields

        #region Methods

        protected override void OnDestroy()
        {
            if (isInitialized) {
                SetWindowLong(hMainWindow, -4, oldWndProcPtr);
                UnregisterTouchWindow(hMainWindow);
Example #9
0
    void Start()
    {
        if (isrunning) return;

        //		hMainWindow = GetForegroundWindow();
        hMainWindow = GetActiveWindow();
        newWndProc = new WndProcDelegate(WndProc);
        newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
        oldWndProcPtr = SetWindowLong(hMainWindow, -4, newWndProcPtr);
        print("openHid: " + WinHidPort.OpenHid(0x0483, 0x5750));

        byte[] data = new byte[61];
        data[0] = 0x58;
        data[1] = 0x57;

        byte[] dest = new byte[63];
        WinHidPort.EncryptInputData(data, 61, ref dest);
        string logg = "";
        for (int i = 0; i < dest.Length; ++i)
        {
            logg += dest[i].ToString() + ", ";
        }
        print("write data: " + logg);

        print("writeHid: " + WinHidPort.WriteHid(dest, 63));

        IntPtr input;
        int inputsize;
        WinHidPort.ReadHid(out input, out inputsize);
        byte[] source = new byte[61];
        byte[] source2 = new byte[59];
        Marshal.Copy(input, source, 0, 61);
        WinHidPort.DecryptOutputData(source, 61, ref source2);

        //		WinHid.FreeByteArray(input);
        print("ReadHid: " + inputsize);
        string log = "";
        for (int i = 0; i < source2.Length; ++i)
            log += source2[i].ToString() + ", ";
        print("Receive Data: " + log);
        WinHidPort.CloseHid();
        isrunning = true;
    }
Example #10
0
 static extern IntPtr CallWindowProc(WndProcDelegate lpPrevWndFunc, IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
Example #11
0
    public void Start()
    {
        if (isrunning) return;

        touchInputSize = Marshal.SizeOf(typeof(TOUCHINPUT));

        hMainWindow = GetForegroundWindow();
		//FindWindow("Unity - Main.unity - effects-unity-RPSEU00X_Starter - PC, Mac & Linux Standalone");
		//FindWindow("RPSEU00X_Starter");
		
        RegisterTouchWindow(hMainWindow, 0);

        newWndProc = new WndProcDelegate(wndProc);
        newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
        oldWndProcPtr = SetWindowLong(hMainWindow, -4, newWndProcPtr);

        isrunning = true;
    }
Example #12
0
        public void ShowFileOpenDialog()
        {
            string[] fileNames;
            List <Agent.KeyConstraint> constraints = new List <Agent.KeyConstraint>();

            if (mAgent is PageantClient)
            {
                // Client Mode with Pageant - Show standard file dialog since we don't
                // need / can't use constraints

                using (var openFileDialog = new OpenFileDialog()) {
                    openFileDialog.Multiselect = true;
                    openFileDialog.Filter      = string.Join("|",
                                                             Strings.filterPuttyPrivateKeyFiles, "*.ppk",
                                                             Strings.filterAllFiles, "*.*");

                    var result = openFileDialog.ShowDialog();
                    if (result != DialogResult.OK)
                    {
                        return;
                    }
                    fileNames = openFileDialog.FileNames;
                }
            }
            else if (CommonOpenFileDialog.IsPlatformSupported)
            {
                // Windows Vista/7/8 has new style file open dialog that can be extended
                // using the Windows API via the WindowsAPICodepack library

                var win7OpenFileDialog = new CommonOpenFileDialog();
                win7OpenFileDialog.Multiselect      = true;
                win7OpenFileDialog.EnsureFileExists = true;

                var confirmConstraintCheckBox =
                    new CommonFileDialogCheckBox(cConfirmConstraintCheckBox,
                                                 "Require user confirmation");
                var lifetimeConstraintTextBox =
                    new CommonFileDialogTextBox(cLifetimeConstraintTextBox, string.Empty);
                lifetimeConstraintTextBox.Visible = false;
                var lifetimeConstraintCheckBox =
                    new CommonFileDialogCheckBox(cLifetimeConstraintCheckBox,
                                                 "Set lifetime (in seconds)");
                lifetimeConstraintCheckBox.CheckedChanged +=
                    delegate(object aSender, EventArgs aEventArgs) {
                    lifetimeConstraintTextBox.Visible =
                        lifetimeConstraintCheckBox.IsChecked;
                };

                var confirmConstraintGroupBox  = new CommonFileDialogGroupBox();
                var lifetimeConstraintGroupBox = new CommonFileDialogGroupBox();

                confirmConstraintGroupBox.Items.Add(confirmConstraintCheckBox);
                lifetimeConstraintGroupBox.Items.Add(lifetimeConstraintCheckBox);
                lifetimeConstraintGroupBox.Items.Add(lifetimeConstraintTextBox);

                win7OpenFileDialog.Controls.Add(confirmConstraintGroupBox);
                win7OpenFileDialog.Controls.Add(lifetimeConstraintGroupBox);

                var filter = new CommonFileDialogFilter(
                    Strings.filterPuttyPrivateKeyFiles, "*.ppk");
                win7OpenFileDialog.Filters.Add(filter);
                filter = new CommonFileDialogFilter(Strings.filterAllFiles, "*.*");
                win7OpenFileDialog.Filters.Add(filter);

                win7OpenFileDialog.FileOk += win7OpenFileDialog_FileOk;

                /* add help listeners to win7OpenFileDialog */

                // declare variables here so that the GC does not eat them.
                WndProcDelegate newWndProc, oldWndProc = null;
                win7OpenFileDialog.DialogOpening += (sender, e) =>
                {
                    var hwnd = win7OpenFileDialog.GetWindowHandle();

                    // hook into WndProc to catch WM_HELP, i.e. user pressed F1
                    newWndProc = (hWnd, msg, wParam, lParam) =>
                    {
                        const short shellHelpCommand = 0x7091;

                        var win32Msg = (Win32Types.Msg)msg;
                        switch (win32Msg)
                        {
                        case Win32Types.Msg.WM_HELP:
                            var helpInfo = (HELPINFO)Marshal.PtrToStructure(lParam, typeof(HELPINFO));
                            // Ignore if we are on an unknown control or control 100.
                            // These are the windows shell control. The help command is
                            // issued by these controls so by not ignoring, we would call
                            // the help method twice.
                            if (helpInfo.iCtrlId != 0 && helpInfo.iCtrlId != 100)
                            {
                                OnAddFromFileHelpRequested(win7OpenFileDialog, EventArgs.Empty);
                            }
                            return((IntPtr)1); // TRUE

                        case Win32Types.Msg.WM_COMMAND:
                            var wParamBytes = BitConverter.GetBytes(wParam.ToInt32());
                            var highWord    = BitConverter.ToInt16(wParamBytes, 0);
                            var lowWord     = BitConverter.ToInt16(wParamBytes, 2);
                            if (lowWord == 0 && highWord == shellHelpCommand)
                            {
                                OnAddFromFileHelpRequested(win7OpenFileDialog, EventArgs.Empty);
                                return((IntPtr)0);
                            }
                            break;
                        }
                        return(CallWindowProc(oldWndProc, hwnd, msg, wParam, lParam));
                    };
                    var newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
                    var oldWndProcPtr = SetWindowLongPtr(hwnd, WindowLongFlags.GWL_WNDPROC, newWndProcPtr);
                    oldWndProc = (WndProcDelegate)
                                 Marshal.GetDelegateForFunctionPointer(oldWndProcPtr, typeof(WndProcDelegate));
                };

                var result = win7OpenFileDialog.ShowDialog();
                if (result != CommonFileDialogResult.Ok)
                {
                    return;
                }
                if (confirmConstraintCheckBox.IsChecked)
                {
                    var constraint = new Agent.KeyConstraint();
                    constraint.Type = Agent.KeyConstraintType.SSH_AGENT_CONSTRAIN_CONFIRM;
                    constraints.Add(constraint);
                }
                if (lifetimeConstraintCheckBox.IsChecked)
                {
                    // error checking for parse done in fileOK event handler
                    uint lifetime   = uint.Parse(lifetimeConstraintTextBox.Text);
                    var  constraint = new Agent.KeyConstraint();
                    constraint.Type = Agent.KeyConstraintType.SSH_AGENT_CONSTRAIN_LIFETIME;
                    constraint.Data = lifetime;
                    constraints.Add(constraint);
                }
                fileNames = win7OpenFileDialog.FileNames.ToArray();
            }
            else
            {
                using (var openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.Multiselect = true;
                    openFileDialog.Filter      = string.Join("|",
                                                             Strings.filterPuttyPrivateKeyFiles, "*.ppk",
                                                             Strings.filterAllFiles, "*.*");

                    openFileDialog.FileOk += xpOpenFileDialog_FileOk;

                    // Windows XP uses old style file open dialog that can be extended
                    // using the Windows API via FileDlgExtenders library
                    XPOpenFileDialog xpOpenFileDialog = null;
                    if (Type.GetType("Mono.Runtime") == null)
                    {
                        xpOpenFileDialog = new XPOpenFileDialog();
                        xpOpenFileDialog.FileDlgStartLocation = AddonWindowLocation.Bottom;
                        mOpenFileDialogMap.Add(openFileDialog, xpOpenFileDialog);
                    }

                    openFileDialog.HelpRequest += OnAddFromFileHelpRequested;
                    // TODO: technically, a listener could be added after this
                    openFileDialog.ShowHelp = AddFromFileHelpRequested != null;

                    var result = xpOpenFileDialog == null?
                                 openFileDialog.ShowDialog() :
                                     openFileDialog.ShowDialog(xpOpenFileDialog, null);

                    if (result != DialogResult.OK)
                    {
                        return;
                    }

                    if (xpOpenFileDialog == null)
                    {
                        // If dialog could not be extended, then we add constraints by holding
                        // down the control key when clicking the Open button.
                        if (Control.ModifierKeys.HasFlag(Keys.Control))
                        {
                            var constraintDialog = new ConstraintsInputDialog();
                            constraintDialog.ShowDialog();
                            if (constraintDialog.DialogResult == DialogResult.OK)
                            {
                                if (constraintDialog.ConfirmConstraintChecked)
                                {
                                    constraints.addConfirmConstraint();
                                }
                                if (constraintDialog.LifetimeConstraintChecked)
                                {
                                    constraints.addLifetimeConstraint(constraintDialog.LifetimeDuration);
                                }
                            }
                        }
                    }
                    else
                    {
                        mOpenFileDialogMap.Remove(openFileDialog);

                        if (xpOpenFileDialog.UseConfirmConstraintChecked)
                        {
                            constraints.addConfirmConstraint();
                        }
                        if (xpOpenFileDialog.UseLifetimeConstraintChecked)
                        {
                            constraints.addLifetimeConstraint
                                (xpOpenFileDialog.LifetimeConstraintDuration);
                        }
                    }
                    fileNames = openFileDialog.FileNames;
                }
            }
            UseWaitCursor = true;
            mAgent.AddKeysFromFiles(fileNames, constraints);
            if (!(mAgent is Agent))
            {
                ReloadKeyListView();
            }
            UseWaitCursor = false;
        }
Example #13
0
        private void init()
        {
            if (Application.platform != RuntimePlatform.WindowsPlayer) return;

            touchInputSize = Marshal.SizeOf(typeof(TOUCHINPUT));

            hMainWindow = GetForegroundWindow();
            RegisterTouchWindow(hMainWindow, 0);

            newWndProc = new WndProcDelegate(wndProc);
            newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
            oldWndProcPtr = SetWindowLong(hMainWindow, -4, newWndProcPtr);

            isInitialized = true;
        }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        private void Release()
        {
            UnSubclass();

            orgWndProc = IntPtr.Zero;
            hookedWndProc = null;

            Hooks.Remove(handle);
        }
Example #15
0
        /// <inheritdoc />
        protected override void OnDisable()
        {
            if (isInitialized)
            {
                if (pressAndHoldAtomID != 0)
                {
                    RemoveProp(hMainWindow, PRESS_AND_HOLD_ATOM);
                    GlobalDeleteAtom(pressAndHoldAtomID);
                }

                SetWindowLongPtr(hMainWindow, -4, oldWndProcPtr);

                hMainWindow = IntPtr.Zero;
                oldWndProcPtr = IntPtr.Zero;
                newWndProcPtr = IntPtr.Zero;

                newWndProc = null;
            }

            foreach (var i in winToInternalId)
            {
                cancelTouch(i.Value);
            }

            base.OnDisable();
        }
Example #16
0
 public static extern int SetWindowLong2(int hwnd, int nIndex, WndProcDelegate dwNewLong);
Example #17
0
 /// <summary>
 /// Initializes a new instance of the NativeWindow class
 /// </summary>
 public NativeWindow()
 {
     wndProcDelegate = new WndProcDelegate(this.WndProc);
 }
Example #18
0
 public static extern IntPtr AllocateHWND(WndProcDelegate method);
Example #19
0
 public static extern IntPtr SetWindowLongPointer(IntPtr hWnd, WindowLong nIndex, WndProcDelegate value);
Example #20
0
 internal static extern IntPtr SetWindowsHookEx(int hook, WndProcDelegate callback, IntPtr hMod, uint dwThreadId);
Example #21
0
 static extern int SetWindowLong(IntPtr hWnd, int nIndex, WndProcDelegate newProc);
Example #22
0
		public static extern int SetWindowLong2(IntPtr hwnd, int nIndex, WndProcDelegate dwNewLong);
Example #23
0
        private void init()
        {
            if (Application.platform != RuntimePlatform.WindowsPlayer) return;

            hMainWindow = GetForegroundWindow();

            newWndProc = wndProc;
            newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
            oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);

            isInitialized = true;
        }
 /// <summary>
 /// Intitialize the WindowSubclasser. To actually subclass the
 /// underlying control use the Install() and Remove() methods
 /// </summary>
 /// <param name="window">Control to subclass</param>
 /// <param name="wndProc">Delegate to pass window messages to</param>
 public WindowSubClasser(IWin32Window window, WndProcDelegate wndProc)
 {
     _window = window;
     m_wndProcDelegate = wndProc;
     m_baseWndProc = IntPtr.Zero;
 }
 /// <summary>
 ///
 /// </summary>
 private void Subclass()
 {
     hookedWndProc = Callback;
     orgWndProc = NativeMethods.SetWindowLong(handle, -4, hookedWndProc);
 }
Example #26
0
 private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, WndProcDelegate wndProcDelegate);
    public void Cleanup()
    {
        if( isInitialized )
        {

            SetWindowLong( hMainWindow, -4, oldWndProcPtr );
            UnregisterTouchWindow( hMainWindow );

            hMainWindow = IntPtr.Zero;
            oldWndProcPtr = IntPtr.Zero;
            newWndProcPtr = IntPtr.Zero;

            newWndProc = null;

        }
    }
Example #28
0
        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);

            var style = (int)(WebBrowserAPI.WS_VISIBLE | WebBrowserAPI.WS_TABSTOP | WebBrowserAPI.WS_CHILD | WebBrowserAPI.HS_NOSELECTION);
            htmlViewHandle = WebBrowserAPI.CreateWindowEx(0, "DISPLAYCLASS", null, style, 0, 0, Width, Height, Handle,
                                                  IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
            //WmApi.SendMessage(htmlViewHandle, WmApi.DTM_ENABLECONTEXTMENU, 0, 1);

            hwnd = Handle;
            newWndProc = new WndProcDelegate(NewWndProc);
            oldWndProc = WebBrowserAPI.GetWindowLong(hwnd, WebBrowserAPI.GWL_WNDPROC);
            int success = WebBrowserAPI.SetWindowLong(hwnd, WebBrowserAPI.GWL_WNDPROC, newWndProc);
        }
Example #29
0
 public static extern int SetWindowProc(IntPtr hWnd, int nIndex, WndProcDelegate lpWndProc);
	/// <inheritdoc />
	internal void Cleanup()
	{

		if( isInitialized )
		{

			SetWindowLong( hMainWindow, -4, oldWndProcPtr );

			hMainWindow = IntPtr.Zero;
			oldWndProcPtr = IntPtr.Zero;
			newWndProcPtr = IntPtr.Zero;

			newWndProc = null;

		}

	}
Example #31
0
        private void init()
        {
            hMainWindow = GetForegroundWindow();

            newWndProc = wndProc;
            newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
            oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);

            EnableMouseInPointer(true);

            isInitialized = true;
        }
Example #32
0
        private void init()
        {
            touchInputSize = Marshal.SizeOf(typeof(TOUCHINPUT));

            hMainWindow = GetForegroundWindow();
            RegisterTouchWindow(hMainWindow, 0);

            newWndProc = wndProc;
            newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
            oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);

            pressAndHoldAtomID = GlobalAddAtom(PRESS_AND_HOLD_ATOM);
            SetProp(hMainWindow, PRESS_AND_HOLD_ATOM, 1);

            isInitialized = true;
        }
Example #33
0
        /// <inheritdoc />
        protected override void OnDisable()
        {
            if (isInitialized)
            {
                SetWindowLongPtr(hMainWindow, -4, oldWndProcPtr);

                hMainWindow = IntPtr.Zero;
                oldWndProcPtr = IntPtr.Zero;
                newWndProcPtr = IntPtr.Zero;

                newWndProc = null;
            }

            foreach (var i in winToInternalId)
            {
                cancelTouch(i.Value);
            }

            base.OnDisable();
        }
Example #34
0
        private void init()
        {
            hMainWindow = GetForegroundWindow();

            newWndProc = wndProc;
            newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
            oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);

            EnableMouseInPointer(true);

            pressAndHoldAtomID = GlobalAddAtom(PRESS_AND_HOLD_ATOM);
            SetProp(hMainWindow, PRESS_AND_HOLD_ATOM, 1);

            isInitialized = true;
        }
Example #35
0
 /// <summary>
 ///
 /// </summary>
 private void Subclass()
 {
     if ((Handle != IntPtr.Zero) && (defWindowProc == IntPtr.Zero))
     {
         defWindowProc = NativeMethods.GetWindowLong(Handle, -4);
         windowProc = Callback;
         NativeMethods.SetWindowLong(Handle, -4, windowProc);
     }
 }
Example #36
0
 public static extern int SetWindowLong(IntPtr hWnd, int nIndex, WndProcDelegate newProc);
Example #37
0
 /// <summary>
 ///
 /// </summary>
 private void UnSubclass()
 {
     if (defWindowProc != IntPtr.Zero)
     {
         NativeMethods.SetWindowLong(Handle, -4, defWindowProc);
         defWindowProc = IntPtr.Zero;
         windowProc = null;
     }
 }
Example #38
0
 /// <summary>
 ///
 /// </summary>
 private void Subclass()
 {
     hookedWndProc = Callback;
     orgWndProc = NativeMethods.SetWindowLong(handle, -4, hookedWndProc);
 }
Example #39
0
	public void Close()
    {
        if (!isrunning) return;
		
        SetWindowLong(hMainWindow, -4, oldWndProcPtr);
        UnregisterTouchWindow(hMainWindow);

        hMainWindow = IntPtr.Zero;
        oldWndProcPtr = IntPtr.Zero;
        newWndProcPtr = IntPtr.Zero;

        newWndProc = null;
		
		isrunning = false;
    }
Example #40
0
 public static extern IntPtr CallWindowProc(WndProcDelegate lpPrevWndFunc, IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
Example #41
0
 private void PreInitialize()
 {
     windowProc        = WndProc;
     thisWindowProcPtr = Marshal.GetFunctionPointerForDelegate(windowProc);
 }