win32API的一些使用经验

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值