NEWS

Hướng dẫn viết ứng dụng ẩn - hiển thị và xóa nút đóng chương trình khác (hide and show and remove close button another application)

Hướng dẫn viết ứng dụng ẩn -  hiển thị và xóa nút đóng chương trình khác  (hide and show and remove close button another application)
Đăng bởi: Thảo Meo - Lượt xem: 14218 09:53:48, 10/12/2016DEVEXPRESS   In bài viết

Hôm nay, mình xin hướng dẫn các bạn cách ẩn và hiển thị ứng dụng chương trình khác.

Ví dụ: Tôi muốn viết 1 ứng dụng, có thể ẩn hoặc hiện chương trình microsoft word (hoặc xóa biểu tượng đóng trên chương trình ms Word)

Các bạn có thể xem demo chương trình như hình bên dưới:

hide_show_another_application

Các bạn có thể sử dụng thủ thuật này, để viết ứng dụng khóa và mở khóa ứng dụng.

Ví dụ: khi bạn mở chương trình zalo trên desktop lên thì yêu cầu phải nhập mật khẩu, nếu mật khẩu đúng mình sẽ cho phép hiển thị ứng dụng zalo.

Source code chương trình:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
         [DllImport("user32.dll")]
        static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
         [DllImport("user32.dll")]
         static extern bool DeleteMenu(IntPtr hMenu, uint uPosition, uint uFlags);
        const uint SC_CLOSE = 0xF060;
        const uint MF_BYCOMMAND = 0x00000000;
        
        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e){               
            var handle = FindWindow(null, "Document1 - Microsoft Word");             
            ShowWindow(handle, 0);    
        }
        private void button2_Click(object sender, EventArgs e)
        {
            var handle = FindWindow(null, "Document1 - Microsoft Word");
            ShowWindow(handle, 1);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            Process[] processes = Process.GetProcessesByName("winword");
            foreach (Process p in processes)
            {
                IntPtr pFoundWindow = p.MainWindowHandle;

                IntPtr nSysMenu = GetSystemMenu(pFoundWindow, false);
                if (nSysMenu != IntPtr.Zero)
                {
                    if (DeleteMenu(nSysMenu, SC_CLOSE, MF_BYCOMMAND))
                    {
                        MessageBox.Show("dfsdf");
                    }
                }
            }
        }
    }
}

CHÚC CÁC BẠN THÀNH CÔNG

DOWNLOAD SOURCE

Tags: win32api

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

Hướng dẫn viết ứng dụng ẩn -  hiển thị và xóa nút đóng chương trình khác  (hide and show and remove close button another application)
Đăng bởi: Thảo Meo - Lượt xem: 14218 09:53:48, 10/12/2016DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.