Sometimes i want disable a cancel button when installing my package, I am using visual studio installer.
I want to disable this cancel button from code side.
Here is a solution with the WIN32 API:
Here is my example code:
Win32 Function declaration:
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
Code to disable the button:
IntPtr hwndWindow = FindWindow("MsiDialogCloseClass", "Installer");
IntPtr hwndButton = FindWindowEx((IntPtr)hwndWindow, IntPtr.Zero, "Button", "Cancel");
if (EnableWindow(hwndButton, false))
{
//has been disabled
}
Here my test window: