Updated SendMessage dependencies in ListView code

pull/211/head
dahall 2020-12-31 20:46:27 -07:00
parent 4e44329587
commit 6dc8b6a749
2 changed files with 83 additions and 4 deletions

View File

@ -1188,8 +1188,8 @@ namespace Vanara.PInvoke
[PInvokeData("commctrl.h", MSDNShortId = "listview_getitemindexrect")]
public static bool ListView_GetItemIndexRect(HWND hwnd, in LVITEMINDEX plvii, int iSubItem, ListViewItemRect code, out Rectangle prc)
{
var rc = new PRECT((int)code, iSubItem, 0, 0);
var lr = SendMessage(hwnd, ListViewMessage.LVM_GETITEMINDEXRECT, plvii, rc);
var rc = new RECT((int)code, iSubItem, 0, 0);
var lr = SendMessage(hwnd, ListViewMessage.LVM_GETITEMINDEXRECT, in plvii, ref rc);
prc = lr == IntPtr.Zero ? Rectangle.Empty : (Rectangle)rc;
return lr != IntPtr.Zero;
}
@ -1340,8 +1340,12 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/desktop/api/commctrl/nf-commctrl-listview_setitemindexstate void
// ListView_SetItemIndexState( hwndLV, plvii, data, mask );
[PInvokeData("commctrl.h", MSDNShortId = "listview_setitemindexstate")]
public static HRESULT ListView_SetItemIndexState(HWND hwndLV, in LVITEMINDEX plvii, uint data, ListViewItemState mask) =>
new HRESULT(SendMessage(hwndLV, (uint)ListViewMessage.LVM_SETITEMINDEXSTATE, in plvii, new LVITEM(0) { stateMask = mask, state = data }).ToInt32());
public static HRESULT ListView_SetItemIndexState(HWND hwndLV, in LVITEMINDEX plvii, uint data, ListViewItemState mask)
{
var lvi = new LVITEM(0) { stateMask = mask, state = data };
using var plvi = new PinnedObject(lvi);
return new HRESULT(SendMessage(hwndLV, (uint)ListViewMessage.LVM_SETITEMINDEXSTATE, in plvii, plvi).ToInt32());
}
/// <summary>
/// Contains information used when searching for a list-view item. This structure is identical to LV_FINDINFO but has been renamed

View File

@ -2448,6 +2448,81 @@ namespace Vanara.PInvoke
where TMsg : struct, IConvertible where TWP : struct, IConvertible
=> SendMessage(hWnd, Convert.ToUInt32(msg), (IntPtr)Convert.ToInt64(wParam), IntPtr.Zero);
/// <summary>
/// <para>
/// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window procedure for the specified
/// window and does not return until the window procedure has processed the message.
/// </para>
/// <para>
/// To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a
/// thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.
/// </para>
/// </summary>
/// <typeparam name="TMsg">The type of the message. This can be any type that converts to <see cref="uint"/>.</typeparam>
/// <typeparam name="TWP">The type of the <paramref name="wParam"/> parameter. This must be a type that can be marshaled to memory.</typeparam>
/// <param name="hWnd">
/// <para>Type: <c>HWND</c></para>
/// <para>
/// A handle to the window whose window procedure will receive the message. If this parameter is <c>HWND_BROADCAST</c>
/// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows,
/// overlapped windows, and pop-up windows; but the message is not sent to child windows.
/// </para>
/// <para>
/// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of
/// lesser or equal integrity level.
/// </para>
/// </param>
/// <param name="msg">
/// <para>Type: <c>UINT</c></para>
/// <para>The message to be sent.</para>
/// <para>For lists of the system-provided messages, see System-Defined Messages.</para>
/// </param>
/// <param name="wParam">
/// <para>Type: <c>WPARAM</c></para>
/// <para>Additional message-specific information.</para>
/// </param>
/// <param name="lParam">
/// <para>Type: <c>LPARAM</c></para>
/// <para>Additional message-specific information.</para>
/// </param>
/// <returns>
/// <para>Type: <c>LRESULT</c></para>
/// <para>The return value specifies the result of the message processing; it depends on the message sent.</para>
/// </returns>
/// <remarks>
/// <para>When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).</para>
/// <para>
/// Applications that need to communicate using <c>HWND_BROADCAST</c> should use the RegisterWindowMessage function to obtain a
/// unique message for inter-application communication.
/// </para>
/// <para>
/// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those &gt;=
/// <c>WM_USER</c>) to another process, you must do custom marshalling.
/// </para>
/// <para>
/// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the
/// specified window was created by a different thread, the system switches to that thread and calls the appropriate window
/// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The
/// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming
/// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set.
/// For more information on nonqueued messages, see Nonqueued Messages.
/// </para>
/// <para>
/// An accessibility application can use <c>SendMessage</c> to send WM_APPCOMMAND messages to the shell to launch applications. This
/// functionality is not guaranteed to work for other types of applications.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Displaying Keyboard Input.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
[PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")]
public static IntPtr SendMessage<TMsg, TWP>(HWND hWnd, TMsg msg, in TWP wParam, [Optional] IntPtr lParam)
where TMsg : struct, IConvertible where TWP : struct
{
using var wmem = SafeCoTaskMemHandle.CreateFromStructure(wParam);
return SendMessage(hWnd, Convert.ToUInt32(msg), wmem, lParam);
}
/// <summary>
/// <para>
/// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window procedure for the specified