win32API的一些使用经验

来源:互联网 发布:cc域名转入 编辑:程序博客网 时间:2024/05/16 14:34

c#程序里调用系统API:

    //利用系统api回收垃圾

[System.Runtime.InteropServices.DllImport("kernel32.dll")]        public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);        public void FlushMemory()        {            GC.Collect();            GC.WaitForPendingFinalizers();            if (Environment.OSVersion.Platform == PlatformID.Win32NT)            {                SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);            }        }

c#脚本里:

//用于unity的C#脚本,使用一些系统函数如:SetWindowPos,GetWIndowLong,FindWindowEx等,用来获取摸个线程的窗体然后改变窗体的位置:

    [DllImport("user32.dll")]    static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);    [DllImport("user32.dll")]    static extern IntPtr GetForegroundWindow();    [DllImport("user32.dll", EntryPoint = "GetWindowLong")]    static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);    const uint SWP_SHOWWINDOW = 0x0040;    [DllImport("user32.dll")]    public static extern System.IntPtr FindWindowEx(System.IntPtr parent, System.IntPtr childe, string strclass, string strname);  IntPtr p = FindWindowEx(System.IntPtr.Zero, System.IntPtr.Zero, null, "线程的名称");             SetWindowPos(p, -1, 左上角.x, 左上角.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);        SetWindowLong(p, -16, 369164288);


c++

//利用系统API设置窗体的位置和属性(TOPMOST)

        static HWND handle  = NULL;handle = WindowFromDC(wglGetCurrentDC());SetWindowLong(handle,-16,369164288);SetWindowPos(handle,HWND_TOPMOST,screenX,screenY,screenwidth,screenheight,SWP_SHOWWINDOW);




0 0
原创粉丝点击