Skip to content

Instantly share code, notes, and snippets.

@harriyott
Last active September 25, 2015 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harriyott/915446 to your computer and use it in GitHub Desktop.
Save harriyott/915446 to your computer and use it in GitHub Desktop.
Enable the "leave" button in SourceSafe. Details at http://harriyott.com/2006/07/sourcesafe-cant-leave-well-alone.aspx
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 trWindowName);
[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";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment