zoukankan      html  css  js  c++  java
  • 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, "测试代码");
    }
    }
  • 相关阅读:
    你的课程
    asp.net的ajax以及json
    asp.net自带的异步刷新控件使用
    基于.net mvc的校友录(源程序)
    基于.net mvc的校友录(七、文件上传以及多对多关系表的LINQ查询实现)
    基于.net mvc的校友录(六、codefirst的使用以及班级模块的关键部分实现)
    逻辑回归实例
    层次聚类
    k均值聚类
    数据处理与转换
  • 原文地址:https://www.cnblogs.com/Peng18233754457/p/9816576.html
Copyright © 2011-2022 走看看