using System; using System.Runtime.InteropServices; using System.Text; namespace Vanara.PInvoke { public static partial class User32 { /// /// Application-defined callback function used with the CreateDialog and DialogBox families of functions. It processes /// messages sent to a modal or modeless dialog box. The DLGPROC type defines a pointer to this callback function. DialogProc /// is a placeholder for the application-defined function name. /// /// /// Type: HWND /// A handle to the dialog box. /// /// /// Type: UINT /// The message. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: INT_PTR /// /// Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the /// dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message. /// /// /// If the dialog box procedure processes a message that requires a specific return value, the dialog box procedure should set the /// desired return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult) immediately before returning /// TRUE. Note that you must call SetWindowLong immediately before returning TRUE; doing so earlier may result /// in the DWL_MSGRESULT value being overwritten by a nested dialog box message. /// /// /// The following messages are exceptions to the general rules stated above. Consult the documentation for the specific message for /// details on the semantics of the return value. /// /// // INT_PTR CALLBACK DialogProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam); https://msdn.microsoft.com/en-us/library/windows/desktop/ms645469(v=vs.85).aspx [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("Winuser.h", MSDNShortId = "ms645469")] public delegate IntPtr DialogProc([In] HWND hwndDlg, [In] uint uMsg, [In] IntPtr wParam, [In] IntPtr lParam); /// /// /// Creates a modeless dialog box from a dialog box template resource. The CreateDialog macro uses the CreateDialogParam function. /// /// /// /// Type: HINSTANCE /// /// A handle to the module which contains the dialog box template. If this parameter is NULL, then the current executable is used. /// /// /// /// Type: LPCTSTR /// /// The dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of /// the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter /// specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can use /// the MAKEINTRESOURCE macro to create this value. /// /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// None /// /// /// /// The CreateDialog function uses the CreateWindowEx function to create the dialog box. CreateDialog then sends a /// WM_INITDIALOG message (and a WM_SETFONT message if the template specifies the DS_SETFONT or DS_SHELLFONT style) to the /// dialog box procedure. The function displays the dialog box if the template specifies the WS_VISIBLE style. Finally, /// CreateDialog returns the window handle to the dialog box. /// /// /// After CreateDialog returns, the application displays the dialog box (if it is not already displayed) by using the /// ShowWindow function. The application destroys the dialog box by using the DestroyWindow function. To support keyboard navigation /// and other dialog box functionality, the message loop for the dialog box must call the IsDialogMessage function. /// /// Examples /// For an example, see Creating a Modeless Dialog Box. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-createdialoga void CreateDialogA( hInstance, lpName, // hWndParent, lpDialogFunc ); [PInvokeData("winuser.h", MSDNShortId = "createdialog")] public static SafeHWND CreateDialog(HINSTANCE hInstance, string lpName, HWND hWndParent, DialogProc lpDialogFunc) => CreateDialogParam(hInstance, lpName, hWndParent, lpDialogFunc); /// /// /// Creates a modeless dialog box from a dialog box template in memory. The CreateDialogIndirect macro uses the /// CreateDialogIndirectParam function. /// /// /// /// Type: HINSTANCE /// A handle to the module that creates the dialog box. /// /// /// Type: LPCDLGTEMPLATE /// /// A template that CreateDialogIndirect uses to create the dialog box. A dialog box template consists of a header that /// describes the dialog box, followed by one or more additional blocks of data that describe each of the controls in the dialog box. /// The template can use either the standard format or the extended format. /// /// /// In a standard template, the header is a DLGTEMPLATE structure followed by additional variable-length arrays. The data for each /// control consists of a DLGITEMTEMPLATE structure followed by additional variable-length arrays. /// /// /// In an extended dialog box template, the header uses the DLGTEMPLATEEX format and the control definitions use the /// DLGITEMTEMPLATEEX format. /// /// After CreateDialogIndirect returns, you can free the template, which is only used to get the dialog box started. /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// None /// /// /// /// The CreateDialogIndirect macro uses the CreateWindowEx function to create the dialog box. CreateDialogIndirect then /// sends a WM_INITDIALOG message to the dialog box procedure. If the template specifies the DS_SETFONT or DS_SHELLFONT style, the /// function also sends a WM_SETFONT message to the dialog box procedure. The function displays the dialog box if the template /// specifies the WS_VISIBLE style. Finally, CreateDialogIndirect returns the window handle to the dialog box. /// /// /// After CreateDialogIndirect returns, you can use the ShowWindow function to display the dialog box (if it is not already /// visible). To destroy the dialog box, use the DestroyWindow function. To support keyboard navigation and other dialog box /// functionality, the message loop for the dialog box must call the IsDialogMessage function. /// /// /// In a standard dialog box template, the DLGTEMPLATE structure and each of the DLGITEMTEMPLATE structures must be aligned on /// DWORD boundaries. The creation data array that follows a DLGITEMTEMPLATE structure must also be aligned on a /// DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries. /// /// /// In an extended dialog box template, the DLGTEMPLATEEX header and each of the DLGITEMTEMPLATEEX control definitions must be /// aligned on DWORD boundaries. The creation data array, if any, that follows a DLGITEMTEMPLATEEX structure must also /// be aligned on a DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries. /// /// /// All character strings in the dialog box template, such as titles for the dialog box and buttons, must be Unicode strings. Use the /// MultiByteToWideChar function to generate Unicode strings from ANSI strings. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-createdialogindirecta void CreateDialogIndirectA( // hInstance, lpTemplate, hWndParent, lpDialogFunc ); [PInvokeData("winuser.h", MSDNShortId = "createdialogindirect")] public static SafeHWND CreateDialogIndirect(HINSTANCE hInstance, IntPtr lpTemplate, HWND hWndParent, DialogProc lpDialogFunc) => CreateDialogIndirectParam(hInstance, lpTemplate, hWndParent, lpDialogFunc); /// /// /// Creates a modeless dialog box from a dialog box template in memory. Before displaying the dialog box, the function passes an /// application-defined value to the dialog box procedure as the lParam parameter of the WM_INITDIALOG message. An application can /// use this value to initialize dialog box controls. /// /// /// /// Type: HINSTANCE /// /// A handle to the module which contains the dialog box template. If this parameter is NULL, then the current executable is used. /// /// /// /// Type: LPCDLGTEMPLATE /// /// The template CreateDialogIndirectParam uses to create the dialog box. A dialog box template consists of a header that /// describes the dialog box, followed by one or more additional blocks of data that describe each of the controls in the dialog box. /// The template can use either the standard format or the extended format. /// /// /// In a standard template, the header is a DLGTEMPLATE structure followed by additional variable-length arrays. The data for each /// control consists of a DLGITEMTEMPLATE structure followed by additional variable-length arrays. /// /// /// In an extended dialog box template, the header uses the DLGTEMPLATEEX format and the control definitions use the /// DLGITEMTEMPLATEEX format. /// /// After CreateDialogIndirectParam returns, you can free the template, which is only used to get the dialog box started. /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// Type: LPARAM /// The value to pass to the dialog box in the lParam parameter of the WM_INITDIALOG message. /// /// /// Type: HWND /// If the function succeeds, the return value is the window handle to the dialog box. /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. /// /// /// /// The CreateDialogIndirectParam function uses the CreateWindowEx function to create the dialog box. /// CreateDialogIndirectParam then sends a WM_INITDIALOG message to the dialog box procedure. If the template specifies the /// DS_SETFONT or DS_SHELLFONT style, the function also sends a WM_SETFONT message to the dialog box procedure. The function displays /// the dialog box if the template specifies the WS_VISIBLE style. Finally, CreateDialogIndirectParam returns the /// window handle to the dialog box. /// /// /// After CreateDialogIndirectParam returns, you can use the ShowWindow function to display the dialog box (if it is not /// already visible). To destroy the dialog box, use the DestroyWindow function. To support keyboard navigation and other dialog box /// functionality, the message loop for the dialog box must call the IsDialogMessage function. /// /// /// In a standard dialog box template, the DLGTEMPLATE structure and each of the DLGITEMTEMPLATE structures must be aligned on /// DWORD boundaries. The creation data array that follows a DLGITEMTEMPLATE structure must also be aligned on a /// DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries. /// /// /// In an extended dialog box template, the DLGTEMPLATEEX header and each of the DLGITEMTEMPLATEEX control definitions must be /// aligned on DWORD boundaries. The creation data array, if any, that follows a DLGITEMTEMPLATEEX structure must also /// be aligned on a DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries. /// /// All character strings in the dialog box template, such as titles for the dialog box and buttons, must be Unicode strings. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-createdialogindirectparama HWND // CreateDialogIndirectParamA( HINSTANCE hInstance, LPCDLGTEMPLATEA lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM // dwInitParam ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "createdialogindirectparam")] public static extern SafeHWND CreateDialogIndirectParam(HINSTANCE hInstance, IntPtr lpTemplate, HWND hWndParent, DialogProc lpDialogFunc, [Optional] IntPtr dwInitParam); /// /// /// Creates a modeless dialog box from a dialog box template resource. Before displaying the dialog box, the function passes an /// application-defined value to the dialog box procedure as the lParam parameter of the WM_INITDIALOG message. An application can /// use this value to initialize dialog box controls. /// /// /// /// Type: HINSTANCE /// /// A handle to the module which contains the dialog box template. If this parameter is NULL, then the current executable is used. /// /// /// /// Type: LPCTSTR /// /// The dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of /// the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter /// specifies a resource identifier, its high-order word must be zero and low-order word must contain the identifier. You can use the /// MAKEINTRESOURCE macro to create this value. /// /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// Type: LPARAM /// The value to be passed to the dialog box procedure in the lParam parameter in the WM_INITDIALOG message. /// /// /// Type: HWND /// If the function succeeds, the return value is the window handle to the dialog box. /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. /// /// /// /// The CreateDialogParam function uses the CreateWindowEx function to create the dialog box. CreateDialogParam then /// sends a WM_INITDIALOG message (and a WM_SETFONT message if the template specifies the DS_SETFONT or DS_SHELLFONT style) to the /// dialog box procedure. The function displays the dialog box if the template specifies the WS_VISIBLE style. Finally, /// CreateDialogParam returns the window handle of the dialog box. /// /// /// After CreateDialogParam returns, the application displays the dialog box (if it is not already displayed) using the /// ShowWindow function. The application destroys the dialog box by using the DestroyWindow function. To support keyboard navigation /// and other dialog box functionality, the message loop for the dialog box must call the IsDialogMessage function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-createdialogparama HWND CreateDialogParamA( HINSTANCE // hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "createdialogparam")] public static extern SafeHWND CreateDialogParam(HINSTANCE hInstance, string lpTemplateName, HWND hWndParent, DialogProc lpDialogFunc, [Optional] IntPtr dwInitParam); /// /// /// Calls the default dialog box window procedure to provide default processing for any window messages that a dialog box with a /// private window class does not process. /// /// /// /// Type: HWND /// A handle to the dialog box. /// /// /// Type: UINT /// The message. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing and depends on the message sent. /// /// /// /// The DefDlgProc function is the window procedure for the predefined class of dialog box. This procedure provides internal /// processing for the dialog box by forwarding messages to the dialog box procedure and carrying out default processing for any /// messages that the dialog box procedure returns as FALSE. Applications that create custom window procedures for their /// custom dialog boxes often use DefDlgProc instead of the DefWindowProc function to carry out default message processing. /// /// /// Applications create custom dialog box classes by filling a WNDCLASS structure with appropriate information and registering the /// class with the RegisterClass function. Some applications fill the structure by using the GetClassInfo function, specifying the /// name of the predefined dialog box. In such cases, the applications modify at least the lpszClassName member before /// registering. In all cases, the cbWndExtra member of WNDCLASS for a custom dialog box class must be set to at least DLGWINDOWEXTRA. /// /// The DefDlgProc function must not be called by a dialog box procedure; doing so results in recursive execution. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-defdlgprocw LRESULT LRESULT DefDlgProcW( HWND hDlg, UINT // Msg, WPARAM wParam, LPARAM lParam ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "defdlgproc")] public static extern IntPtr DefDlgProc(HWND hDlg, uint Msg, IntPtr wParam, IntPtr lParam); /// /// /// Creates a modal dialog box from a dialog box template resource. DialogBox does not return control until the specified /// callback function terminates the modal dialog box by calling the EndDialog function. /// /// DialogBox is implemented as a call to the DialogBoxParam function. /// /// /// Type: HINSTANCE /// /// A handle to the module which contains the dialog box template. If this parameter is NULL, then the current executable is used. /// /// /// /// Type: LPCTSTR /// /// The dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of /// the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter /// specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can use /// the MAKEINTRESOURCE macro to create this value. /// /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// None /// /// /// /// The DialogBox macro uses the CreateWindowEx function to create the dialog box. DialogBox then sends a WM_INITDIALOG /// message (and a WM_SETFONT message if the template specifies the DS_SETFONT or DS_SHELLFONT style) to the dialog box procedure. /// The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), disables the /// owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box. /// /// /// When the dialog box procedure calls the EndDialog function, DialogBox destroys the dialog box, ends the message loop, /// enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box procedure when it /// called EndDialog. /// /// Examples /// For an example, see Creating a Modal Dialog Box. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-dialogboxa void DialogBoxA( hInstance, lpTemplate, // hWndParent, lpDialogFunc ); [PInvokeData("winuser.h", MSDNShortId = "dialogbox")] public static IntPtr DialogBox(HINSTANCE hInstance, string lpTemplate, HWND hWndParent, DialogProc lpDialogFunc) => DialogBoxParam(hInstance, lpTemplate, hWndParent, lpDialogFunc); /// /// /// Creates a modal dialog box from a dialog box template resource. DialogBox does not return control until the specified /// callback function terminates the modal dialog box by calling the EndDialog function. /// /// DialogBox is implemented as a call to the DialogBoxParam function. /// /// /// Type: HINSTANCE /// /// A handle to the module which contains the dialog box template. If this parameter is NULL, then the current executable is used. /// /// /// /// Type: LPCTSTR /// /// The dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of /// the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter /// specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can /// use the MAKEINTRESOURCE macro to create this value. /// /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// None /// /// /// /// The DialogBox macro uses the CreateWindowEx function to create the dialog box. DialogBox then sends a /// WM_INITDIALOG message (and a WM_SETFONT message if the template specifies the DS_SETFONT or DS_SHELLFONT style) to the dialog /// box procedure. The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), /// disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box. /// /// /// When the dialog box procedure calls the EndDialog function, DialogBox destroys the dialog box, ends the message loop, /// enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box procedure when /// it called EndDialog. /// /// Examples /// For an example, see Creating a Modal Dialog Box. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-dialogboxa void DialogBoxA( hInstance, lpTemplate, // hWndParent, lpDialogFunc ); [PInvokeData("winuser.h", MSDNShortId = "dialogbox")] public static IntPtr DialogBox(HINSTANCE hInstance, ResourceId lpTemplate, HWND hWndParent, DialogProc lpDialogFunc) => DialogBoxParam(hInstance, lpTemplate, hWndParent, lpDialogFunc); /// /// /// Creates a modal dialog box from a dialog box template in memory. DialogBoxIndirect does not return control until the /// specified callback function terminates the modal dialog box by calling the EndDialog function. /// /// DialogBoxIndirect is implemented as a call to the DialogBoxIndirectParam function. /// /// /// Type: HINSTANCE /// A handle to the module that creates the dialog box. /// /// /// Type: LPCDLGTEMPLATE /// /// The template that DialogBoxIndirect uses to create the dialog box. A dialog box template consists of a header that /// describes the dialog box, followed by one or more additional blocks of data that describe each of the controls in the dialog box. /// The template can use either the standard format or the extended format. /// /// /// In a standard template for a dialog box, the header is a DLGTEMPLATE structure followed by additional variable-length arrays. The /// data for each control consists of a DLGITEMTEMPLATE structure followed by additional variable-length arrays. /// /// /// In an extended template for a dialog box, the header uses the DLGTEMPLATEEX format and the control definitions use the /// DLGITEMTEMPLATEEX format. /// /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// None /// /// /// /// The DialogBoxIndirect macro uses the CreateWindowEx function to create the dialog box. DialogBoxIndirect then sends /// a WM_INITDIALOG message to the dialog box procedure. If the template specifies the DS_SETFONT or DS_SHELLFONT style, the function /// also sends a WM_SETFONT message to the dialog box procedure. The function displays the dialog box (regardless of whether the /// template specifies the WS_VISIBLE style), disables the owner window, and starts its own message loop to retrieve and /// dispatch messages for the dialog box. /// /// /// When the dialog box procedure calls the EndDialog function, DialogBoxIndirect destroys the dialog box, ends the message /// loop, enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box procedure /// when it called EndDialog. /// /// /// In a standard dialog box template, the DLGTEMPLATE structure and each of the DLGITEMTEMPLATE structures must be aligned on /// DWORD boundaries. The creation data array that follows a DLGITEMTEMPLATE structure must also be aligned on a /// DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries. /// /// /// In an extended dialog box template, the DLGTEMPLATEEX header and each of the DLGITEMTEMPLATEEX control definitions must be /// aligned on DWORD boundaries. The creation data array, if any, that follows a DLGITEMTEMPLATEEX structure must also /// be aligned on a DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries. /// /// /// All character strings in the dialog box template, such as titles for the dialog box and buttons, must be Unicode strings. Use the /// MultiByteToWideChar function to generate Unicode strings from ANSI strings. /// /// Examples /// For an example, see Creating a Template in Memory. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-dialogboxindirecta void DialogBoxIndirectA( hInstance, // lpTemplate, hWndParent, lpDialogFunc ); [PInvokeData("winuser.h", MSDNShortId = "dialogboxindirect")] public static IntPtr DialogBoxIndirect(HINSTANCE hInstance, IntPtr lpTemplate, HWND hWndParent, DialogProc lpDialogFunc) => DialogBoxIndirectParam(hInstance, lpTemplate, hWndParent, lpDialogFunc); /// /// /// Creates a modal dialog box from a dialog box template in memory. Before displaying the dialog box, the function passes an /// application-defined value to the dialog box procedure as the lParam parameter of the WM_INITDIALOG message. An application can /// use this value to initialize dialog box controls. /// /// /// /// Type: HINSTANCE /// A handle to the module that creates the dialog box. /// /// /// Type: LPCDLGTEMPLATE /// /// The template that DialogBoxIndirectParam uses to create the dialog box. A dialog box template consists of a header that /// describes the dialog box, followed by one or more additional blocks of data that describe each of the controls in the dialog box. /// The template can use either the standard format or the extended format. /// /// /// In a standard template for a dialog box, the header is a DLGTEMPLATE structure followed by additional variable-length arrays. The /// data for each control consists of a DLGITEMTEMPLATE structure followed by additional variable-length arrays. /// /// /// In an extended template for a dialog box, the header uses the DLGTEMPLATEEX format and the control definitions use the /// DLGITEMTEMPLATEEX format. /// /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// Type: LPARAM /// The value to pass to the dialog box in the lParam parameter of the WM_INITDIALOG message. /// /// /// Type: INT_PTR /// /// If the function succeeds, the return value is the nResult parameter specified in the call to the EndDialog function that was used /// to terminate the dialog box. /// /// /// If the function fails because the hWndParent parameter is invalid, the return value is zero. The function returns zero in this /// case for compatibility with previous versions of Windows. If the function fails for any other reason, the return value is –1. To /// get extended error information, call GetLastError. /// /// /// /// /// The DialogBoxIndirectParam function uses the CreateWindowEx function to create the dialog box. /// DialogBoxIndirectParam then sends a WM_INITDIALOG message to the dialog box procedure. If the template specifies the /// DS_SETFONT or DS_SHELLFONT style, the function also sends a WM_SETFONT message to the dialog box procedure. The function displays /// the dialog box (regardless of whether the template specifies the WS_VISIBLE style), disables the owner window, and starts /// its own message loop to retrieve and dispatch messages for the dialog box. /// /// /// When the dialog box procedure calls the EndDialog function, DialogBoxIndirectParam destroys the dialog box, ends the /// message loop, enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box /// procedure when it called EndDialog. /// /// /// In a standard dialog box template, the DLGTEMPLATE structure and each of the DLGITEMTEMPLATE structures must be aligned on /// DWORD boundaries. The creation data array that follows a DLGITEMTEMPLATE structure must also be aligned on a /// DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries. /// /// /// In an extended dialog box template, the DLGTEMPLATEEX header and each of the DLGITEMTEMPLATEEX control definitions must be /// aligned on DWORD boundaries. The creation data array, if any, that follows a DLGITEMTEMPLATEEX structure must also /// be aligned on a DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries. /// /// All character strings in the dialog box template, such as titles for the dialog box and buttons, must be Unicode strings. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-dialogboxindirectparama INT_PTR DialogBoxIndirectParamA( // HINSTANCE hInstance, LPCDLGTEMPLATEA hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "dialogboxindirectparam")] public static extern IntPtr DialogBoxIndirectParam(HINSTANCE hInstance, IntPtr hDialogTemplate, HWND hWndParent, DialogProc lpDialogFunc, [Optional] IntPtr dwInitParam); /// /// /// Creates a modal dialog box from a dialog box template resource. Before displaying the dialog box, the function passes an /// application-defined value to the dialog box procedure as the lParam parameter of the WM_INITDIALOG message. An application can /// use this value to initialize dialog box controls. /// /// /// /// Type: HINSTANCE /// /// A handle to the module which contains the dialog box template. If this parameter is NULL, then the current executable is used. /// /// /// /// Type: LPCTSTR /// /// The dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of /// the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter /// specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can use /// the MAKEINTRESOURCE macro to create this value. /// /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// Type: LPARAM /// The value to pass to the dialog box in the lParam parameter of the WM_INITDIALOG message. /// /// /// Type: INT_PTR /// /// If the function succeeds, the return value is the value of the nResult parameter specified in the call to the EndDialog function /// used to terminate the dialog box. /// /// /// If the function fails because the hWndParent parameter is invalid, the return value is zero. The function returns zero in this /// case for compatibility with previous versions of Windows. If the function fails for any other reason, the return value is –1. To /// get extended error information, call GetLastError. /// /// /// /// /// The DialogBoxParam function uses the CreateWindowEx function to create the dialog box. DialogBoxParam then sends a /// WM_INITDIALOG message (and a WM_SETFONT message if the template specifies the DS_SETFONT or DS_SHELLFONT style) to the dialog box /// procedure. The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), /// disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box. /// /// /// When the dialog box procedure calls the EndDialog function, DialogBoxParam destroys the dialog box, ends the message loop, /// enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box procedure when it /// called EndDialog. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-dialogboxparama INT_PTR DialogBoxParamA( HINSTANCE // hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "dialogboxparam")] public static extern IntPtr DialogBoxParam(HINSTANCE hInstance, string lpTemplateName, HWND hWndParent, DialogProc lpDialogFunc, [Optional] IntPtr dwInitParam); /// /// /// Creates a modal dialog box from a dialog box template resource. Before displaying the dialog box, the function passes an /// application-defined value to the dialog box procedure as the lParam parameter of the WM_INITDIALOG message. An application can /// use this value to initialize dialog box controls. /// /// /// /// Type: HINSTANCE /// /// A handle to the module which contains the dialog box template. If this parameter is NULL, then the current executable is used. /// /// /// /// Type: LPCTSTR /// /// The dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of /// the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter /// specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can use /// the MAKEINTRESOURCE macro to create this value. /// /// /// /// Type: HWND /// A handle to the window that owns the dialog box. /// /// /// Type: DLGPROC /// A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. /// /// /// Type: LPARAM /// The value to pass to the dialog box in the lParam parameter of the WM_INITDIALOG message. /// /// /// Type: INT_PTR /// /// If the function succeeds, the return value is the value of the nResult parameter specified in the call to the EndDialog function /// used to terminate the dialog box. /// /// /// If the function fails because the hWndParent parameter is invalid, the return value is zero. The function returns zero in this /// case for compatibility with previous versions of Windows. If the function fails for any other reason, the return value is –1. To /// get extended error information, call GetLastError. /// /// /// /// /// The DialogBoxParam function uses the CreateWindowEx function to create the dialog box. DialogBoxParam then sends a /// WM_INITDIALOG message (and a WM_SETFONT message if the template specifies the DS_SETFONT or DS_SHELLFONT style) to the dialog box /// procedure. The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), /// disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box. /// /// /// When the dialog box procedure calls the EndDialog function, DialogBoxParam destroys the dialog box, ends the message loop, /// enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box procedure when it /// called EndDialog. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-dialogboxparama INT_PTR DialogBoxParamA( HINSTANCE // hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "dialogboxparam")] public static extern IntPtr DialogBoxParam(HINSTANCE hInstance, ResourceId lpTemplateName, HWND hWndParent, DialogProc lpDialogFunc, [Optional] IntPtr dwInitParam); /// /// Retrieves the current selection from a combo box filled by using the DlgDirListComboBox function. The selection is interpreted as /// a drive letter, a file, or a directory name. /// /// /// Type: HWND /// A handle to the dialog box that contains the combo box. /// /// /// Type: LPTSTR /// A pointer to the buffer that receives the selected path. /// /// /// Type: int /// The length, in characters, of the buffer pointed to by the lpString parameter. /// /// /// Type: int /// The integer identifier of the combo box control in the dialog box. /// /// /// Type: BOOL /// If the current selection is a directory name, the return value is nonzero. /// If the current selection is not a directory name, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// If the current selection specifies a directory name or drive letter, the DlgDirSelectComboBoxEx function removes the /// enclosing square brackets (and hyphens for drive letters) so the name or letter is ready to be inserted into a new path or file /// name. If there is no selection, the contents of the buffer pointed to by lpString do not change. /// /// The DlgDirSelectComboBoxEx function does not allow more than one file name to be returned from a combo box. /// If the string is as long or longer than the buffer, the buffer contains the truncated string with a terminating null character. /// DlgDirSelectComboBoxEx sends CB_GETCURSEL and CB_GETLBTEXT messages to the combo box. /// You can use this function with all three types of combo boxes (CBS_SIMPLE, CBS_DROPDOWN, and CBS_DROPDOWNLIST). /// /// Security Warning: Improper use of this function can cause problems for your application. For instance, the nCount /// parameter should be set properly for both ANSI and Unicode versions. Failure to do so could lead to a buffer overflow. You should /// review Security Considerations: Microsoft Windows Controls before continuing. /// /// /// Windows 95 or later: DlgDirSelectComboBoxExW is supported by the Microsoft Layer for Unicode (MSLU). To use this, /// you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows Me/98/95 Systems. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-dlgdirselectcomboboxexa BOOL DlgDirSelectComboBoxExA( HWND // hwndDlg, LPSTR lpString, int cchOut, int idComboBox ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DlgDirSelectComboBoxEx(HWND hwndDlg, StringBuilder lpString, int cchOut, int idComboBox); /// /// Destroys a modal dialog box, causing the system to end any processing for the dialog box. /// /// /// Type: HWND /// A handle to the dialog box to be destroyed. /// /// /// Type: INT_PTR /// The value to be returned to the application from the function that created the dialog box. /// /// /// 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. /// /// /// /// Dialog boxes created by the DialogBox, DialogBoxParam, DialogBoxIndirect, and DialogBoxIndirectParam functions must be destroyed /// using the EndDialog function. An application calls EndDialog from within the dialog box procedure; the function /// must not be used for any other purpose. /// /// /// A dialog box procedure can call EndDialog at any time, even during the processing of the WM_INITDIALOG message. If your /// application calls the function while WM_INITDIALOG is being processed, the dialog box is destroyed before it is shown and /// before the input focus is set. /// /// /// EndDialog does not destroy the dialog box immediately. Instead, it sets a flag and allows the dialog box procedure to /// return control to the system. The system checks the flag before attempting to retrieve the next message from the application /// queue. If the flag is set, the system ends the message loop, destroys the dialog box, and uses the value in nResult as the return /// value from the function that created the dialog box. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enddialog BOOL EndDialog( HWND hDlg, INT_PTR nResult ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "enddialog")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EndDialog(HWND hDlg, IntPtr nResult); /// /// /// Retrieves the system's dialog base units, which are the average width and height of characters in the system font. For dialog /// boxes that use the system font, you can use these values to convert between dialog template units, as specified in dialog box /// templates, and pixels. For dialog boxes that do not use the system font, the conversion from dialog template units to pixels /// depends on the font used by the dialog box. /// /// /// For either type of dialog box, it is easier to use the MapDialogRect function to perform the conversion. MapDialogRect /// takes the font into account and correctly converts a rectangle from dialog template units into pixels. /// /// /// /// Type: LONG /// /// The function returns the dialog base units. The low-order word of the return value contains the horizontal dialog box base unit, /// and the high-order word contains the vertical dialog box base unit. /// /// /// /// /// The horizontal base unit returned by GetDialogBaseUnits is equal to the average width, in pixels, of the characters in the /// system font; the vertical base unit is equal to the height, in pixels, of the font. /// /// /// The system font is used only if the dialog box template fails to specify a font. Most dialog box templates specify a font; as a /// result, this function is not useful for most dialog boxes. /// /// /// For a dialog box that does not use the system font, the base units are the average width and height, in pixels, of the characters /// in the dialog's font. You can use the GetTextMetrics and GetTextExtentPoint32 functions to calculate these values for a selected /// font. However, by using the MapDialogRect function, you can avoid errors that might result if your calculations differ from those /// performed by the system. /// /// /// Each horizontal base unit is equal to 4 horizontal dialog template units; each vertical base unit is equal to 8 vertical dialog /// template units. Therefore, to convert dialog template units to pixels, use the following formulas: /// /// Similarly, to convert from pixels to dialog template units, use the following formulas: /// Examples /// For an example, see "Creating a Combo Box Toolbar" in Using Combo Boxes. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdialogbaseunits long GetDialogBaseUnits( ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "getdialogbaseunits")] public static extern long GetDialogBaseUnits(); /// /// Retrieves the identifier of the specified control. /// /// /// Type: HWND /// A handle to the control. /// /// /// Type: int /// If the function succeeds, the return value is the identifier of the control. /// /// If the function fails, the return value is zero. An invalid value for the hwndCtl parameter, for example, will cause the function /// to fail. To get extended error information, call GetLastError. /// /// /// /// /// GetDlgCtrlID accepts child window handles as well as handles of controls in dialog boxes. An application sets the /// identifier for a child window when it creates the window by assigning the identifier value to the hmenu parameter when calling /// the CreateWindow or CreateWindowEx function. /// /// /// Although GetDlgCtrlID may return a value if hwndCtl is a handle to a top-level window, top-level windows cannot have /// identifiers and such a return value is never valid. /// /// Examples /// For an example, see Initializing a Dialog Box. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdlgctrlid int GetDlgCtrlID( HWND hWnd ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "getdlgctrlid")] public static extern int GetDlgCtrlID(HWND hWnd); /// /// Retrieves a handle to a control in the specified dialog box. /// /// /// Type: HWND /// A handle to the dialog box that contains the control. /// /// /// Type: int /// The identifier of the control to be retrieved. /// /// /// Type: HWND /// If the function succeeds, the return value is the window handle of the specified control. /// /// If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get /// extended error information, call GetLastError. /// /// /// /// /// You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the hDlg /// parameter specifies a parent window and the child window has a unique identifier (as specified by the hMenu parameter in the /// CreateWindow or CreateWindowEx function that created the child window), GetDlgItem returns a valid handle to the child window. /// /// Examples /// For an example, see Initializing a Dialog Box. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdlgitem HWND GetDlgItem( HWND hDlg, int nIDDlgItem ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "getdlgitem")] public static extern HWND GetDlgItem(HWND hDlg, int nIDDlgItem); /// /// Translates the text of a specified control in a dialog box into an integer value. /// /// /// Type: HWND /// A handle to the dialog box that contains the control of interest. /// /// /// Type: int /// The identifier of the control whose text is to be translated. /// /// /// Type: BOOL* /// Indicates success or failure ( TRUE indicates success, FALSE indicates failure). /// If this parameter is NULL, the function returns no information about success or failure. /// /// /// Type: BOOL /// /// Indicates whether the function should examine the text for a minus sign at the beginning and return a signed integer value if it /// finds one ( TRUE specifies this should be done, FALSE that it should not). /// /// /// /// Type: UINT /// /// If the function succeeds, the variable pointed to by lpTranslated is set to TRUE, and the return value is the translated /// value of the control text. /// /// /// If the function fails, the variable pointed to by lpTranslated is set to FALSE, and the return value is zero. Note that, /// because zero is a possible translated value, a return value of zero does not by itself indicate failure. /// /// If lpTranslated is NULL, the function returns no information about success or failure. /// /// Note that, if the bSigned parameter is TRUE and there is a minus sign (–) at the beginning of the text, /// GetDlgItemInt translates the text into a signed integer value. Otherwise, the function creates an unsigned integer value. /// To obtain the proper value in this case, cast the return value to an int type. /// /// To get extended error information, call GetLastError. /// /// /// /// The GetDlgItemInt function retrieves the text of the specified control by sending the control a WM_GETTEXT message. The /// function translates the retrieved text by stripping any extra spaces at the beginning of the text and then converting the decimal /// digits. The function stops translating when it reaches the end of the text or encounters a nonnumeric character. /// /// /// The GetDlgItemInt function returns zero if the translated value is greater than INT_MAX (for signed numbers) or /// UINT_MAX (for unsigned numbers). /// /// Examples /// For an example, see Creating a Modeless Dialog Box. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdlgitemint UINT GetDlgItemInt( HWND hDlg, int // nIDDlgItem, BOOL *lpTranslated, BOOL bSigned ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "getdlgitemint")] public static extern uint GetDlgItemInt(HWND hDlg, int nIDDlgItem, [MarshalAs(UnmanagedType.Bool)] out bool lpTranslated, [MarshalAs(UnmanagedType.Bool)] bool bSigned); /// /// Retrieves the title or text associated with a control in a dialog box. /// /// /// Type: HWND /// A handle to the dialog box that contains the control. /// /// /// Type: int /// The identifier of the control whose title or text is to be retrieved. /// /// /// Type: LPTSTR /// The buffer to receive the title or text. /// /// /// Type: int /// /// The maximum length, in characters, of the string to be copied to the buffer pointed to by lpString. If the length of the string, /// including the null character, exceeds the limit, the string is truncated. /// /// /// /// Type: UINT /// /// If the function succeeds, the return value specifies the number of characters copied to the buffer, not including the terminating /// null character. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// If the string is as long or longer than the buffer, the buffer will contain the truncated string with a terminating null character. /// /// The GetDlgItemText function sends a WM_GETTEXT message to the control. /// Examples /// For an example, see Creating a Modal Dialog Box. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdlgitemtexta UINT GetDlgItemTextA( HWND hDlg, int // nIDDlgItem, LPSTR lpString, int cchMax ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "getdlgitemtext")] public static extern uint GetDlgItemText(HWND hDlg, int nIDDlgItem, StringBuilder lpString, int cchMax); /// /// /// Retrieves a handle to the first control in a group of controls that precedes (or follows) the specified control in a dialog box. /// /// /// /// Type: HWND /// A handle to the dialog box to be searched. /// /// /// Type: HWND /// /// A handle to the control to be used as the starting point for the search. If this parameter is NULL, the function uses the /// last (or first) control in the dialog box as the starting point for the search. /// /// /// /// Type: BOOL /// /// Indicates how the function is to search the group of controls in the dialog box. If this parameter is TRUE, the function /// searches for the previous control in the group. If it is FALSE, the function searches for the next control in the group. /// /// /// /// Type: HWND /// If the function succeeds, the return value is a handle to the previous (or next) control in the group of controls. /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. /// /// /// /// The GetNextDlgGroupItem function searches controls in the order (or reverse order) they were created in the dialog box /// template. The first control in the group must have the WS_GROUP style; all other controls in the group must have been /// consecutively created and must not have the WS_GROUP style. /// /// /// When searching for the previous control, the function returns the first control it locates that is visible and not disabled. If /// the control specified by hCtl has the WS_GROUP style, the function temporarily reverses the search to locate the first /// control having the WS_GROUP style, then resumes the search in the original direction, returning the first control it /// locates that is visible and not disabled, or returning hCtl if no such control is found. /// /// /// When searching for the next control, the function returns the first control it locates that is visible, not disabled, and does /// not have the WS_GROUP style. If it encounters a control having the WS_GROUP style, the function reverses the /// search, locates the first control having the WS_GROUP style, and returns this control if it is visible and not disabled. /// Otherwise, the function resumes the search in the original direction and returns the first control it locates that is visible and /// not disabled, or returns hCtl if no such control is found. /// /// /// If the search for the next control in the group encounters a window with the WS_EX_CONTROLPARENT style, the system /// recursively searches the window's children. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getnextdlggroupitem HWND GetNextDlgGroupItem( HWND hDlg, // HWND hCtl, BOOL bPrevious ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "getnextdlggroupitem")] public static extern HWND GetNextDlgGroupItem(HWND hDlg, HWND hCtl, [MarshalAs(UnmanagedType.Bool)] bool bPrevious); /// /// Retrieves a handle to the first control that has the WS_TABSTOP style that precedes (or follows) the specified control. /// /// /// Type: HWND /// A handle to the dialog box to be searched. /// /// /// Type: HWND /// /// A handle to the control to be used as the starting point for the search. If this parameter is NULL, the function fails. /// /// /// /// Type: BOOL /// /// Indicates how the function is to search the dialog box. If this parameter is TRUE, the function searches for the previous /// control in the dialog box. If this parameter is FALSE, the function searches for the next control in the dialog box. /// /// /// /// Type: HWND /// /// If the function succeeds, the return value is the window handle of the previous (or next) control that has the WS_TABSTOP style set. /// /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. /// /// /// /// The GetNextDlgTabItem function searches controls in the order (or reverse order) they were created in the dialog box /// template. The function returns the first control it locates that is visible, not disabled, and has the WS_TABSTOP style. If no /// such control exists, the function returns hCtl. /// /// /// If the search for the next control with the WS_TABSTOP style encounters a window with the WS_EX_CONTROLPARENT /// style, the system recursively searches the window's children. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getnextdlgtabitem HWND GetNextDlgTabItem( HWND hDlg, HWND // hCtl, BOOL bPrevious ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "getnextdlgtabitem")] public static extern HWND GetNextDlgTabItem(HWND hDlg, HWND hCtl, [MarshalAs(UnmanagedType.Bool)] bool bPrevious); /// /// Determines whether a message is intended for the specified dialog box and, if it is, processes the message. /// /// /// Type: HWND /// A handle to the dialog box. /// /// /// Type: LPMSG /// A pointer to an MSG structure that contains the message to be checked. /// /// /// Type: BOOL /// If the message has been processed, the return value is nonzero. /// If the message has not been processed, the return value is zero. /// /// /// /// Although the IsDialogMessage function is intended for modeless dialog boxes, you can use it with any window that contains /// controls, enabling the windows to provide the same keyboard selection as is used in a dialog box. /// /// /// When IsDialogMessage processes a message, it checks for keyboard messages and converts them into selections for the /// corresponding dialog box. For example, the TAB key, when pressed, selects the next control or group of controls, and the DOWN /// ARROW key, when pressed, selects the next control in a group. /// /// /// Because the IsDialogMessage function performs all necessary translating and dispatching of messages, a message processed /// by IsDialogMessage must not be passed to the TranslateMessage or DispatchMessage function. /// /// IsDialogMessage sends WM_GETDLGCODE messages to the dialog box procedure to determine which keys should be processed. /// /// IsDialogMessage can send DM_GETDEFID and DM_SETDEFID messages to the window. These messages are defined in the Winuser.h /// header file as WM_USER and WM_USER + 1, so conflicts are possible with application-defined messages having the same values. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-isdialogmessagea BOOL IsDialogMessageA( HWND hDlg, LPMSG // lpMsg ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "isdialogmessage")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsDialogMessage(HWND hDlg, in MSG lpMsg); /// /// /// Converts the specified dialog box units to screen units (pixels). The function replaces the coordinates in the specified RECT /// structure with the converted coordinates, which allows the structure to be used to create a dialog box or position a control /// within a dialog box. /// /// /// /// Type: HWND /// /// A handle to a dialog box. This function accepts only handles returned by one of the dialog box creation functions; handles for /// other windows are not valid. /// /// /// /// Type: LPRECT /// A pointer to a RECT structure that contains the dialog box coordinates to be converted. /// /// /// 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 MapDialogRect function assumes that the initial coordinates in the RECT structure represent dialog box units. To /// convert these coordinates from dialog box units to pixels, the function retrieves the current horizontal and vertical base units /// for the dialog box, then applies the following formulas: /// /// /// If the dialog box template has the DS_SETFONT or DS_SHELLFONT style, the base units are the average width and height, in /// pixels, of the characters in the font specified by the template. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-mapdialogrect BOOL MapDialogRect( HWND hDlg, LPRECT lpRect ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "mapdialogrect")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool MapDialogRect(HWND hDlg, in RECT lpRect); /// /// Sends a message to the specified control in a dialog box. /// /// /// Type: HWND /// A handle to the dialog box that contains the control. /// /// /// Type: int /// The identifier of the control that receives the message. /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing and depends on the message sent. /// /// /// The SendDlgItemMessage function does not return until the message has been processed. /// /// Using SendDlgItemMessage is identical to retrieving a handle to the specified control and calling the SendMessage function. /// /// Examples /// For an example, see Creating a Modeless Dialog Box. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-senddlgitemmessagea LRESULT SendDlgItemMessageA( HWND // hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "senddlgitemmessage")] public static extern IntPtr SendDlgItemMessage(HWND hDlg, int nIDDlgItem, uint Msg, IntPtr wParam, IntPtr lParam); /// /// Sets the text of a control in a dialog box to the string representation of a specified integer value. /// /// /// Type: HWND /// A handle to the dialog box that contains the control. /// /// /// Type: int /// The control to be changed. /// /// /// Type: UINT /// The integer value used to generate the item text. /// /// /// Type: BOOL /// /// Indicates whether the uValue parameter is signed or unsigned. If this parameter is TRUE, uValue is signed. If this /// parameter is TRUE and uValue is less than zero, a minus sign is placed before the first digit in the string. If this /// parameter is FALSE, uValue is unsigned. /// /// /// /// 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. /// /// /// To set the new text, this function sends a WM_SETTEXT message to the specified control. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setdlgitemint BOOL SetDlgItemInt( HWND hDlg, int // nIDDlgItem, UINT uValue, BOOL bSigned ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "setdlgitemint")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetDlgItemInt(HWND hDlg, int nIDDlgItem, uint uValue, [MarshalAs(UnmanagedType.Bool)] bool bSigned); /// /// Sets the title or text of a control in a dialog box. /// /// /// Type: HWND /// A handle to the dialog box that contains the control. /// /// /// Type: int /// The control with a title or text to be set. /// /// /// Type: LPCTSTR /// The text to be copied to the control. /// /// /// 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 SetDlgItemText function sends a WM_SETTEXT message to the specified control. /// Examples /// For an example, see Using List Boxes. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setdlgitemtexta BOOL SetDlgItemTextA( HWND hDlg, int // nIDDlgItem, LPCSTR lpString ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "setdlgitemtext")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetDlgItemText(HWND hDlg, int nIDDlgItem, string lpString); /// /// /// Defines the dimensions and style of a control in a dialog box. One or more of these structures are combined with a DLGTEMPLATE /// structure to form a standard template for a dialog box. /// /// /// /// /// In a standard template for a dialog box, the DLGITEMTEMPLATE structure is always immediately followed by three /// variable-length arrays specifying the class, title, and creation data for the control. Each array consists of one or more 16-bit elements. /// /// /// Each DLGITEMTEMPLATE structure in the template must be aligned on a DWORD boundary. The class and title arrays must /// be aligned on WORD boundaries. The creation data array must be aligned on a WORD boundary. /// /// /// Immediately following each DLGITEMTEMPLATE structure is a class array that specifies the window class of the control. If /// the first element of this array is any value other than 0xFFFF, the system treats the array as a null-terminated Unicode string /// that specifies the name of a registered window class. If the first element is 0xFFFF, the array has one additional element that /// specifies the ordinal value of a predefined system class. The ordinal can be one of the following atom values. /// /// /// /// Value /// Meaning /// /// /// 0x0080 /// Button /// /// /// 0x0081 /// Edit /// /// /// 0x0082 /// Static /// /// /// 0x0083 /// List box /// /// /// 0x0084 /// Scroll bar /// /// /// 0x0085 /// Combo box /// /// /// /// Following the class array is a title array that contains the initial text or resource identifier of the control. If the first /// element of this array is 0xFFFF, the array has one additional element that specifies an ordinal value of a resource, such as an /// icon, in an executable file. You can use a resource identifier for controls, such as static icon controls, that load and display /// an icon or other resource rather than text. If the first element is any value other than 0xFFFF, the system treats the array as a /// null-terminated Unicode string that specifies the initial text. /// /// /// The creation data array begins at the next WORD boundary after the title array. This creation data can be of any size and /// format. If the first word of the creation data array is nonzero, it indicates the size, in bytes, of the creation data (including /// the size word). The control's window procedure must be able to interpret the data. When the system creates the control, it passes /// a pointer to this data in the lParam parameter of the WM_CREATE message that it sends to the control. /// /// /// If you specify character strings in the class and title arrays, you must use Unicode strings. Use the MultiByteToWideChar /// function to generate Unicode strings from ANSI strings. /// /// /// The x, y, cx, and cy members specify values in dialog box units. You can convert these values to /// screen units (pixels) by using the MapDialogRect function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-dlgitemtemplate typedef struct DLGITEMTEMPLATE { DWORD // style; DWORD dwExtendedStyle; short x; short y; short cx; short cy; WORD id; }; [PInvokeData("winuser.h", MSDNShortId = "dlgitemtemplate")] [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct DLGITEMTEMPLATE { /// /// Type: DWORD /// /// The style of the control. This member can be a combination of window style values (such as WS_BORDER) and one or more /// of the control style values (such as BS_PUSHBUTTON and ES_LEFT). /// /// public uint style; /// /// Type: DWORD /// /// The extended styles for a window. This member is not used to create controls in dialog boxes, but applications that use /// dialog box templates can use it to create other types of windows. For a list of values, see Extended Window Styles. /// /// public uint dwExtendedStyle; /// /// Type: short /// /// The x-coordinate, in dialog box units, of the upper-left corner of the control. This coordinate is always relative to the /// upper-left corner of the dialog box's client area. /// /// public short x; /// /// Type: short /// /// The y-coordinate, in dialog box units, of the upper-left corner of the control. This coordinate is always relative to the /// upper-left corner of the dialog box's client area. /// /// public short y; /// /// Type: short /// The width, in dialog box units, of the control. /// public short cx; /// /// Type: short /// The height, in dialog box units, of the control. /// public short cy; /// /// Type: WORD /// The control identifier. /// public ushort id; } /// /// /// Defines the dimensions and style of a dialog box. This structure, always the first in a standard template for a dialog box, also /// specifies the number of controls in the dialog box and therefore specifies the number of subsequent DLGITEMTEMPLATE structures in /// the template. /// /// /// /// /// In a standard template for a dialog box, the DLGTEMPLATE structure is always immediately followed by three variable-length /// arrays that specify the menu, class, and title for the dialog box. When the DS_SETFONT style is specified, these arrays are also /// followed by a 16-bit value specifying point size and another variable-length array specifying a typeface name. Each array /// consists of one or more 16-bit elements. The menu, class, title, and font arrays must be aligned on WORD boundaries. /// /// /// Immediately following the DLGTEMPLATE structure is a menu array that identifies a menu resource for the dialog box. If the /// first element of this array is 0x0000, the dialog box has no menu and the array has no other elements. If the first element is /// 0xFFFF, the array has one additional element that specifies the ordinal value of a menu resource in an executable file. If the /// first element has any other value, the system treats the array as a null-terminated Unicode string that specifies the name of a /// menu resource in an executable file. /// /// /// Following the menu array is a class array that identifies the window class of the control. If the first element of the array is /// 0x0000, the system uses the predefined dialog box class for the dialog box and the array has no other elements. If the first /// element is 0xFFFF, the array has one additional element that specifies the ordinal value of a predefined system window class. If /// the first element has any other value, the system treats the array as a null-terminated Unicode string that specifies the name of /// a registered window class. /// /// /// Following the class array is a title array that specifies a null-terminated Unicode string that contains the title of the dialog /// box. If the first element of this array is 0x0000, the dialog box has no title and the array has no other elements. /// /// /// The 16-bit point size value and the typeface array follow the title array, but only if the style member specifies the /// DS_SETFONT style. The point size value specifies the point size of the font to use for the text in the dialog box and its /// controls. The typeface array is a null-terminated Unicode string specifying the name of the typeface for the font. When these /// values are specified, the system creates a font having the specified size and typeface (if possible) and sends a WM_SETFONT /// message to the dialog box procedure and the control window procedures as it creates the dialog box and controls. /// /// /// Following the DLGTEMPLATE header in a standard dialog box template are one or more DLGITEMTEMPLATE structures that define /// the dimensions and style of the controls in the dialog box. The cdit member specifies the number of DLGITEMTEMPLATE /// structures in the template. These DLGITEMTEMPLATE structures must be aligned on DWORD boundaries. /// /// If you specify character strings in the menu, class, title, or typeface arrays, you must use Unicode strings. /// /// The x, y, cx, and cy members specify values in dialog box units. You can convert these values to /// screen units (pixels) by using the MapDialogRect function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-dlgtemplate typedef struct DLGTEMPLATE { DWORD style; // DWORD dwExtendedStyle; WORD cdit; short x; short y; short cx; short cy; }; [PInvokeData("winuser.h", MSDNShortId = "dlgtemplate")] [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct DLGTEMPLATE { /// /// Type: DWORD /// /// The style of the dialog box. This member can be a combination of window style values (such as WS_CAPTION and /// WS_SYSMENU) and dialog box style values (such as DS_CENTER). /// /// /// If the style member includes the DS_SETFONT style, the header of the dialog box template contains additional data /// specifying the font to use for text in the client area and controls of the dialog box. The font data begins on the /// WORD boundary that follows the title array. The font data specifies a 16-bit point size value and a Unicode font name /// string. If possible, the system creates a font according to the specified values. Then the system sends a WM_SETFONT message /// to the dialog box and to each control to provide a handle to the font. If DS_SETFONT is not specified, the dialog box /// template does not include the font data. /// /// The DS_SHELLFONT style is not supported in the DLGTEMPLATE header. /// public uint style; /// /// Type: DWORD /// /// The extended styles for a window. This member is not used to create dialog boxes, but applications that use dialog box /// templates can use it to create other types of windows. For a list of values, see Extended Window Styles. /// /// public uint dwExtendedStyle; /// /// Type: WORD /// The number of items in the dialog box. /// public ushort cdit; /// /// Type: short /// The x-coordinate, in dialog box units, of the upper-left corner of the dialog box. /// public short x; /// /// Type: short /// The y-coordinate, in dialog box units, of the upper-left corner of the dialog box. /// public short y; /// /// Type: short /// The width, in dialog box units, of the dialog box. /// public short cx; /// /// Type: short /// The height, in dialog box units, of the dialog box. /// public short cy; } /* /// /// /// An extended dialog box template begins with a DLGTEMPLATEEX header that describes the dialog box and specifies the number /// of controls in the dialog box. For each control in a dialog box, an extended dialog box template has a block of data that uses /// the DLGITEMTEMPLATEEX format to describe the control. /// /// /// The DLGTEMPLATEEX structure is not defined in any standard header file. The structure definition is provided here to /// explain the format of an extended template for a dialog box. /// /// /// /// /// You can use an extended dialog box template instead of a standard dialog box template in the CreateDialogIndirectParam, /// DialogBoxIndirectParam, CreateDialogIndirect, and DialogBoxIndirect functions. /// /// /// Following the DLGTEMPLATEEX header in an extended dialog box template is one or more DLGITEMTEMPLATEEX structures /// that describe the controls of the dialog box. The cDlgItems member of the DLGITEMTEMPLATEEX structure specifies the /// number of DLGITEMTEMPLATEEX structures that follow in the template. /// /// /// Each DLGITEMTEMPLATEEX structure in the template must be aligned on a DWORD boundary. If the style member /// specifies the DS_SETFONT or DS_SHELLFONT style, the first DLGITEMTEMPLATEEX structure begins on the first /// DWORD boundary after the typeface string. If these styles are not specified, the first structure begins on the /// first DWORD boundary after the title string. /// /// The menu, windowClass, title, and typeface arrays must be aligned on WORD boundaries. /// /// If you specify character strings in the menu, windowClass, title, and typeface arrays, you must use /// Unicode strings. Use the MultiByteToWideChar function to generate these Unicode strings from ANSI strings. /// /// /// The x, y, cx, and cy members specify values in dialog box units. You can convert these values to /// screen units (pixels) by using the MapDialogRect function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/dlgbox/dlgtemplateex typedef struct { WORD dlgVer; WORD signature; DWORD helpID; // DWORD exStyle; DWORD style; WORD cDlgItems; short x; short y; short cx; short cy; sz_Or_Ord menu; sz_Or_Ord windowClass; WCHAR // title[titleLen]; WORD pointsize; WORD weight; BYTE italic; BYTE charset; WCHAR typeface[stringLen]; } DLGTEMPLATEEX; [PInvokeData("", MSDNShortId = "9f016cc6-56e2-45d3-8773-1b405fc10d29")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct DLGTEMPLATEEX { /// The version number of the extended dialog box template. This member must be set to 1. public ushort dlgVer; /// /// Indicates whether a template is an extended dialog box template. If signature is 0xFFFF, this is an extended dialog box /// template. In this case, the dlgVer member specifies the template version number. If signature is any value other than 0xFFFF, /// this is a standard dialog box template that uses the DLGTEMPLATE and DLGITEMTEMPLATE structures. /// public ushort signature; /// /// The help context identifier for the dialog box window. When the system sends a WM_HELP message, it passes this value in the /// wContextId member of the HELPINFO structure. /// public uint helpID; /// /// The extended windows styles. This member is not used when creating dialog boxes, but applications that use dialog box /// templates can use it to create other types of windows. For a list of values, see Extended Window Styles. /// public WindowStylesEx exStyle; /// /// The style of the dialog box. This member can be a combination of window style values and dialog box style values. /// /// If style includes the DS_SETFONT or DS_SHELLFONT dialog box style, the DLGTEMPLATEEX header of the extended dialog box /// template contains four additional members(pointsize, weight, italic, and typeface) that describe the font to use for the text /// in the client area and controls of the dialog box.If possible, the system creates a font according to the values specified in /// these members.Then the system sends a WM_SETFONT message to the dialog box and to each control to provide a handle to the font. /// /// For more information, see Dialog Box Fonts. /// public WindowStyles style; /// The number of controls in the dialog box. public ushort cDlgItems; /// The x-coordinate, in dialog box units, of the upper-left corner of the dialog box. public short x; /// The y-coordinate, in dialog box units, of the upper-left corner of the dialog box. public short y; /// The width, in dialog box units, of the dialog box. public short cx; /// The height, in dialog box units, of the dialog box. public short cy; /// /// A variable-length array of 16-bit elements that identifies a menu resource for the dialog box. If the first element of this /// array is 0x0000, the dialog box has no menu and the array has no other elements. If the first element is 0xFFFF, the array /// has one additional element that specifies the ordinal value of a menu resource in an executable file. If the first element /// has any other value, the system treats the array as a null-terminated Unicode string that specifies the name of a menu /// resource in an executable file. /// public IntPtr menu; /// /// A variable-length array of 16-bit elements that identifies the window class of the dialog box. If the first element of the /// array is 0x0000, the system uses the predefined dialog box class for the dialog box and the array has no other elements. If /// the first element is 0xFFFF, the array has one additional element that specifies the ordinal value of a predefined system /// window class. If the first element has any other value, the system treats the array as a null-terminated Unicode string that /// specifies the name of a registered window class. /// public IntPtr windowClass; /// /// The title of the dialog box. If the first element of this array is 0x0000, the dialog box has no title and the array has no /// other elements. /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = titleLen)] public string title; /// /// The point size of the font to use for the text in the dialog box and its controls. /// This member is present only if the style member specifies DS_SETFONT or DS_SHELLFONT. /// public ushort pointsize; /// /// The weight of the font. Note that, although this can be any of the values listed for the lfWeight member of the LOGFONT /// structure, any value that is used will be automatically changed to FW_NORMAL. /// This member is present only if the style member specifies DS_SETFONT or DS_SHELLFONT. /// public ushort weight; /// /// Indicates whether the font is italic. If this value is TRUE, the font is italic. /// This member is present only if the style member specifies DS_SETFONT or DS_SHELLFONT. /// public byte italic; /// /// The character set to be used. For more information, see the lfcharset member of LOGFONT. /// This member is present only if the style member specifies DS_SETFONT or DS_SHELLFONT. /// public byte charset; /// /// The name of the typeface for the font. /// This member is present only if the style member specifies DS_SETFONT or DS_SHELLFONT. /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = stringLen)] public string typeface; } */ } }