BringWindowToTop完美激活窗口与置顶

        void ActiveWin(IntPtr h)
        {
            IntPtr hForeWnd = GetForegroundWindow();//获取当前窗口句柄
            int tIdCur = GetWindowThreadProcessId(hForeWnd, IntPtr.Zero);//获取当前窗口句柄的线程ID
            int tIdCurProgram = GetCurrentThreadId();//获取当前运行程序线程ID
            var r = AttachThreadInput(tIdCur, tIdCurProgram, 1);//是否能成功和当前自身进程所附加的输入上下文有关
            //SwitchToThisWindow(h, true);
            //ShowWindow(hJD, 9);
            BringWindowToTop(h);
            //SetForegroundWindow(h);
            //SetActiveWindow(hJD);
            //SetFocus(hJD);
            AttachThreadInput(tIdCur, tIdCurProgram, 0);
        }

        void TopWin(IntPtr h)
        {
            SetWindowPos(h, -1, 0, 0, 0, 0, 1 | 2 | 10 | 40);
        }

 

 

 

posted @ 2018-11-14 18:35  -Ward-  阅读(474)  评论(0编辑  收藏  举报