Added CreateWindow "macro". BREAKING CHANGE: Corrected GetClientRect to have 'out rect' param rather than by ref.

pull/161/head
dahall 2020-07-29 17:32:29 -06:00
parent f9f07c8ba6
commit 95d7300c3e
1 changed files with 120 additions and 6 deletions

View File

@ -2020,6 +2020,118 @@ namespace Vanara.PInvoke
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseWindow(HWND hWnd);
/// <summary>
/// <para>Creates an overlapped, pop-up, or child window. It specifies the window class, window title, window style, and (optionally) the initial position and size of the window. The function also specifies the window's parent or owner, if any, and the window's menu.</para>
/// <para>To use extended window styles in addition to the styles supported by <c>CreateWindow</c>, use the CreateWindowEx function.</para>
/// </summary>
/// <param name="lpClassName">
/// <para>Type: <c>LPCTSTR</c></para>
/// <para>A <c>null</c>-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. If lpClassName is a string, it specifies the window class name. The class name can be any name registered with <c>RegisterClass</c> or <c>RegisterClassEx</c>, provided that the module that registers the class is also the module that creates the window. The class name can also be any of the predefined system class names. For a list of system class names, see the Remarks section.</para>
/// </param>
/// <param name="lpWindowName">
/// <para>Type: <c>LPCTSTR</c></para>
/// <para>The window name. If the window style specifies a title bar, the window title pointed to by lpWindowName is displayed in the title bar. When using <c>CreateWindow</c> to create controls, such as buttons, check boxes, and static controls, use lpWindowName to specify the text of the control. When creating a static control with the <c>SS_ICON</c> style, use lpWindowName to specify the icon name or identifier. To specify an identifier, use the syntax "#num".</para>
/// </param>
/// <param name="dwStyle">
/// <para>Type: <c>DWORD</c></para>
/// <para>The style of the window being created. This parameter can be a combination of the window style values, plus the control styles indicated in the Remarks section.</para>
/// </param>
/// <param name="x">
/// <para>Type: <c>int</c></para>
/// <para>The initial horizontal position of the window. For an overlapped or pop-up window, the x parameter is the initial x-coordinate of the window's upper-left corner, in screen coordinates. For a child window, x is the x-coordinate of the upper-left corner of the window relative to the upper-left corner of the parent window's client area. If this parameter is set to <c>CW_USEDEFAULT</c>, the system selects the default position for the window's upper-left corner and ignores the y parameter. <c>CW_USEDEFAULT</c> is valid only for overlapped windows; if it is specified for a pop-up or child window, the x and y parameters are set to zero.</para>
/// </param>
/// <param name="y">
/// <para>Type: <c>int</c></para>
/// <para>The initial vertical position of the window. For an overlapped or pop-up window, the y parameter is the initial y-coordinate of the window's upper-left corner, in screen coordinates. For a child window, y is the initial y-coordinate of the upper-left corner of the child window relative to the upper-left corner of the parent window's client area. For a list box, y is the initial y-coordinate of the upper-left corner of the list box's client area relative to the upper-left corner of the parent window's client area.</para>
/// <para>If an overlapped window is created with the <c>WS_VISIBLE</c> style bit set and the x parameter is set to <c>CW_USEDEFAULT</c>, then the y parameter determines how the window is shown. If the y parameter is <c>CW_USEDEFAULT</c>, then the window manager calls ShowWindow with the <c>SW_SHOW</c> flag after the window has been created. If the y parameter is some other value, then the window manager calls <c>ShowWindow</c> with that value as the nCmdShow parameter.</para>
/// </param>
/// <param name="nWidth">
/// <para>Type: <c>int</c></para>
/// <para>The width, in device units, of the window. For overlapped windows, nWidth is either the window's width, in screen coordinates, or <c>CW_USEDEFAULT</c>. If nWidth is <c>CW_USEDEFAULT</c>, the system selects a default width and height for the window; the default width extends from the initial x-coordinate to the right edge of the screen, and the default height extends from the initial y-coordinate to the top of the icon area. <c>CW_USEDEFAULT</c> is valid only for overlapped windows; if <c>CW_USEDEFAULT</c> is specified for a pop-up or child window, nWidth and nHeight are set to zero.</para>
/// </param>
/// <param name="nHeight">
/// <para>Type: <c>int</c></para>
/// <para>The height, in device units, of the window. For overlapped windows, nHeight is the window's height, in screen coordinates. If nWidth is set to <c>CW_USEDEFAULT</c>, the system ignores nHeight.</para>
/// </param>
/// <param name="hWndParent">
/// <para>Type: <c>HWND</c></para>
/// <para>A handle to the parent or owner window of the window being created. To create a child window or an owned window, supply a valid window handle. This parameter is optional for pop-up windows.</para>
/// <para>To create a message-only window, supply <c>HWND_MESSAGE</c> or a handle to an existing message-only window.</para>
/// </param>
/// <param name="hMenu">
/// <para>Type: <c>HMENU</c></para>
/// <para>A handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be <c>NULL</c> if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.</para>
/// </param>
/// <param name="hInstance">
/// <para>Type: <c>HINSTANCE</c></para>
/// <para>A handle to the instance of the module to be associated with the window.</para>
/// </param>
/// <param name="lpParam">
/// <para>Type: <c>LPVOID</c></para>
/// <para>A pointer to a value to be passed to the window through the CREATESTRUCT structure (<c>lpCreateParams</c> member) pointed to by the lParam param of the WM_CREATE message. This message is sent to the created window by this function before it returns.</para>
/// <para>If an application calls <c>CreateWindow</c> to create a MDI client window, lpParam should point to a CLIENTCREATESTRUCT structure. If an MDI client window calls <c>CreateWindow</c> to create an MDI child window, lpParam should point to a MDICREATESTRUCT structure. lpParam may be <c>NULL</c> if no additional data is needed.</para>
/// </param>
/// <returns>None</returns>
/// <remarks>
/// <para>Before returning, <c>CreateWindow</c> sends a WM_CREATE message to the window procedure. For overlapped, pop-up, and child windows, <c>CreateWindow</c> sends <c>WM_CREATE</c>, WM_GETMINMAXINFO, and WM_NCCREATE messages to the window. The lParam parameter of the <c>WM_CREATE</c> message contains a pointer to a CREATESTRUCT structure. If the <c>WS_VISIBLE</c> style is specified, <c>CreateWindow</c> sends the window all the messages required to activate and show the window.</para>
/// <para>If the created window is a child window, its default position is at the bottom of the Z-order. If the created window is a top-level window, its default position is at the top of the Z-order (but beneath all topmost windows unless the created window is itself topmost).</para>
/// <para>For information on controlling whether the Taskbar displays a button for the created window, see Managing Taskbar Buttons.</para>
/// <para>For information on removing a window, see the DestroyWindow function.</para>
/// <para>The following predefined system classes can be specified in the lpClassName parameter. Note the corresponding control styles you can use in the dwStyle parameter.</para>
/// <list type="table">
/// <listheader>
/// <term>System class</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>BUTTON</term>
/// <term>Designates a small rectangular child window that represents a button the user can click to turn it on or off. Button controls can be used alone or in groups, and they can either be labeled or appear without text. Button controls typically change appearance when the user clicks them. For more information, see Buttons For a table of the button styles you can specify in the dwStyle parameter, see Button Styles.</term>
/// </item>
/// <item>
/// <term>COMBOBOX</term>
/// <term>Designates a control consisting of a list box and a selection field similar to an edit control. When using this style, an application should either display the list box at all times or enable a drop-down list box. If the list box is visible, typing characters into the selection field highlights the first list box entry that matches the characters typed. Conversely, selecting an item in the list box displays the selected text in the selection field. For more information, see Combo Boxes. For a table of the combo box styles you can specify in the dwStyle parameter, see Combo Box Styles.</term>
/// </item>
/// <item>
/// <term>EDIT</term>
/// <term>Designates a rectangular child window into which the user can type text from the keyboard. The user selects the control and gives it the keyboard focus by clicking it or moving to it by pressing the TAB key. The user can type text when the edit control displays a flashing caret; use the mouse to move the cursor, select characters to be replaced, or position the cursor for inserting characters; or use the BACKSPACE key to delete characters. For more information, see Edit Controls. For a table of the edit control styles you can specify in the dwStyle parameter, see Edit Control Styles.</term>
/// </item>
/// <item>
/// <term>LISTBOX</term>
/// <term>Designates a list of character strings. Specify this control whenever an application must present a list of names, such as file names, from which the user can choose. The user can select a string by clicking it. A selected string is highlighted, and a notification message is passed to the parent window. For more information, see List Boxes. For a table of the list box styles you can specify in the dwStyle parameter, see List Box Styles.</term>
/// </item>
/// <item>
/// <term>MDICLIENT</term>
/// <term>Designates an MDI client window. This window receives messages that control the MDI application's child windows. The recommended style bits are WS_CLIPCHILDREN and WS_CHILD. Specify the WS_HSCROLL and WS_VSCROLL styles to create an MDI client window that allows the user to scroll MDI child windows into view. For more information, see Multiple Document Interface.</term>
/// </item>
/// <item>
/// <term>RichEdit</term>
/// <term>Designates a Microsoft Rich Edit 1.0 control. This window lets the user view and edit text with character and paragraph formatting, and can include embedded Component Object Model (COM) objects. For more information, see Rich Edit Controls. For a table of the rich edit control styles you can specify in the dwStyle parameter, see Rich Edit Control Styles.</term>
/// </item>
/// <item>
/// <term>RICHEDIT_CLASS</term>
/// <term>Designates a Microsoft Rich Edit 2.0 control. This controls let the user view and edit text with character and paragraph formatting, and can include embedded COM objects. For more information, see Rich Edit Controls. For a table of the rich edit control styles you can specify in the dwStyle parameter, see Rich Edit Control Styles.</term>
/// </item>
/// <item>
/// <term>SCROLLBAR</term>
/// <term>Designates a rectangle that contains a scroll box and has direction arrows at both ends. The scroll bar sends a notification message to its parent window whenever the user clicks the control. The parent window is responsible for updating the position of the scroll box, if necessary. For more information, see Scroll Bars. For a table of the scroll bar control styles you can specify in the dwStyle parameter, see Scroll Bar Control Styles.</term>
/// </item>
/// <item>
/// <term>STATIC</term>
/// <term>Designates a simple text field, box, or rectangle used to label, box, or separate other controls. Static controls take no input and provide no output. For more information, see Static Controls. For a table of the static control styles you can specify in the dwStyle parameter, see Static Control Styles.</term>
/// </item>
/// </list>
/// <para><c>CreateWindow</c> is implemented as a call to the CreateWindowEx function, as shown below.</para>
/// <para><code>#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\ CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam) #define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\ CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam) #ifdef UNICODE #define CreateWindow CreateWindowW #else #define CreateWindow CreateWindowA #endif</code></para>
/// <para>Examples</para>
/// <para>For an example, see Using Window Classes.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowa
// void CreateWindowA( lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam );
[PInvokeData("winuser.h", MSDNShortId = "NF:winuser.CreateWindowA")]
public static void CreateWindow(string lpClassName, string lpWindowName, WindowStyles dwStyle,
int x, int y, int nWidth, int nHeight, [Optional] HWND hWndParent, [Optional] HMENU hMenu, HINSTANCE hInstance, [Optional] IntPtr lpParam)
=> CreateWindowEx(0, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
/// <summary>
/// <para>
/// Creates an overlapped, pop-up, or child window with an extended window style; otherwise, this function is identical to the
@ -2269,7 +2381,8 @@ namespace Vanara.PInvoke
// HINSTANCE hInstance, LPVOID lpParam );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "createwindowex")]
public static extern SafeHWND CreateWindowEx(WindowStylesEx dwExStyle, string lpClassName, string lpWindowName, WindowStyles dwStyle, int X, int Y, int nWidth, int nHeight, [Optional] HWND hWndParent, [Optional] HMENU hMenu, HINSTANCE hInstance, [Optional] IntPtr lpParam);
public static extern SafeHWND CreateWindowEx(WindowStylesEx dwExStyle, string lpClassName, string lpWindowName, WindowStyles dwStyle,
int X, int Y, int nWidth, int nHeight, [Optional] HWND hWndParent, [Optional] HMENU hMenu, HINSTANCE hInstance, [Optional] IntPtr lpParam);
/// <summary>
/// <para>
@ -3556,7 +3669,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
[System.Security.SecurityCritical]
public static extern bool GetClientRect(HWND hWnd, [In, Out] ref RECT lpRect);
public static extern bool GetClientRect(HWND hWnd, out RECT lpRect);
/// <summary>
/// Retrieves a handle to the desktop window. The desktop window covers the entire screen. The desktop window is the area on top of
@ -8350,7 +8463,8 @@ namespace Vanara.PInvoke
/// <para>
/// A handle to the class background brush. This member can be a handle to the physical brush to be used for painting the
/// background, or it can be a color value. A color value must be one of the following standard system colors (the value 1 must
/// be added to the chosen color). If a color value is given, you must convert it to one of the following <c>HBRUSH</c> types:
/// be added to the chosen color found in <see cref="SystemColorIndex"/>). If a color value is given, you must convert it to one
/// of the following <c>HBRUSH</c> types:
/// </para>
/// <list type="bullet">
/// <item>
@ -8415,9 +8529,9 @@ namespace Vanara.PInvoke
/// <para>UnregisterClass</para>
/// <para>. An application should not delete these brushes.</para>
/// <para>
/// When this member is <c>NULL</c>, an application must paint its own background whenever it is requested to paint in its client
/// area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND message or
/// test the <c>fErase</c> member of the PAINTSTRUCT structure filled by the BeginPaint function.
/// When this member is <c>NULL</c>, an application must paint its own background whenever it is requested to paint in its
/// client area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND
/// message or test the <c>fErase</c> member of the PAINTSTRUCT structure filled by the BeginPaint function.
/// </para>
/// </summary>
public HBRUSH hbrBackground;