Unity 修改windows窗口的标题

摘要:
要修改Windows窗口的标题名,需要修改以下内容:第一个是使用UnityEngine;使用系统;使用System.Runtime。InteropServices;publicclassSetWindowText:MonoBehavior{#regionWIN32API delegateboolEnumWindowsCallBack(IntPtrhwnd,IntPtrl

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

Unity 修改windows窗口的标题第1张

 第一种:

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, "测试代码");
}
}

免责声明:文章转载自《Unity 修改windows窗口的标题》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇vsnprintfrobotframework的学习笔记(十四)------学习Robot Framework必须掌握的库—-BuiltIn库下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

VC++的DLL应用(含Demo演示)

在大学大一的时候学的是C,然后后来大二的时候专业又开了C++这个课程,然后再后来自己又自学了一点VC++,大三的时候也试着编写过一个MFC的最简单的窗口程序。到大四的时候,自己又做了一个GIS的项目,是用C#.NET来编写的,然后发现C#上手好容易,而且还大部分语法规则都沿用了C,C++的习惯,于是觉得C++实在是没有一点优势可言啊。但这个暑假的实习经历又...

Mac下发布Unity3d中Android平台下出现“android (invokation failed)”的错误

 昨天想要给Murphy同学编译一个Andorid版本的工程,但我本机没有Android SDK,于是安装了Murphy发给我的安装包,并升级设置,结果在发布的最后出现了如下错误: Error building Player: Exception: android (invokation failed)ERROR: unknown errorcmd:an...

unity, 设置帧率上限

用unity做了个demo,把所有开销大的特效都去了,在真机上运行仍然卡。显示帧率来看,最高到30。原来unity在ios设备上帧率默认限制为不超过30。 可以通过Application.targetFrameRate = 60;改成最高60。注意这个设置对编辑器无效。 参考: http://answers.unity3d.com/questions/32...

Unity3D for iOS初级教程:Part 1/3(上)

                                                              Unity3D for iOS初级教程:Part 1/3(上) 这篇教材是来自教程团队成员 Christine Abernathy, 他是Facebook的开发支持团队的工程师。Unity是最为流行的游戏引擎之一。这是有充分缘由的:U...

Unity中嵌入网页插件Embedded Browser2.1.0

背景 最近刚换了工作,新公司不是做手游的,一开始有点抵触,总觉得不是做游戏自己就是跨行了,认为自己不对口,但是慢慢发现在这可以学的东西面很广,所以感觉又到了打怪升级的时候了,老子就在这进阶了。 一进公司他们使用H5开发,做一款地形信息系统的软件,基于Unity开发,但是所有页面都是Js写的,所以我第一件事要做的是实现Unity嵌入网页,并实现交互。 在这里...

记录一款Unity VR视频播放器插件的开发

效果图## 先上一个效果图: 背景 公司最近在做VR直播平台,VR开发我们用到了Unity,而在Unity中播放视频就需要一款视频插件,我们调研了几个视频插件,记录两个,如下: Unity视频插件调研 网上搜了搜,最流行的有以下两款Unity插件: AVPro 这个在Unity商店售价150$,最新release版本为1.6.15,功能包括: Power...