MessageBox() private method

private MessageBox ( int hWnd, String text, String caption, uint type ) : int
hWnd int
text String
caption String
type uint
return int
コード例 #1
0
ファイル: Homework.cs プロジェクト: Gabatawr/Project.cs
        public static void Run()
        {
            List <(string, string)> list = new List <(string, string)>
            {
                ("Kashyrin Artem", "About"),
                ("Test 2", "2"),
                ("Test 3", "3"),
                ("Test 4", "4"),
                ("Test 5", "5"),
                (@"https://github.com/Gabatawr", "GitHub")
            };

            int i = 0;

            User32.MB_RValue ret;
            User32.MB_Button btns = User32.MB_Button.MB_CANCELTRYCONTINUE;

            do
            {
                if (i == list.Count - 1)
                {
                    btns = User32.MB_Button.MB_OK;
                }
                ret = User32.MessageBox(new IntPtr(0), list[i].Item1, list[i].Item2, btns);
                i  += ret == User32.MB_RValue.IDTRYAGAIN ? 0 : 1;
            } while (ret != User32.MB_RValue.IDCANCEL && ret != User32.MB_RValue.IDOK);
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: dahall/WinClassicSamplesCS
        public static HRESULT DisplayItem(this IShellItemArray psia, HWND hwnd = default)
        {
            // Get the first ShellItem and display its name
            IShellItem psi            = psia.GetItemAt(0);
            var        pszDisplayName = psi.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY);

            User32.MessageBox(hwnd, pszDisplayName, pszDisplayName, User32.MB_FLAGS.MB_OK);
            return(HRESULT.S_OK);
        }
コード例 #3
0
ファイル: EntryPoint.cs プロジェクト: DeaTh-G/Reloaded-II
        private static void HandleException(Exception ex)
        {
            // This method is singled out to avoid loading System.Windows.Forms at startup; because it is lazy loaded.
            var errorMessage = $"Failed to Load Reloaded-II.\n{ex.Message}\n{ex.StackTrace}\nA log is available at: {_loader?.LogWriter?.FlushPath}";

            _loader?.Console?.WaitForConsoleInit();
            _loader?.Logger?.WriteLine(errorMessage, _loader.Logger.ColorRed);
            _loader?.LogWriter?.Flush();
            User32.MessageBox(0, errorMessage, "Oh Noes!", 0);
        }
コード例 #4
0
ファイル: App.xaml.cs プロジェクト: BlackGad/PS.Framework
        private void FatalShutdown(Exception e, string message)
        {
            _logger?.Fatal(e, message);
            Shutdown(-1);

            User32.MessageBox(IntPtr.Zero,
                              $"{message}. Details: {e.GetBaseException().Message}",
                              "Fatal error",
                              MessageBoxStyle.OK |
                              MessageBoxStyle.IconError);
        }
コード例 #5
0
    private static void HandleLoadError(Exception ex)
    {
        // This method is singled out to avoid loading System.Windows.Forms at startup; because it is lazy loaded.
        var errorMessage = $"Failed to Load Reloaded-II.\n{ex.Message}\n{ex.StackTrace}\nA log is available at: {_loader?.LogWriter?.FlushPath}";

        Exception innerException = ex.InnerException;

        while (innerException != null)
        {
            errorMessage  += $"\nInner Exception: {innerException.Message} | {innerException.StackTrace}";
            innerException = innerException.InnerException;
        }

        _loader?.Console?.WaitForConsoleInit();
        Logger?.LogWriteLine(errorMessage, Logger.ColorError);
        _loader?.LogWriter?.Flush();
        User32.MessageBox(0, errorMessage, "Oh Noes!", 0);
    }
コード例 #6
0
 protected void MessageBox(HWND hwnd, string msg, string caption = "Error") =>
 User32.MessageBox(hwnd, msg, caption, User32.MB_FLAGS.MB_OK);
コード例 #7
0
ファイル: MessageBox.cs プロジェクト: radtek/HinxCor
 /// <summary>
 /// 显示一个信息盒子, 阻断当前线程
 /// </summary>
 /// <param name="handle">载体窗口句柄</param>
 /// <param name="text">需要显示的Text主体内容</param>
 /// <param name="caption">标题</param>
 /// <param name="MB_CMDS">窗体命令,0 为空,可以自主选择命令组拼,注意不能重复使用相同组内容</param>
 /// <returns>窗体返回结果(用户点击的按钮)</returns>
 public static int Show(IntPtr handle, string text, string caption, LNG MB_CMDS)
 {
     return(User32.MessageBox(handle, text, caption, (int)MB_CMDS));
 }
コード例 #8
0
ファイル: MessageBox.cs プロジェクト: radtek/HinxCor
 /// <summary>
 /// 显示一个信息盒子, 阻断当前线程
 /// </summary>
 /// <param name="handle">载体窗口句柄</param>
 /// <param name="text">需要显示的Text主体内容</param>
 /// <param name="caption">标题</param>
 /// <param name="buttons">窗体提供的按钮选项,用户选择结果将返回</param>
 /// <param name="icon">信息盒子的提示图标(信息类型)</param>
 /// <param name="defaultButton">默认选择的按钮(注意有无第四项)</param>
 /// <param name="options">信息盒子选项</param>
 /// <param name="displayHelpButton">是否显示帮助按钮</param>
 /// <returns>窗体返回结果(用户点击的按钮)</returns>
 public static DialogResult ShowTopMost(IntPtr handle, string text, string caption, DefaultButtons buttons, DefaultICON icon, DefaultSelectedButton defaultButton, MessageBoxOptions options, bool displayHelpButton)
 {
     return((DialogResult)User32.MessageBox(handle, text, caption, GetCMD((LNG)buttons, (LNG)icon, (LNG)defaultButton, (LNG)options, MB_TOPMOST, displayHelpButton ? MB_HELP : 0)));
 }
コード例 #9
0
ファイル: MessageBox.cs プロジェクト: radtek/HinxCor
 /// <summary>
 /// 显示一个信息盒子, 阻断当前线程
 /// </summary>
 /// <param name="text">需要显示的Text主体内容</param>
 /// <param name="caption">标题</param>
 /// <param name="buttons">窗体提供的按钮选项,用户选择结果将返回</param>
 /// <param name="icon">信息盒子的提示图标(信息类型)</param>
 /// <param name="defaultButton">默认选择的按钮(注意有无第四项)</param>
 /// <param name="options">信息盒子选项</param>
 /// <param name="displayHelpButton">是否显示帮助按钮</param>
 /// <returns>窗体返回结果(用户点击的按钮)</returns>
 public static DialogResult Show(string text, string caption, DefaultButtons buttons, DefaultICON icon, DefaultSelectedButton defaultButton, MessageBoxOptions options, bool displayHelpButton)
 {
     return((DialogResult)User32.MessageBox(User32.GetForegroundWindow(), text, caption, GetCMD((LNG)buttons, (LNG)icon, (LNG)defaultButton, (LNG)options, displayHelpButton ? MB_HELP : 0)));
 }
コード例 #10
0
    private static unsafe int HandleCrash(IntPtr exceptionPtrs)
    {
        var exceptionPointers = (EXCEPTION_POINTERS *)exceptionPtrs;

        try
        {
            var currentLogPath = _loader.LogWriter.FlushPath;

            // Determine Paths
            var logFolderName = Path.GetFileNameWithoutExtension(currentLogPath);
            var dumpFolder    = Path.Combine(Paths.CrashDumpPath, logFolderName !);
            var dumpPath      = Path.Combine(dumpFolder, "dump.dmp");
            var logPath       = Path.Combine(dumpFolder, Path.GetFileName(currentLogPath) !);
            var infoPath      = Path.Combine(dumpFolder, "info.json" !);
            Directory.CreateDirectory(dumpFolder);

            // Flush log.
            Logger?.LogWriteLine("Crashed. Generating Crash Dump. Might take a while.", Logger.ColorError);
            Logger?.Shutdown();
            _loader.LogWriter.Flush();
            _loader.LogWriter.Dispose();

            File.Copy(currentLogPath, logPath, true);

            // Let's create our crash dump.
            using var crashDumpFile = new FileStream(dumpPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            var exceptionInfo = new Kernel32.MinidumpExceptionInformation()
            {
                ThreadId          = Kernel32.GetCurrentThread(),
                ExceptionPointers = (IntPtr)exceptionPointers,
                ClientPointers    = true
            };

            // 289 is the default for Minidumps made by Windows Error Reporting.
            // Figured this out by opening one in hex editor.
            Kernel32.MiniDumpWriteDump(_process.Handle, (uint)_process.Id, crashDumpFile.SafeFileHandle, (MinidumpType)289, ref exceptionInfo, IntPtr.Zero, IntPtr.Zero);

            // Inform the user.
            var info = new CrashDumpInfo(_loader, exceptionPointers);
            File.WriteAllText(infoPath, JsonSerializer.Serialize(info, new JsonSerializerOptions()
            {
                WriteIndented = true,
                Converters    = { new JsonStringEnumConverter() }
            }));
            User32.MessageBox(0, $"Crash information saved. If you believe this crash is mod related, ask for mod author(s) support. Otherwise, delete the generated files.\n\n" +
                              $"Info for nerds:\n" +
                              $"Crash Address: {info.CrashAddress}\n" +
                              $"Faulting Module: {info.FaultingModulePath}", "Shit! Program Crashed in Application Code!", 0);

            Process.Start(new ProcessStartInfo("cmd", $"/c start explorer \"{dumpFolder}\"")
            {
                CreateNoWindow = true,
                WindowStyle    = ProcessWindowStyle.Hidden
            });
            return((int)Kernel32.EXCEPTION_FLAG.EXCEPTION_EXECUTE_HANDLER);
        }
        catch (Exception e)
        {
            Console.WriteLine($"Epic Fail! Failed to create crash dump.\n" +
                              $"{e.Message}\n" +
                              $"{e.StackTrace}");
            return(0);
        }
    }
コード例 #11
0
 public static MessageBoxResult Show(IntPtr parent, string message, string caption, MessageBoxOptions options = MessageBoxOptions.OkOnly)
 {
     return((MessageBoxResult)User32.MessageBox(parent, message, caption, (uint)options));
 }