⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winapi.cs

📁 Hide-Delete icon from ToolBar32 for specific process , from command line arguments. TBBUTTON CSha
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LicenseManage.BaseClasses
{
    using System.Runtime.InteropServices;

    class WinAPI
    {
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_CLOSE = 0xF060;


        // This is a platform invoke prototype. SetLastError is true, which allows 
        // the GetLastWin32Error method of the Marshal class to work correctly.    
        [DllImport("Kernel32", ExactSpelling = true, SetLastError = true)]
        static extern Boolean CloseHandle(IntPtr h);


        [DllImport("user32.dll", EntryPoint = "MessageBox")]
        public static extern int ShowMessage(int hWnd,string text, string caption, uint type);

        /// <summary>
        /// 
        /// The FindWindowEx function retrieves a handle to a window whose class name and window name match the specified strings. 
        /// The function searches child windows, beginning with the one following the specified child window. 
        /// This function does not perform a case-sensitive search.
        /// 
        /// 
        /// · hwndParent
        ///Identifies the parent window whose child windows are to be searched.
        ///If hwndParent is NULL, the function uses the desktop window as the parent window. 
        /// The function searches among windows that are child windows of the desktop.
        /// 
        /// · hwndChildAfter
        /// Identifies a child window. The search begins with the next child window in the Z order. hwndChildAfter must be a direct child window of hwndParent, not just a descendant window.
        /// If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
        /// Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level windows. 
        /// 
        /// · lpszClass
        ///Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. 
        /// If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. 
        /// The atom, a 16-bit value, must be placed in the low-order word of lpszClass; the high-order word must be zero.
        /// 
        ///· lpszWindow
        ///Points to a null-terminated string that specifies the window name (the window’s title). 
        /// If this parameter is NULL, all window names match.
        /// 
        /// Returns
        /// 
        /// If the function succeeds, the return value is the handle to the window that has the specified class and window names.
        /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. 
        ///  
        /// </summary>
        /// <param name="hwndParent"></param>
        /// <param name="hwndChildAfter"></param>
        /// <param name="lpszClass"></param>
        /// <param name="lpszWindow"></param>
        /// <returns>DLLCall("user32.dll","hwnd","FindWindow", "str", "Shell_TrayWnd", "int", 0)</returns>
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32", EntryPoint = "SendMessageA")]
        /// <summary>
        /// Sends the specified message to a window or windows. 
        /// The SendMessage function calls the window procedure for the specified window and does not return until the window procedure
        ///  has processed the message.
        /// </summary>
        /// <param name="Hwnd"></param>
        /// <param name="wMsg"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        public static extern int SendMessage(int Hwnd, int wMsg, int wParam, int lParam);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static public extern IntPtr GetForegroundWindow(); // 
        
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct STRINGBUFFER
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
            public string szText;
        }
        
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowText(IntPtr hWnd, out STRINGBUFFER ClassName, int nMaxCount);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);

        public delegate bool EnumThreadProc(IntPtr hwnd, IntPtr lParam);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool EnumThreadWindows(int threadId, EnumThreadProc pfnEnum, IntPtr lParam);


        //[DllImport("user32.dll", SetLastError = true)]
        //public static extern bool RegisterHotKey(IntPtr hWnd, // handle to window    
        //    int id,            // hot key identifier    
        //    KeyModifiers fsModifiers,  // key-modifier options    
        //    Keys vk            // virtual-key code    
        //    );

        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool UnregisterHotKey(IntPtr hWnd,  // handle to window    
                                                   int id      // hot key identifier    
            );

        [Flags()]
        public enum KeyModifiers
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            Windows = 8
        }

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int FindWindow(string s, string s1);


        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

        
        /// <summary>
        /// int 2035711, bool False, int pId  , 
        /// Sees if it can read the memory from the Process with max process access rights (2035711) ,
        /// </summary>
        /// <param name="dwDesiredAccess"></param>
        /// <param name="bInheritHandle"></param>
        /// <param name="dwProcessId"></param>
        /// <returns></returns>
        [DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
        public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);

        /// <summary>
        ///  __in      HANDLE hProcess,
        ///__in_opt  LPVOID lpAddress,
        ///__in      SIZE_T dwSize,
        /// __in      DWORD flAllocationType,
        /// __in      DWORD flProtect

        /// </summary>
        /// <param name="hProcesshwdl"></param>
        /// <param name="hProcess"></param>
        /// <param name="lpAddress"></param>
        /// <param name="i"></param>
        /// <param name="i1"></param>
        /// <param name="i2"></param>
        /// <param name="dwSize"></param>
        /// <param name="flAllocationType"></param>
        /// <param name="flProtect"></param>
        /// <returns></returns>
        [DllImport("kernel32.dll", SetLastError=true, ExactSpelling=true)]
        public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);

        [DllImport("Kernel32.dll")]
        public static extern bool ReadProcessMemory
            (
            IntPtr hProcess,
            IntPtr lpBaseAddress,
            byte[] lpBuffer,
            UInt32 nSize,
            ref UInt32 lpNumberOfBytesRead
            );

    // bool ReadData(TSUBTYPE* data, LPCVOID lpData)
    //{
    //    return m_hProcess ? ReadProcessMemory(m_hProcess, lpData, 
    //        (LPVOID)data, sizeof TSUBTYPE, NULL) : FALSE;
    //}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -