狠狠色丁香婷婷综合尤物/久久精品综合一区二区三区/中国有色金属学报/国产日韩欧美在线观看 - 国产一区二区三区四区五区tv

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

【C#】Win32Api接口隱藏第三方軟件應用程序的右下角托盤圖標

admin
2024年3月19日 16:18 本文熱度 681
//使用方法 SetTrayIconVisible("qq", false);

        //獲取托盤指針

        private static IntPtr TrayToolbarWindow32()

        {

            IntPtr h = IntPtr.Zero;

            IntPtr hTemp = IntPtr.Zero;

 

            h = Win32API.FindWindow("Shell_TrayWnd", null); //托盤容器

            h = Win32API.FindWindowEx(h, IntPtr.Zero, "TrayNotifyWnd", null);//找到托盤

            h = Win32API.FindWindowEx(h, IntPtr.Zero, "SysPager", null);

 

            hTemp = Win32API.FindWindowEx(h, IntPtr.Zero, "ToolbarWindow32", null);

 

            return hTemp;

        }

        //顯示/隱藏單個系統托盤圖標,由參數caption指定圖標

        public static void SetTrayIconVisible(string caption, bool isShow)

        {

            IntPtr vHandle = TrayToolbarWindow32();

            int vCount = Win32API.SendMessage(vHandle, Win32API.TB_BUTTONCOUNT, 0, 0);

            IntPtr vProcessId = IntPtr.Zero;

            Win32API.GetWindowThreadProcessId(vHandle, ref vProcessId);

            IntPtr vProcess = Win32API.OpenProcess(Win32API.PROCESS_VM_OPERATION | Win32API.PROCESS_VM_READ |

            Win32API.PROCESS_VM_WRITE, IntPtr.Zero, vProcessId);

            IntPtr vPointer = Win32API.VirtualAllocEx(vProcess, (int)IntPtr.Zero, 0x1000,

            Win32API.MEM_RESERVE | Win32API.MEM_COMMIT, Win32API.PAGE_READWRITE);

            char[] vBuffer = new char[256];

            IntPtr pp = Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0);

            uint vNumberOfBytesRead = 0;

            try

            {

                for (int i = 0; i < vCount; i++)

                {

                    Win32API.SendMessage(vHandle, Win32API.TB_GETBUTTONTEXT, i, vPointer.ToInt32());

 

                    Win32API.ReadProcessMemoryEx(vProcess, vPointer,

                    Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0),

                    vBuffer.Length * sizeof(char), ref vNumberOfBytesRead);

 

                    int l = 0;

                    for (int j = 0; j < vBuffer.Length; j++)

                    {

                        if (vBuffer[j] == (char)0)

                        {

                            l = j;

                            break;

                        }

                    }

                    string s = new string(vBuffer, 0, l);

 

                    if (s.IndexOf(caption) >= 0)

                    {

                        if (isShow)

                            Win32API.SendMessage(vHandle, Win32API.TB_HIDEBUTTON, i, 0);

                        else

                            Win32API.SendMessage(vHandle, Win32API.TB_HIDEBUTTON, i, 1);

                    }

                    Console.WriteLine(s);

                }

            }

            finally

            {

                Win32API.VirtualFreeEx(vProcess, vPointer, 0, Win32API.MEM_RELEASE);

                Win32API.CloseHandle(vProcess);

            }

        }

創建類:Win32API.cs

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

 

/********************************************************************************

* 資料收集:Jonny Sun ,www.csframework.com

* ******************************************************************************/

 

namespace HideIcon

{

    /// <summary>

    /// 操作Windows窗體,系統托盤所用的API函數

    /// </summary>

    public class Win32API

    {

        public const int WM_USER = 0x400;

        public const int WM_CLOSE = 0x10;

        public const int WM_GETTEXT = 0x000D;

        public const int WM_SETTEXT = 0x000C;

 

        public const int STANDARD_RIGHTS_REQUIRED = 0xF0000;

        public const int SYNCHRONIZE = 0x100000;

        public const int PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF;

        public const int PROCESS_TERMINATE = 0x1;

 

        public const int PROCESS_VM_OPERATION = 0x8;

        public const int PROCESS_VM_READ = 0x10;

        public const int PROCESS_VM_WRITE = 0x20;

 

        public const int MEM_RESERVE = 0x2000;

        public const int MEM_COMMIT = 0x1000;

        public const int MEM_RELEASE = 0x8000;

 

        public const int PAGE_READWRITE = 0x4;

 

        public const int TB_BUTTONCOUNT = (WM_USER + 24);

        public const int TB_HIDEBUTTON = (WM_USER + 4);

        public const int TB_GETBUTTON = (WM_USER + 23);

        public const int TB_GETBUTTONTEXT = WM_USER + 75;

        public const int TB_GETBITMAP = (WM_USER + 44);

        public const int TB_DELETEBUTTON = (WM_USER + 22);

        public const int TB_ADDBUTTONS = (WM_USER + 20);

        public const int TB_INSERTBUTTON = (WM_USER + 21);

        public const int TB_ISBUTTONHIDDEN = (WM_USER + 12);

        public const int ILD_NORMAL = 0x0;

        public const int TPM_NONOTIFY = 0x80;

 

        public const int WS_VISIBLE = 268435456;//窗體可見

        public const int WS_MINIMIZEBOX = 131072;//有最小化按鈕

        public const int WS_MAXIMIZEBOX = 65536;//有最大化按鈕

        public const int WS_BORDER = 8388608;//窗體有邊框

        public const int GWL_STYLE = (-16);//窗體樣式

        public const int GW_HWNDFIRST = 0;

        public const int GW_HWNDNEXT = 2;

        public const int SW_HIDE = 0;

        public const int SW_SHOW = 5;

 

        [DllImport("User32.Dll")]

        public static extern void GetClassName(IntPtr hwnd, StringBuilder s, int nMaxCount);

 

        [DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]

        public static extern void SetForegroundWindow(IntPtr hwnd);

 

        [DllImport("user32.dll", EntryPoint = "GetDlgItem", SetLastError = true)]

        public static extern IntPtr GetDlgItem(int nID, IntPtr phWnd);

 

        [DllImport("user32.dll", CharSet = CharSet.Auto)]

        public static extern int RegisterWindowMessage(string msg);

 

        [DllImport("kernel32", EntryPoint = "OpenProcess")]

        public static extern IntPtr OpenProcess(int dwDesiredAccess, IntPtr bInheritHandle, IntPtr dwProcessId);

 

        [DllImport("kernel32", EntryPoint = "CloseHandle")]

        public static extern int CloseHandle(IntPtr hObject);

 

        [DllImport("user32", EntryPoint = "GetWindowThreadProcessId")]

        public static extern IntPtr GetWindowThreadProcessId(IntPtr hwnd, ref IntPtr lpdwProcessId);

 

        [DllImport("user32.dll")]

        public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

 

        [DllImport("user32", EntryPoint = "SendMessage")]

        public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

 

        [DllImport("user32", EntryPoint = "SendMessage")]

        public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);

 

        [DllImport("kernel32", EntryPoint = "ReadProcessMemory")]

        public static extern int ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref IntPtr lpBuffer, int nSize, int lpNumberOfBytesWritten);

 

        [DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")]

        public static extern bool ReadProcessMemoryEx(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int nSize, ref uint vNumberOfBytesRead);

 

        [DllImport("kernel32", EntryPoint = "ReadProcessMemory")]

        public static extern int ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, int lpNumberOfBytesWritten);

 

        [DllImport("kernel32", EntryPoint = "WriteProcessMemory")]

        public static extern int WriteProcessMemory(IntPtr hProcess, ref int lpBaseAddress, ref int lpBuffer, int nSize, ref int lpNumberOfBytesWritten);

 

        [DllImport("kernel32", EntryPoint = "VirtualAllocEx")]

        public static extern IntPtr VirtualAllocEx(IntPtr hProcess, int lpAddress, int dwSize, int flAllocationType, int flProtect);

 

        [DllImport("kernel32", EntryPoint = "VirtualFreeEx")]

        public static extern int VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, int dwFreeType);

 

        [DllImport("User32.dll")]

        public extern static int GetWindow(int hWnd, int wCmd);

 

        [DllImport("User32.dll")]

        public extern static int GetWindowLongA(int hWnd, int wIndx);

 

        [DllImport("user32.dll")]

        public static extern bool GetWindowText(int hWnd, StringBuilder title, int maxBufSize);

 

        [DllImport("user32.dll", CharSet = CharSet.Auto)]

        public extern static int GetWindowTextLength(IntPtr hWnd);

 

        [DllImport("User32.dll", EntryPoint = "FindWindow")]

        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

 

        [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]

        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

 

        [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]

        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

 

        [DllImport("user32.dll", EntryPoint = "SendMessageA")]

        public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

 

    }

}


該文章在 2024/3/19 16:18:53 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved