首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以编程方式在c#中隐藏Windows8.1的磁贴

以编程方式在c#中隐藏Windows8.1的磁贴
EN

Stack Overflow用户
提问于 2013-08-02 22:00:45
回答 1查看 678关注 0票数 0

我必须扩展一个终端服务器软件才能与Windows8.1一起工作。场景如下:

两台PC:一台运行客户端软件,另一台运行服务器。服务器操作系统为Windows 8.1

当用户按下客户端PC上的按钮时,它通过虚拟信道打开到服务器PC的RDP连接。必须有一个登录,磁贴必须被隐藏,也有软件的服务器部分必须启动。

为了隐藏windows早期版本下的普通桌面,我们使用了以下命令:

代码语言:javascript
复制
// For Windows Vista and Windows 7 hide the Status-Bar and all Desktop-Icons
int   a_hWndTaskBar      = FindWindow( "Shell_TrayWnd", null );
int   a_hWndStart        = FindWindow( "Button", "Start" );
int   a_hWndDesktop      = FindWindow( "Progman", null );
bool  a_bResult          = false;

try
{
  a_bResult = SetWindowPos( a_hWndTaskBar, 0, 0, 0, 0, 0, SWP_HIDEWINDOW );
  a_bResult = SetWindowPos( a_hWndStart, 0, 0, 0, 0, 0, SWP_HIDEWINDOW );
  a_bResult = ShowWindow( a_hWndDesktop, SW_HIDE );
}
catch( Exception e )
{
  MessageBox.Show( e.Message );
}

我必须做什么才能在Windows8.1中实现这一点?

马库斯

EN

回答 1

Stack Overflow用户

发布于 2014-01-26 02:25:38

这里:适用于我:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Constants.UI
{

    public class Taskbar
    {
        [DllImport("user32.dll")]// For Windows Mobile, replace user32.dll with coredll.dll
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", SetLastError = true)]
        private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

        [DllImport("user32.dll")]
        private static extern int ShowWindow(int hwnd, int command);

        private const int SW_HIDE = 0;
        private const int SW_SHOW = 1;

        protected static int Handle
        {
            get
            {
                return HandlePtr.ToInt32();
            }
        }
        protected static IntPtr HandlePtr
        {
            get
            {
                return FindWindow("Shell_TrayWnd", "");
            }
        }
        protected static int StartHandle
        {
            get
            {
                int hStart = FindWindow("Button", "Start").ToInt32();
                if (hStart == 0)
                {
                    hStart = FindWindowEx(HandlePtr, IntPtr.Zero, "Start", null).ToInt32(); //windows 8
                }
                return hStart;
            }
        }

        private Taskbar()
        {
            // hide ctor
        }
        static object lockAccess = new object();
        public static void Show()
        {
            try
            {
                lock (lockAccess)
                {
                    ShowWindow(Handle, SW_SHOW);
                    ShowWindow(StartHandle, SW_SHOW);
                }
            }
            catch { }
        }

        public static void Hide()
        {
            try
            {
                lock (lockAccess)
                {
                    ShowWindow(Handle, SW_HIDE);
                    ShowWindow(StartHandle, SW_HIDE);
                }
            }
            catch { }
        }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18018803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档