首页 技术 正文
技术 2022年11月13日
0 收藏 667 点赞 3,499 浏览 2378 个字
  1. 不显示在任务栏,Alt+Tab也不显示

            protected override CreateParams CreateParams        {            get            {                const int WS_EX_APPWINDOW = 0x40000;                const int WS_EX_TOOLWINDOW = 0x80;                CreateParams cp = base.CreateParams;                cp.ExStyle &= (~WS_EX_APPWINDOW);    // 不显示在TaskBar                cp.ExStyle |= WS_EX_TOOLWINDOW;      // 不显示在Alt-Tab                return cp;            }        }
  2. 无标题拖动
            [DllImport("user32.dll")]        public static extern bool ReleaseCapture();        [DllImport("user32.dll")]        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);        public const int SC_MOVE = 0xF010;        public const int HTCAPTION = 0x0002;        public const Int32 WM_SYSCOMMAND = 274;        private void picMain_MouseDown(object sender, MouseEventArgs e)        {            ReleaseCapture();            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);        }
  3. 键盘事件
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)        {            int WM_KEYDOWN = 256;            int WM_SYSKEYDOWN = 260;            if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)            {                switch (keyData)                {                    case Keys.Escape:                        this.WindowState = FormWindowState.Normal;                        return false;                    case Keys.Enter:                        this.WindowState = FormWindowState.Maximized;                        return false;                    case Keys.Up:                    case Keys.Left:                        return false;                    case Keys.Right:                    case Keys.Down:                        return false;                }            }            return base.ProcessCmdKey(ref msg, keyData);        }
  4. 新建Form始终显示在主窗体上面
            [DllImport("user32 ")]        public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);            Form frm = new Form();            SetParent(frm.Handle, this.Handle);

    检测是否有实例

                bool createNew;            using (System.Threading.Mutex m = new System.Threading.Mutex(true, "Global\\" + Application.ProductName, out createNew))            {                if (createNew)                {/// 执行创建工作} else                {                    /// 激活现有实例                }            }
  5. 激活现有实例
            [DllImport("user32.dll")]        public static extern bool IsIconic(IntPtr hWnd);        //隐藏窗口,活动状态给令一个窗口        private const int SW_HIDE = 0;        //用原来的大小和位置显示一个窗口,同时令其进入活动状态        private const int SW_SHOWNORMAL = 1;        //最小化窗口,并将其激活        private const int SW_SHOWMINIMIZED = 2;        //最大化窗口,并将其激活        private const int SW_SHOWMAXIMIZED = 3;        //用最近的大小和位置显示一个窗口,同时不改变活动窗口        private const int SW_SHOWNOACTIVATE = 4;        //用原来的大小和位置显示一个窗口,同时令其进入活动状态        private const int SW_RESTORE = 9;        //根据默认 创建窗口时的样式 来显示        private const int SW_SHOWDEFAULT = 10;        [DllImport("User32.dll")]        public static extern bool ShowWindowAsync(System.IntPtr hWnd, int cmdShow);        [DllImport("User32.dll")]        public static extern bool SetForegroundWindow(System.IntPtr hWnd);        public static void RaiseOtherProcess()        {            Process proc = Process.GetCurrentProcess();            Process.GetProcesses();            foreach (Process otherProc in                Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName))            {                if (proc.Id != otherProc.Id)                {                    IntPtr hWnd = otherProc.MainWindowHandle;                    if (IsIconic(hWnd))                    {                        ShowWindowAsync(hWnd, SW_RESTORE);                    }                    SetForegroundWindow(hWnd);                    break;                }            }        }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289