using System;using System.Collections.Generic;using System.Linq;using System.Runtime.CompilerServices;using System.Runtime.InteropServices;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using 桌面窗口管理器;using static System.Windows.Forms.VisualStyles.VisualStyleElement;using static WindowsFormsApp4.HungAppCheckDialog;using static WindowsFormsApp4.Win32InternalDefaultDialogClass;namespace WindowsFormsApp4{public class Win32InternalDefaultDialogClass{// 常量定义public const int WM_INITDIALOG 0x0110;public const int WM_CLOSE 0x0010;public const int WM_DESTROY 0x0002;public const int SW_SHOWNORMAL 1;public const int WM_COMMAND 0x0111;public const int BN_CLICKED 0;// 必要的 Win32 API 导入[DllImport(user32.dll, SetLastError true)]public static extern IntPtr CreateDialogParam(IntPtr hInstance, string lpTemplateName, IntPtr hWndParent, DialogProc lpDialogFunc, IntPtr dwInitParam);[DllImport(user32.dll, SetLastError true)]public static extern IntPtr DialogBoxParam(IntPtr hInstance, string lpTemplateName, IntPtr hWndParent, DialogProc lpDialogFunc, IntPtr dwInitParam);[DllImport(user32.dll, SetLastError true)]public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);[DllImport(user32.dll, SetLastError true)]public static extern bool EnableWindow(IntPtr hWnd, bool bEnable);[DllImport(user32.dll, SetLastError true)]public static extern bool DestroyWindow(IntPtr hWnd);[DllImport(user32.dll, SetLastError true)]public static extern bool PostQuitMessage(int nExitCode);[DllImport(user32.dll, SetLastError true)]public static extern bool IsDialogMessage(IntPtr hDlg, ref MSG msg);[DllImport(user32.dll, SetLastError true)]public static extern bool GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);[DllImport(user32.dll, SetLastError true)]public static extern bool TranslateMessage(ref MSG msg);[DllImport(user32.dll, SetLastError true)]public static extern IntPtr DispatchMessage(ref MSG msg);[DllImport(kernel32.dll, SetLastError true, CharSet CharSet.Unicode)]public static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, uint dwFlags);[DllImport(kernel32.dll, SetLastError true)]public static extern bool FreeLibrary(IntPtr hModule);[DllImport(user32.dll, SetLastError true)]public static extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);// 常量public const uint LOAD_LIBRARY_AS_DATAFILE 0x00000002;// 定义 MSG 结构用于消息循环[StructLayout(LayoutKind.Sequential)]public struct MSG{public IntPtr hwnd;public uint message;public IntPtr wParam;public IntPtr lParam;public uint time;public int pt_x;public int pt_y;}[DllImport(user32.dll)]public static extern IntPtr DefWindowProcW(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);public delegate IntPtr DialogProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);}public class HungAppCheckDialog : CommonDialog{public DialogProc _dialogProc;public HungAppCheckDialog(){_dialogProc DialogProc2;}public IntPtr DialogProc2(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam){int cmd (int)(wParam.ToInt64() 0xFFFF); // 低字为控件IDint notifyCode (int)((wParam.ToInt64() 16) 0xFFFF); // 高字为通知码switch (msg){case WM_COMMAND:if (notifyCode BN_CLICKED cmd 1) // 假设按钮ID为1001{KillProcessButtonClicked.Invoke(null, null);EWindow.EForm.FromHandle(hDlg).Close_P();}if (notifyCode BN_CLICKED cmd 2) // 假设按钮ID为1001{EWindow.EForm.FromHandle(hDlg).Close_P();}return IntPtr.Zero; // 已处理default:return DefWindowProcW(hWnd, msg, wParam, lParam);}}public EventHandler KillProcessButtonClicked;public override void Reset() { }IntPtr hDlg;// 核心RunDialog 实现模态显示protected override bool RunDialog(IntPtr hwndOwner){IntPtr hModule LoadLibraryEx(c:\\windows\\system32\\dwm.exe,IntPtr.Zero,LOAD_LIBRARY_AS_DATAFILE);if (hModule IntPtr.Zero)return false; // 加载失败hDlg CreateDialogParam(hModule,#1000,hwndOwner,_dialogProc,IntPtr.Zero);if (hDlg IntPtr.Zero){FreeLibrary(hModule);return false;}ShowWindow(hDlg, SW_SHOWNORMAL);if (hwndOwner ! IntPtr.Zero)EnableWindow(hwndOwner, false);MSG msg;while (GetMessage(out msg, IntPtr.Zero, 0, 0)){if (!IsDialogMessage(hDlg, ref msg)){TranslateMessage(ref msg);DispatchMessage(ref msg);}if (!EWindow.EForm.FromHandle(hDlg).IsWindow){EnableWindow(hwndOwner, true);FreeLibrary(hModule);return true;}}if (hwndOwner ! IntPtr.Zero)EnableWindow(hwndOwner, true);FreeLibrary(hModule);return true;}}public class ErrorMessageViewerDialog : CommonDialog{public DialogProc _dialogProc;public ErrorMessageViewerDialog(){_dialogProc DialogProc2;}public IntPtr DialogProc2(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam){int cmd (int)(wParam.ToInt64() 0xFFFF); // 低字为控件IDint notifyCode (int)((wParam.ToInt64() 16) 0xFFFF); // 高字为通知码switch (msg){case WM_COMMAND:if (notifyCode BN_CLICKED cmd 1) // 假设按钮ID为1001{}return IntPtr.Zero; // 已处理default:return DefWindowProcW(hWnd, msg, wParam, lParam);}}public EventHandler KillProcessButtonClicked;public override void Reset() { }// 核心RunDialog 实现模态显示protected override bool RunDialog(IntPtr hwndOwner){IntPtr hModule LoadLibraryEx(c:\\windows\\system32\\appmgr.dll,IntPtr.Zero,LOAD_LIBRARY_AS_DATAFILE);if (hModule IntPtr.Zero)return false; // 加载失败IntPtr hDlg CreateDialogParam(hModule,#220,hwndOwner,_dialogProc,IntPtr.Zero);if (hDlg IntPtr.Zero){FreeLibrary(hModule);return false;}ShowWindow(hDlg, SW_SHOWNORMAL);if (hwndOwner ! IntPtr.Zero)EnableWindow(hwndOwner, false);MSG msg;while (GetMessage(out msg, IntPtr.Zero, 0, 0)){if (!IsDialogMessage(hDlg, ref msg)){TranslateMessage(ref msg);DispatchMessage(ref msg);}if (!EWindow.EForm.FromHandle(hDlg).IsWindow){EnableWindow(hwndOwner, true);FreeLibrary(hModule);return true;}}if (hwndOwner ! IntPtr.Zero)EnableWindow(hwndOwner, true);FreeLibrary(hModule);return true;}}public class SeccionsMessageDialog : CommonDialog{public DialogProc _dialogProc;public SeccionsMessageDialog(){_dialogProc DialogProc2;}public IntPtr DialogProc2(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam){int cmd (int)(wParam.ToInt64() 0xFFFF); // 低字为控件IDint notifyCode (int)((wParam.ToInt64() 16) 0xFFFF); // 高字为通知码switch (msg){case WM_COMMAND:if (notifyCode BN_CLICKED cmd 1) // 假设按钮ID为1001{}return IntPtr.Zero; // 已处理default:return DefWindowProcW(hWnd, msg, wParam, lParam);}}public EventHandler KillProcessButtonClicked;public override void Reset() { }// 核心RunDialog 实现模态显示protected override bool RunDialog(IntPtr hwndOwner){IntPtr hModule LoadLibraryEx(c:\\windows\\system32\\taskmgr.exe,IntPtr.Zero,LOAD_LIBRARY_AS_DATAFILE);if (hModule IntPtr.Zero)return false; // 加载失败IntPtr hDlg CreateDialogParam(hModule,#34850,hwndOwner,_dialogProc,IntPtr.Zero);if (hDlg IntPtr.Zero){FreeLibrary(hModule);return false;}ShowWindow(hDlg, SW_SHOWNORMAL);if (hwndOwner ! IntPtr.Zero)EnableWindow(hwndOwner, false);MSG msg;while (GetMessage(out msg, IntPtr.Zero, 0, 0)){if (!IsDialogMessage(hDlg, ref msg)){TranslateMessage(ref msg);DispatchMessage(ref msg);}if (!EWindow.EForm.FromHandle(hDlg).IsWindow){EnableWindow(hwndOwner, true);FreeLibrary(hModule);return true;}}if (hwndOwner ! IntPtr.Zero)EnableWindow(hwndOwner, true);FreeLibrary(hModule);return true;}}public class RenameDialog : CommonDialog{public DialogProc _dialogProc;public RenameDialog(){_dialogProc DialogProc2;}public IntPtr DialogProc2(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam){int cmd (int)(wParam.ToInt64() 0xFFFF); // 低字为控件IDint notifyCode (int)((wParam.ToInt64() 16) 0xFFFF); // 高字为通知码switch (msg){case WM_COMMAND:if (notifyCode BN_CLICKED cmd 1) // 假设按钮ID为1001{}return IntPtr.Zero; // 已处理default:return DefWindowProcW(hWnd, msg, wParam, lParam);}}public EventHandler KillProcessButtonClicked;public override void Reset() { }// 核心RunDialog 实现模态显示protected override bool RunDialog(IntPtr hwndOwner){IntPtr hModule LoadLibraryEx(c:\\windows\\system32\\shell32.dll,IntPtr.Zero,LOAD_LIBRARY_AS_DATAFILE);if (hModule IntPtr.Zero)return false; // 加载失败IntPtr hDlg CreateDialogParam(hModule,#8192,hwndOwner,_dialogProc,IntPtr.Zero);if (hDlg IntPtr.Zero){FreeLibrary(hModule);return false;}ShowWindow(hDlg, SW_SHOWNORMAL);if (hwndOwner ! IntPtr.Zero)EnableWindow(hwndOwner, false);MSG msg;while (GetMessage(out msg, IntPtr.Zero, 0, 0)){if (!IsDialogMessage(hDlg, ref msg)){TranslateMessage(ref msg);DispatchMessage(ref msg);}if (!EWindow.EForm.FromHandle(hDlg).IsWindow){EnableWindow(hwndOwner, true);FreeLibrary(hModule);return true;}}if (hwndOwner ! IntPtr.Zero)EnableWindow(hwndOwner, true);FreeLibrary(hModule);return true;}}}