diff --git a/PInvoke/ComCtl32/CommCtrl.ListView.cs b/PInvoke/ComCtl32/CommCtrl.ListView.cs index 9725ddc8..3d022cc7 100644 --- a/PInvoke/ComCtl32/CommCtrl.ListView.cs +++ b/PInvoke/ComCtl32/CommCtrl.ListView.cs @@ -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()); + } /// /// Contains information used when searching for a list-view item. This structure is identical to LV_FINDINFO but has been renamed diff --git a/PInvoke/User32/WinUser.Message.cs b/PInvoke/User32/WinUser.Message.cs index e5c8ef65..b113d2c7 100644 --- a/PInvoke/User32/WinUser.Message.cs +++ b/PInvoke/User32/WinUser.Message.cs @@ -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); + /// + /// + /// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified + /// window and does not return until the window procedure has processed the message. + /// + /// + /// 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. + /// + /// + /// The type of the message. This can be any type that converts to . + /// The type of the parameter. This must be a type that can be marshaled to memory. + /// + /// Type: HWND + /// + /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST + /// ((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. + /// + /// + /// 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. + /// + /// + /// + /// 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; it depends on the message sent. + /// + /// + /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). + /// + /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a + /// unique message for inter-application communication. + /// + /// + /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= + /// WM_USER) to another process, you must do custom marshalling. + /// + /// + /// 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. + /// + /// + /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This + /// functionality is not guaranteed to work for other types of applications. + /// + /// Examples + /// For an example, see Displaying Keyboard Input. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage + [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] + public static IntPtr SendMessage(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); + } + /// /// /// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified