/// <summary> /// to enable/disable Outlook controls by passing Outlook control /// </summary> /// <param name="outlookControls"></param> /// <param name="value"></param> private static void Enable(OutlookControls outlookControls, bool value) { IntPtr controlButton = GetControl(outlookControls); EnableWindow(controlButton, value); }
/// <summary> /// to get reference of Control /// </summary> /// <param name="outlookControls"></param> /// <returns></returns> private static IntPtr GetControl(OutlookControls outlookControls) { IntPtr hwndControl = IntPtr.Zero; //Get a handle for the Calculator Application main window int hwnd = FindWindow("rctrl_renwnd32", null); IntPtr control = GetAllChildrenWindowHandles((IntPtr)hwnd, 100, "AfxWndW"); //525494 IntPtr control1 = GetAllChildrenWindowHandles((IntPtr)control, 100, "AfxWndW"); //525652 IntPtr control2 = GetAllChildrenWindowHandles((IntPtr)control1, 100, "#32770"); //394446 switch (outlookControls) { case OutlookControls.ToButton: hwndControl = GetAllChildrenWindowHandles((IntPtr)control2, 100, "Button", "To&..."); break; case OutlookControls.ToText: hwndControl = GetAllChildrenWindowHandles((IntPtr)control2, 100, "RichEdit20WPT", "To"); break; case OutlookControls.CcButton: hwndControl = GetAllChildrenWindowHandles((IntPtr)control2, 100, "Button", "&Cc..."); break; case OutlookControls.CcText: hwndControl = GetAllChildrenWindowHandles((IntPtr)control2, 100, "RichEdit20WPT", "Cc"); break; case OutlookControls.BccButton: hwndControl = GetAllChildrenWindowHandles((IntPtr)control2, 100, "Button", "&Bcc..."); break; case OutlookControls.BccText: hwndControl = GetAllChildrenWindowHandles((IntPtr)control2, 100, "RichEdit20WPT", "Bcc"); break; } return hwndControl; }