MineStudio / KMCCC

An OpenSource Minecraft Launcher for .Net Developers
GNU Lesser General Public License v3.0
127 stars 34 forks source link

SetTitle函数有BUG #18

Closed mcoo closed 3 years ago

mcoo commented 4 years ago

当游戏窗口未加载时执行 handle.SetTitle("修改游戏窗口"); 会返回 True 实际未执行成功! 源代码:

public static bool SetTitle(this LaunchHandle handle, string title)
        {
            try
            {
                SetWindowText(handle.Process.MainWindowHandle, title);
                return true;
            }
            catch
            {
                return false;
            }
        }

这里的SetWindowText并不会触发try,当执行失败只会返回0,所以会造成判断错误! 贴上 修复后代码:

public static bool SetTitle(this LaunchHandle handle, string title)
        {
            try
            {
                if (SetWindowText(handle.Process.MainWindowHandle, title) != 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch
            {
                return false;
            }
        }