Ejemplo n.º 1
0
    /// <summary>
    /// 可自定 Windows 的動作, 像是 隱藏 一般 最大化 最小化, 此程式會開啟程式, 不須額外執行 Process.Start()
    /// </summary>
    /// <param name="path"></param>
    /// <param name="fileName"></param>
    /// <param name="windowStyle"></param>
    ///
    /// Example:相對路徑
    /// string path = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\exe");
    /// WindowsEventAPI.SetWindowEvent(path, "Kinect.exe", ProcessWindowStyle.Minimized);
    public static void SetWindowEvent(string path, string fileName, WindowsStyle windowStyle = WindowsStyle.Normal)
    {
        string file = Path.Combine(path, fileName);

        using (Process myProcess = new Process())
        {
            myProcess.StartInfo.UseShellExecute = true;
            myProcess.StartInfo.FileName        = file;
            myProcess.StartInfo.CreateNoWindow  = false;

            myProcess.StartInfo.WindowStyle = Select(windowStyle);
            myProcess.Start();
        }
    }
Ejemplo n.º 2
0
        internal static IntPtr CreateWindowEx(WindowsStyleEx dwExStyle, string lpszClassName, string lpszWindowName,
                                              WindowsStyle style, int x, int y, int width, int height,
                                              IntPtr hWndParent, IntPtr hMenu, IntPtr hInst,
                                              [MarshalAs(UnmanagedType.AsAny)] object pvParam)
        {
            IntPtr ptr = IntCreateWindowEx(dwExStyle, lpszClassName, lpszWindowName, style, x, y, width, height, hWndParent,
                                           hMenu, hInst, pvParam);

            if (ptr == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
            return(ptr);
        }
Ejemplo n.º 3
0
    public static void SetWindowEvent(string file, WindowsStyle windowStyle = WindowsStyle.Normal)
    {
        using (Process myProcess = new Process())
        {
            myProcess.StartInfo.UseShellExecute = true;
            myProcess.StartInfo.FileName        = file;
            myProcess.StartInfo.CreateNoWindow  = false;

            myProcess.StartInfo.WindowStyle = Select(windowStyle);
            myProcess.Start();
        }
        /// Click on screen center.
        SetCursorPos(Screen.width / 2, Screen.height / 2);
        //System.Threading.Thread.Sleep(100);
        Mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        Mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }
Ejemplo n.º 4
0
    private static ProcessWindowStyle Select(WindowsStyle style)
    {
        switch (style)
        {
        case WindowsStyle.Hidden:
            return(ProcessWindowStyle.Hidden);

        case WindowsStyle.Maximized:
            return(ProcessWindowStyle.Maximized);

        case WindowsStyle.Minimized:
            return(ProcessWindowStyle.Minimized);

        default:
            return(ProcessWindowStyle.Normal);
        }
    }
Ejemplo n.º 5
0
            public Window(WindowsStyle pStyle, WindowsStyleEx pExStyle, string pClassName,
                          string pWindowName, int pLeft, int pTop, int pWidth, int pHeight)
            {
                PreInitialize();

                IntPtr xHandle =
                    CreateWindowEx(pExStyle, pClassName, pWindowName, pStyle, pLeft, pTop, pWidth, pHeight,
                                   IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

                if (xHandle == IntPtr.Zero)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
                wndHandle     = xHandle;
                destroyWindow = true;
                Subclass();
            }
Ejemplo n.º 6
0
 internal static extern IntPtr IntCreateWindowEx(WindowsStyleEx dwExStyle, string lpszClassName, string lpszWindowName,
                                                 WindowsStyle style, int x, int y, int width, int height,
                                                 IntPtr hWndParent, IntPtr hMenu, IntPtr hInst,
                                                 [MarshalAs(UnmanagedType.AsAny)] object pvParam);