打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Unity 修改windows窗口的标题

修改windows窗口的标题名称,就是修改下图的东西:

 

 第一种:

using UnityEngine;using System;using System.Runtime.InteropServices;public class SetWindowText : MonoBehaviour{    #region WIN32API    delegate bool EnumWindowsCallBack(IntPtr hwnd, IntPtr lParam);    [DllImport("user32", CharSet = CharSet.Unicode)]    static extern bool SetWindowTextW(IntPtr hwnd, string title);    [DllImport("user32")]    static extern int EnumWindows(EnumWindowsCallBack lpEnumFunc, IntPtr lParam);    [DllImport("user32")]    static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref IntPtr lpdwProcessId);    #endregion    IntPtr myWindowHandle;    public void Start()    {        IntPtr handle = (IntPtr)System.Diagnostics.Process.GetCurrentProcess().Id;  //获取进程ID        EnumWindows(new EnumWindowsCallBack(EnumWindCallback), handle);     //枚举查找本窗口        SetWindowTextW(myWindowHandle, "测试代码"); //设置窗口标题    }    bool EnumWindCallback(IntPtr hwnd, IntPtr lParam)    {        IntPtr pid = IntPtr.Zero;        GetWindowThreadProcessId(hwnd, ref pid);        if (pid == lParam)  //判断当前窗口是否属于本进程        {            myWindowHandle = hwnd;            return false;        }        return true;    }}

第二种:

using System;using System.Collections;using System.Collections.Generic;using System.Runtime.InteropServices;using System.Text;using UnityEngine;public class NewBehaviourScript : MonoBehaviour {    //Import the following.    [DllImport("user32.dll", EntryPoint = "SetWindowTextW", CharSet = CharSet.Unicode)]    public static extern bool SetWindowTextW(System.IntPtr hwnd, System.String lpString);    [DllImport("user32.dll", EntryPoint = "FindWindow")]    public static extern System.IntPtr FindWindow(System.String className, System.String windowName);    public void Change()    {        //Get the window handle.        var windowPtr = FindWindow(null, "WindowTitleChange");//打包时的ProductName,找到名字是WindowTitleChange的窗口
     //Set the title text using the window handle. 
     SetWindowTextW(windowPtr, "测试代码");
}
}

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
C# 调用 Google Earth Com API开发(二)
C# 如何判断并且激活,最大化已有的外部应用程序的窗口? (源码例程) - 编程岁月 - ...
如何让MessageBox.Show的在父窗口上居中显示
C#截取 当前桌面的活动窗体图像
C# WINDOWS服务交互的实现
C#调用windows API的一些方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服