namespace Harriyott.SourceSafeLeaveEnable
{
public partial class MainForm : Form
{
[DllImport("User32.dll")]
public static extern Int32 FindWindow(String lpClassName, String lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("User32.dll")]
public static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string strClassName, string strWindowName);
[DllImport("user32.dll")]
static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
public MainForm()
{
InitializeComponent();
}
private void btnEnable_Click(object sender, EventArgs e)
{
// Find the prompt window
int windowHandle = FindWindow(null, "WindowsForms10.Window.8.app.0.11ecf05");
if (windowHandle > 0)
{
// Find the radio button
int leaveHandle = FindWindowEx(windowHandle, 0, "Button", "&Leave this file?");
if (leaveHandle > 0)
{
EnableWindow((IntPtr)leaveHandle, true);
lblStatus.Text = "Enabled";
}
else
{
lblStatus.Text = "Cannot find the 'Leave this file?' control";
}
}
else
{
lblStatus.Text = "Cannot find the prompt window";
}
}
}
}