using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class User32 { private const int BCM_FIRST = 0x1600; private const int BCN_FIRST = -1250; /// Message identifiers used with the SendMessage function. [PInvokeData("winuser.h")] public enum ButtonMessage { /// /// Gets the check state of a radio button or check box. Return value is one of the values. /// BM_GETCHECK = 0x00F0, /// Sets the check state of a radio button or check box. wParam is one of the values. BM_SETCHECK = 0x00F1, /// Retrieves the state of a button or check box. Return value is one of the values. BM_GETSTATE = 0x00F2, /// /// Sets the highlight state of a button. The highlight state indicates whether the button is highlighted as if the user had /// pushed it. /// BM_SETSTATE = 0x00F3, /// Sets the style of a button. BM_SETSTYLE = 0x00F4, /// /// Simulates the user clicking a button. This message causes the button to receive the WM_LBUTTONDOWN and WM_LBUTTONUP messages, /// and the button's parent window to receive a BN_CLICKED notification code. /// BM_CLICK = 0x00F5, /// Retrieves a handle to the image (icon or bitmap) associated with the button. BM_GETIMAGE = 0x00F6, /// Associates a new image (icon or bitmap) with the button. BM_SETIMAGE = 0x00F7, /// Sets a flag on a radio button that controls the generation of BN_CLICKED messages when the button receives focus. BM_SETDONTCLICK = 0x00F8, /// Gets the size of the button that best fits its text and image, if an image list is present. BCM_GETIDEALSIZE = BCM_FIRST + 0x0001, /// Assigns an image list to a button control. BCM_SETIMAGELIST = BCM_FIRST + 0x0002, /// Gets the BUTTON_IMAGELIST structure that describes the image list assigned to a button control. BCM_GETIMAGELIST = BCM_FIRST + 0x0003, /// The BCM_SETTEXTMARGIN message sets the margins for drawing text in a button control. BCM_SETTEXTMARGIN = BCM_FIRST + 0x0004, /// Gets the margins used to draw text in a button control. BCM_GETTEXTMARGIN = BCM_FIRST + 0x0005, /// Sets the drop down state for a button with style TBSTYLE_DROPDOWN. BCM_SETDROPDOWNSTATE = BCM_FIRST + 0x0006, /// Sets information for a split button control. BCM_SETSPLITINFO = BCM_FIRST + 0x0007, /// Gets information for a split button control. BCM_GETSPLITINFO = BCM_FIRST + 0x0008, /// Sets the text of the note associated with a command link button. BCM_SETNOTE = BCM_FIRST + 0x0009, /// Gets the text of the note associated with a command link button. BCM_GETNOTE = BCM_FIRST + 0x000A, /// Gets the length of the note text that may be displayed in the description for a command link button. BCM_GETNOTELENGTH = BCM_FIRST + 0x000B, /// Sets the elevation required state for a specified button or command link to display an elevated icon. BCM_SETSHIELD = BCM_FIRST + 0x000C, } /// Notifications for buttons. [PInvokeData("winuser.h")] public enum ButtonNotification { /// /// Sent when the user clicks a button. The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_CLICKED = 0, /// /// Sent when a button should be painted. This notification code is provided only for compatibility with 16-bit /// versions of Windows earlier than version 3.0. Applications should use the BS_OWNERDRAW button style and the DRAWITEMSTRUCT /// structure for this task. /// The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_PAINT = 1, /// /// Sent when the user selects a button. This notification code is provided only for compatibility with 16-bit /// versions of Windows earlier than version 3.0. Applications should use the BS_OWNERDRAW button style and the DRAWITEMSTRUCT /// structure for this task. /// The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_HILITE = 2, /// /// Sent when the highlight should be removed from a button. This notification code is provided only for /// compatibility with 16-bit versions of Windows earlier than version 3.0. Applications should use the BS_OWNERDRAW button style /// and the DRAWITEMSTRUCT structure for this task. /// The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_UNHILITE = 3, /// /// Sent when a button is disabled. This notification code is provided only for compatibility with 16-bit /// versions of Windows earlier than version 3.0. Applications should use the BS_OWNERDRAW button style and the DRAWITEMSTRUCT /// structure for this task. /// The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_DISABLE = 4, /// /// Sent when the user double-clicks a button. This notification code is sent automatically for BS_USERBUTTON, BS_RADIOBUTTON, /// and BS_OWNERDRAW buttons. Other button types send BN_DBLCLK only if they have the BS_NOTIFY style. The parent window of the /// button receives this notification code through the WM_COMMAND message. /// BN_DOUBLECLICKED = 5, /// /// Sent when the push state of a button is set to pushed. This notification code is provided only for /// compatibility with 16-bit versions of Windows earlier than version 3.0. Applications should use the BS_OWNERDRAW button style /// and the DRAWITEMSTRUCT structure for this task. /// The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_PUSHED = BN_HILITE, /// /// Sent when the push state of a button is set to unpushed. This notification code is provided only for /// compatibility with 16-bit versions of Windows earlier than version 3.0. Applications should use the BS_OWNERDRAW button style /// and the DRAWITEMSTRUCT structure for this task. /// The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_UNPUSHED = BN_UNHILITE, /// /// Sent when the user double-clicks a button. This notification code is sent automatically for BS_USERBUTTON, BS_RADIOBUTTON, /// and BS_OWNERDRAW buttons. Other button types send BN_DBLCLK only if they have the BS_NOTIFY style. The parent window of the /// button receives this notification code through the WM_COMMAND message. /// BN_DBLCLK = BN_DOUBLECLICKED, /// /// Sent when a button receives the keyboard focus. The button must have the BS_NOTIFY style to send this notification code. /// The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_SETFOCUS = 6, /// /// Sent when a button loses the keyboard focus. The button must have the BS_NOTIFY style to send this notification code. /// The parent window of the button receives this notification code through the WM_COMMAND message. /// BN_KILLFOCUS = 7, /// /// Notifies the button control owner that the mouse is entering or leaving the client area of the button control. The button /// control sends this notification code in the form of a WM_NOTIFY message. /// BCN_HOTITEMCHANGE = BCN_FIRST + 0x0001, /// /// Sent when the user clicks a drop down arrow on a button. The parent window of the control receives this notification code in /// the form of a WM_NOTIFY message. /// BCN_DROPDOWN = BCN_FIRST + 0x0002, /// /// Sent by a button control to its parent to get measurements for the two rectangles of the split button. This notification code /// is sent in the form of a WM_NOTIFY message. /// /// /// lParam /// /// A pointer to an NMCUSTOMSPLITRECTINFO to receive bounding rectangles information. The NMCUSTOMSPLITRECTINFO structure is sent /// with the notification code as a request for the parent to provide measurements for the rectangles of the split button. /// /// /// /// Return value /// /// Return CDRF_SKIPDEFAULT to tell the button control to use the values returned in the NMCUSTOMSPLITRECTINFO structure; /// otherwise, return CDRF_DODEFAULT. /// /// /// /// NM_GETCUSTOMSPLITRECT = BCN_FIRST + 0x0003, } /// Flags indicating the state of buttons. [PInvokeData("winuser.h")] [Flags] public enum ButtonStateFlags { /// No special state. Equivalent to zero. BST_UNCHECKED = 0x0000, /// The button is checked. BST_CHECKED = 0x0001, /// The state of the button is indeterminate. Applies only if the button has the BS_3STATE or BS_AUTO3STATE style. BST_INDETERMINATE = 0x0002, /// The button is being shown in the pushed state. BST_PUSHED = 0x0004, /// The button has the keyboard focus. BST_FOCUS = 0x0008, /// The button is hot; that is, the mouse is hovering over it. BST_HOT = 0x0200, /// /// Windows Vista. The button is in the drop-down state. Applies only if the button has the TBSTYLE_DROPDOWN style. /// BST_DROPDOWNPUSHED = 0x0400 } /// /// Specifies a combination of button styles. If you create a button using the BUTTON class with the CreateWindow or CreateWindowEx /// function, you can specify any of the button styles listed below. /// [PInvokeData("winuser.h", MSDNShortId = "30254cb5-43cd-407f-8ad6-bd7f9ec3edc7")] [Flags] public enum ButtonStyle { /// /// Creates a button that is the same as a check box, except that the box can be grayed as well as checked or cleared. Use the /// grayed state to show that the state of the check box is not determined. /// BS_3STATE = 0x00000005, /// /// Creates a button that is the same as a three-state check box, except that the box changes its state when the user selects it. /// The state cycles through checked, indeterminate, and cleared. /// BS_AUTO3STATE = 0x00000006, /// /// Creates a button that is the same as a check box, except that the check state automatically toggles between checked and /// cleared each time the user selects the check box. /// BS_AUTOCHECKBOX = 0x00000003, /// /// Creates a button that is the same as a radio button, except that when the user selects it, the system automatically sets the /// button's check state to checked and automatically sets the check state for all other buttons in the same group to cleared. /// BS_AUTORADIOBUTTON = 0x00000009, /// Specifies that the button displays a bitmap. See the Remarks section for its interaction with BS_ICON. BS_BITMAP = 0x00000080, /// Places text at the bottom of the button rectangle. BS_BOTTOM = 0x00000800, /// Centers text horizontally in the button rectangle. BS_CENTER = 0x00000300, /// /// Creates a small, empty check box with text. By default, the text is displayed to the right of the check box. To display the /// text to the left of the check box, combine this flag with the BS_LEFTTEXT style (or with the equivalent BS_RIGHTBUTTON style). /// BS_CHECKBOX = 0x00000002, /// /// Creates a command link button that behaves like a BS_PUSHBUTTON style button, but the command link button has a green arrow /// on the left pointing to the button text. A caption for the button text can be set by sending the BCM_SETNOTE message to the button. /// BS_COMMANDLINK = 0x0000000E, /// /// Creates a command link button that behaves like a BS_PUSHBUTTON style button. If the button is in a dialog box, the user can /// select the command link button by pressing the ENTER key, even when the command link button does not have the input focus. /// This style is useful for enabling the user to quickly select the most likely (default) option. /// BS_DEFCOMMANDLINK = 0x0000000F, /// /// Creates a push button that behaves like a BS_PUSHBUTTON style button, but has a distinct appearance. If the button is in a /// dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. /// This style is useful for enabling the user to quickly select the most likely (default) option. /// BS_DEFPUSHBUTTON = 0x00000001, /// /// Creates a split button that behaves like a BS_PUSHBUTTON style button, but also has a distinctive appearance. If the split /// button is in a dialog box, the user can select the split button by pressing the ENTER key, even when the split button does /// not have the input focus. This style is useful for enabling the user to quickly select the most likely (default) option. /// BS_DEFSPLITBUTTON = 0x0000000D, /// /// Creates a rectangle in which other controls can be grouped. Any text associated with this style is displayed in the /// rectangle's upper left corner. /// BS_GROUPBOX = 0x00000007, /// Specifies that the button displays an icon. See the Remarks section for its interaction with BS_BITMAP. BS_ICON = 0x00000040, /// Specifies that the button is two-dimensional; it does not use the default shading to create a 3-D image. BS_FLAT = 0x00008000, /// /// Left-justifies the text in the button rectangle. However, if the button is a check box or radio button that does not have the /// BS_RIGHTBUTTON style, the text is left justified on the right side of the check box or radio button. /// BS_LEFT = 0x00000100, /// /// Places text on the left side of the radio button or check box when combined with a radio button or check box style. Same as /// the BS_RIGHTBUTTON style. /// BS_LEFTTEXT = 0x00000020, /// /// Wraps the button text to multiple lines if the text string is too long to fit on a single line in the button rectangle. /// BS_MULTILINE = 0x00002000, /// /// Enables a button to send BN_KILLFOCUS and BN_SETFOCUS notification codes to its parent window. /// /// Note that buttons send the BN_CLICKED notification code regardless of whether it has this style. To get BN_DBLCLK /// notification codes, the button must have the BS_RADIOBUTTON or BS_OWNERDRAW style. /// /// BS_NOTIFY = 0x00004000, /// /// Creates an owner-drawn button. The owner window receives a WM_DRAWITEM message when a visual aspect of the button has /// changed. Do not combine the BS_OWNERDRAW style with any other button styles. /// BS_OWNERDRAW = 0x0000000B, /// Creates a push button that posts a WM_COMMAND message to the owner window when the user selects the button. BS_PUSHBUTTON = 0x00000000, /// /// Makes a button (such as a check box, three-state check box, or radio button) look and act like a push button. The button /// looks raised when it isn't pushed or checked, and sunken when it is pushed or checked. /// BS_PUSHLIKE = 0x00001000, /// /// Creates a small circle with text. By default, the text is displayed to the right of the circle. To display the text to the /// left of the circle, combine this flag with the BS_LEFTTEXT style (or with the equivalent BS_RIGHTBUTTON style). Use radio /// buttons for groups of related, but mutually exclusive choices. /// BS_RADIOBUTTON = 0x00000004, /// /// Right-justifies text in the button rectangle. However, if the button is a check box or radio button that does not have the /// BS_RIGHTBUTTON style, the text is right justified on the right side of the check box or radio button. /// BS_RIGHT = 0x00000200, /// /// Positions a radio button's circle or a check box's square on the right side of the button rectangle. Same as the BS_LEFTTEXT style. /// BS_RIGHTBUTTON = BS_LEFTTEXT, /// Creates a split button. A split button has a drop down arrow. BS_SPLITBUTTON = 0x0000000C, /// Specifies that the button displays text. BS_TEXT = 0x00000000, /// Places text at the top of the button rectangle. BS_TOP = 0x00000400, /// /// Do not use this style. A composite style bit that results from using the OR operator on BS_* style bits. It can be used to /// mask out valid BS_* bits from a given bitmask. Note that this is out of date and does not correctly include all valid styles. /// Thus, you should not use this style. /// BS_TYPEMASK = 0x0000000F, /// /// Obsolete, but provided for compatibility with 16-bit versions of Windows. Applications should use BS_OWNERDRAW instead. /// BS_USERBUTTON = 0x00000008, /// Places text in the middle (vertically) of the button rectangle. BS_VCENTER = 0x00000C00, } /// /// Changes the check state of a button control. /// /// /// Type: HWND /// A handle to the dialog box that contains the button. /// /// /// Type: int /// The identifier of the button to modify. /// /// /// Type: UINT /// The check state of the button. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// BST_CHECKED /// Sets the button state to checked. /// /// /// BST_INDETERMINATE /// /// Sets the button state to grayed, indicating an indeterminate state. Use this value only if the button has the BS_3STATE or /// BS_AUTO3STATE style. /// /// /// /// BST_UNCHECKED /// Sets the button state to cleared /// /// /// /// /// Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// The CheckDlgButton function sends a BM_SETCHECK message to the specified button control in the specified dialog box. /// /// Examples /// For an example, see Creating a Modeless Dialog Box in Using Dialog Boxes. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-checkdlgbutton BOOL CheckDlgButton( HWND hDlg, int // nIDButton, UINT uCheck ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "checkdlgbutton")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CheckDlgButton(HWND hDlg, int nIDButton, ButtonStateFlags uCheck); /// /// /// Adds a check mark to (checks) a specified radio button in a group and removes a check mark from (clears) all other radio buttons /// in the group. /// /// /// /// Type: HWND /// A handle to the dialog box that contains the radio button. /// /// /// Type: int /// The identifier of the first radio button in the group. /// /// /// Type: int /// The identifier of the last radio button in the group. /// /// /// Type: int /// The identifier of the radio button to select. /// /// /// Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// The CheckRadioButton function sends a BM_SETCHECK message to each of the radio buttons in the indicated group. /// /// The nIDFirstButton and nIDLastButton parameters specify a range of button identifiers (normally the resource IDs of the buttons). /// The position of buttons in the tab order is irrelevant; if a button forms part of a group, but has an ID outside the specified /// range, it is not affected by this call. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-checkradiobutton BOOL CheckRadioButton( HWND hDlg, int // nIDFirstButton, int nIDLastButton, int nIDCheckButton ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "checkradiobutton")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CheckRadioButton(HWND hDlg, int nIDFirstButton, int nIDLastButton, int nIDCheckButton); /// /// /// The IsDlgButtonChecked function determines whether a button control is checked or whether a three-state button control is /// checked, unchecked, or indeterminate. /// /// /// /// Type: HWND /// A handle to the dialog box that contains the button control. /// /// /// Type: int /// The identifier of the button control. /// /// /// Type: UINT /// /// The return value from a button created with the BS_AUTOCHECKBOX, BS_AUTORADIOBUTTON, BS_AUTO3STATE, BS_CHECKBOX, BS_RADIOBUTTON, /// or BS_3STATE styles can be one of the values in the following table. If the button has any other style, the return value is zero. /// /// /// /// Return code /// Description /// /// /// BST_CHECKED /// The button is checked. /// /// /// BST_INDETERMINATE /// The button is in an indeterminate state (applies only if the button has the BS_3STATE or BS_AUTO3STATE style). /// /// /// BST_UNCHECKED /// The button is not checked. /// /// /// /// /// The IsDlgButtonChecked function sends a BM_GETCHECK message to the specified button control. /// Examples /// For an example, see the section titled "Creating a Modeless Dialog Box" in Using Dialog Boxes. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-isdlgbuttonchecked UINT IsDlgButtonChecked( HWND hDlg, int // nIDButton ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "isdlgbuttonchecked")] public static extern ButtonStateFlags IsDlgButtonChecked(HWND hDlg, int nIDButton); } }