How to change windows applicatioin's position via Win32 API

可以使用的Win32 API是:

[DllImport("user32.dll")]
private extern static bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);

 

static void SetWindowPosition(string locationURL)
        {
            SHDocVw.ShellWindows windows = new SHDocVw.ShellWindows();
            SHDocVw.InternetExplorer currentWindow = null;
            foreach (SHDocVw.InternetExplorer window in windows)
            {
                if (window.LocationURL.Contains(locationURL))
                {
                    currentWindow = window;
                    break;
                }
            }

            if (currentWindow != null)
            {
                IntPtr handle = (IntPtr)currentWindow.HWND;
                var width = Screen.PrimaryScreen.Bounds.Width;
                var height = Screen.PrimaryScreen.Bounds.Height;
                SetWindowPos(handle, (IntPtr)0, width / 2, 0, width / 2, height, 0x0040);
            }
        }

 

posted @ 2017-07-19 17:00  supperwu  阅读(202)  评论(0编辑  收藏  举报