//[DllImport("user32.dll", EntryPoint = "LockWindowUpdate", CharSet = CharSet.Auto)] //private static extern int LockWindowUpdateInternal(IntPtr hWnd); //public static void LockWindowUpdate(IWin32Window window) { // if (window == null) // NativeMethods.LockWindowUpdateInternal(IntPtr.Zero); // else // NativeMethods.LockWindowUpdateInternal(window.Handle); //} /// <summary> /// Put an image under the ListView. /// </summary> /// <remarks> /// <para> /// The ListView must have its handle created before calling this. /// </para> /// <para> /// This doesn't work very well. Specifically, it doesn't play well with owner drawn, /// and grid lines are drawn over it. /// </para> /// </remarks> /// <param name="lv"></param> /// <param name="image">The image to be used as the background. If this is null, any existing background image will be cleared.</param> /// <param name="isWatermark">If this is true, the image is pinned to the bottom right and does not scroll. The other parameters are ignored</param> /// <param name="isTiled">If this is true, the image will be tiled to fill the whole control background. The offset parameters will be ignored.</param> /// <param name="xOffset">If both watermark and tiled are false, this indicates the horizontal percentage where the image will be placed. 0 is absolute left, 100 is absolute right.</param> /// <param name="yOffset">If both watermark and tiled are false, this indicates the vertical percentage where the image will be placed.</param> /// <returns></returns> public static bool SetBackgroundImage(ListView lv, Image image, bool isWatermark, bool isTiled, int xOffset, int yOffset) { LVBKIMAGE lvbkimage = new LVBKIMAGE(); // We have to clear any pre-existing background image, otherwise the attempt to set the image will fail. // We don't know which type may already have been set, so we just clear both the watermark and the image. lvbkimage.ulFlags = LVBKIF_TYPE_WATERMARK; IntPtr result = NativeMethods.SendMessageLVBKIMAGE(lv.Handle, LVM_SETBKIMAGE, 0, ref lvbkimage); lvbkimage.ulFlags = LVBKIF_SOURCE_HBITMAP; result = NativeMethods.SendMessageLVBKIMAGE(lv.Handle, LVM_SETBKIMAGE, 0, ref lvbkimage); Bitmap bm = image as Bitmap; if (bm != null) { lvbkimage.hBmp = bm.GetHbitmap(); lvbkimage.ulFlags = isWatermark ? LVBKIF_TYPE_WATERMARK : (isTiled ? LVBKIF_SOURCE_HBITMAP | LVBKIF_STYLE_TILE : LVBKIF_SOURCE_HBITMAP); lvbkimage.xOffset = xOffset; lvbkimage.yOffset = yOffset; result = NativeMethods.SendMessageLVBKIMAGE(lv.Handle, LVM_SETBKIMAGE, 0, ref lvbkimage); } return(result != IntPtr.Zero); }
public static void SetListViewImage(IntPtr listHandle, string imagePath, int xTileOffsetPercent, int yTileOffsetPercent) { if (listHandle == IntPtr.Zero) { return; } try { var apiItem = new LVBKIMAGE(); apiItem.pszImage = Marshal.StringToCoTaskMemUni(imagePath); apiItem.cchImageMax = imagePath.Length; apiItem.ulFlags = LVBKIF_SOURCE_URL | LVBKIF_STYLE_TILE; apiItem.xOffsetPercent = xTileOffsetPercent; apiItem.yOffsetPercent = yTileOffsetPercent; // Set the background color of the ListView to 0XFFFFFFFF (-1) so it will be transparent var clear = new IntPtr(-1); SendMessage(listHandle, W32_LVM.LVM_SETTEXTBKCOLOR, IntPtr.Zero, ref clear); SendMessage(listHandle, W32_LVM.LVM_SETBKIMAGEW, 0, ref apiItem); } catch (Exception ex) { throw new Exception("An exception in API.SetListViewImage occured: " + ex.Message); } }
public static void SetListViewImage(System.Windows.Forms.ListView lst, string ImagePath, ImagePosition Position) { int x = 0; int y = 0; GetImageLocation(Position, ref x, ref y); try{ LVBKIMAGE apiItem = new LVBKIMAGE(); apiItem.pszImage = ImagePath + Convert.ToChar(0); apiItem.cchImageMax = ImagePath.Length; apiItem.ulFlags = LVBKIF_SOURCE_URL | LVBKIF_STYLE_NORMAL; apiItem.xOffsetPercent = x; apiItem.yOffsetPercent = y; // Set the background colour of the ListView to 0XFFFFFFFF (-1) so it will be transparent int clear = CLR_NONE; SendMessage(lst.Handle, LVM_SETTEXTBKCOLOR, 0, ref clear); SendMessage(lst.Handle, LVM_SETBKIMAGE, 0, ref apiItem); } catch (Exception ex) { throw new System.Exception("An exception in ListViewAPI.SetListViewImage occured: " + ex.Message); } }
//[DllImport("user32.dll", EntryPoint = "LockWindowUpdate", CharSet = CharSet.Auto)] //private static extern int LockWindowUpdateInternal(IntPtr hWnd); //public static void LockWindowUpdate(IWin32Window window) { // if (window == null) // NativeMethods.LockWindowUpdateInternal(IntPtr.Zero); // else // NativeMethods.LockWindowUpdateInternal(window.Handle); //} /// <summary> /// Put an image under the ListView. /// </summary> /// <remarks> /// <para> /// The ListView must have its handle created before calling this. /// </para> /// <para> /// This doesn't work very well. /// </para> /// </remarks> /// <param name="lv"></param> /// <param name="image"></param> /// <returns></returns> public static bool SetBackgroundImage(ListView lv, Image image) { const int LVBKIF_SOURCE_NONE = 0x0; //const int LVBKIF_SOURCE_HBITMAP = 0x1; //const int LVBKIF_SOURCE_URL = 0x2; //const int LVBKIF_SOURCE_MASK = 0x3; //const int LVBKIF_STYLE_NORMAL = 0x0; //const int LVBKIF_STYLE_TILE = 0x10; //const int LVBKIF_STYLE_MASK = 0x10; //const int LVBKIF_FLAG_TILEOFFSET = 0x100; const int LVBKIF_TYPE_WATERMARK = 0x10000000; //const int LVBKIF_FLAG_ALPHABLEND = 0x20000000; const int LVM_SETBKIMAGE = 0x108A; LVBKIMAGE lvbkimage = new LVBKIMAGE(); Bitmap bm = image as Bitmap; if (bm == null) { lvbkimage.ulFlags = LVBKIF_SOURCE_NONE; } else { lvbkimage.hBmp = bm.GetHbitmap(); lvbkimage.ulFlags = LVBKIF_TYPE_WATERMARK; } Application.OleRequired(); IntPtr result = NativeMethods.SendMessageLVBKIMAGE(lv.Handle, LVM_SETBKIMAGE, 0, ref lvbkimage); return(result != IntPtr.Zero); }
public static void SetBackgroundImage(this ListView listView, Bitmap bmp) { var imgStruct = new LVBKIMAGE { ulFlags = LVBKIF_SOURCE_HBITMAP | LVBKIF_STYLE_TILE, hbm = bmp.GetHbitmap() }; SendMessage(listView.Handle, LVM_SETBKIMAGE, 0, ref imgStruct); }
public static bool SetBackgroundImage(ListView lv, Image image) { LVBKIMAGE lParam = new LVBKIMAGE(); Bitmap bitmap = image as Bitmap; if (bitmap == null) { lParam.ulFlags = 0; } else { lParam.hBmp = bitmap.GetHbitmap(); lParam.ulFlags = 0x10000000; } Application.OleRequired(); return(SendMessageLVBKIMAGE(lv.Handle, 0x108a, 0, ref lParam) != IntPtr.Zero); }
public static void SetListViewImage(XPListView lst, string ImagePath, int XTileOffsetPercent, int YTileOffsetPercent) { try { LVBKIMAGE apiItem = new LVBKIMAGE(); apiItem.pszImage = ImagePath + Convert.ToChar(0); apiItem.cchImageMax = ImagePath.Length; apiItem.ulFlags = LVBKIF_SOURCE_URL | LVBKIF_STYLE_TILE; apiItem.xOffsetPercent = XTileOffsetPercent; apiItem.yOffsetPercent = YTileOffsetPercent; // Set the background colour of the ListView to 0XFFFFFFFF (-1) so it will be transparent int clear = CLR_NONE; SendMessage(lst.Handle, LVM_SETTEXTBKCOLOR, 0, ref clear); SendMessage(lst.Handle, LVM_SETBKIMAGE, 0, ref apiItem); } catch (Exception ex) { throw new System.Exception("An exception in ListViewAPI.SetListViewImage occured: " + ex.Message); } }
/// <summary> /// Put an image under the ListView. /// </summary> /// <remarks> /// <para> /// The ListView must have its handle created before calling this. /// </para> /// <para> /// This doesn't work very well. /// </para> /// </remarks> /// <param name="lv"></param> /// <param name="image"></param> /// <returns></returns> public static bool SetBackgroundImage(ListView lv, Image image) { const int LVBKIF_SOURCE_NONE = 0x00000000; //const int LVBKIF_SOURCE_HBITMAP = 0x00000001; //const int LVBKIF_SOURCE_URL = 0x00000002; //const int LVBKIF_SOURCE_MASK = 0x00000003; //const int LVBKIF_STYLE_NORMAL = 0x00000000; //const int LVBKIF_STYLE_TILE = 0x00000010; //const int LVBKIF_STYLE_MASK = 0x00000010; //const int LVBKIF_FLAG_TILEOFFSET = 0x00000100; const int LVBKIF_TYPE_WATERMARK = 0x10000000; //const int LVBKIF_FLAG_ALPHABLEND = 0x20000000; const int LVM_SETBKIMAGE = 0x108A; LVBKIMAGE lvbkimage = new LVBKIMAGE(); Bitmap bm = image as Bitmap; if (bm == null) lvbkimage.ulFlags = LVBKIF_SOURCE_NONE; else { lvbkimage.hBmp = bm.GetHbitmap(); lvbkimage.ulFlags = LVBKIF_TYPE_WATERMARK; } Application.OleRequired(); IntPtr result = NativeMethods.SendMessageLVBKIMAGE(lv.Handle, LVM_SETBKIMAGE, 0, ref lvbkimage); return (result != IntPtr.Zero); }
//[DllImport("user32.dll", EntryPoint = "LockWindowUpdate", CharSet = CharSet.Auto)] //private static extern int LockWindowUpdateInternal(IntPtr hWnd); //public static void LockWindowUpdate(IWin32Window window) { // if (window == null) // NativeMethods.LockWindowUpdateInternal(IntPtr.Zero); // else // NativeMethods.LockWindowUpdateInternal(window.Handle); //} /// <summary> /// Put an image under the ListView. /// </summary> /// <remarks> /// <para> /// The ListView must have its handle created before calling this. /// </para> /// <para> /// This doesn't work very well. Specifically, it doesn't play well with owner drawn, /// and grid lines are drawn over it. /// </para> /// </remarks> /// <param name="lv"></param> /// <param name="image">The image to be used as the background. If this is null, any existing background image will be cleared.</param> /// <param name="isWatermark">If this is true, the image is pinned to the bottom right and does not scroll. The other parameters are ignored</param> /// <param name="isTiled">If this is true, the image will be tiled to fill the whole control background. The offset parameters will be ignored.</param> /// <param name="xOffset">If both watermark and tiled are false, this indicates the horizontal percentage where the image will be placed. 0 is absolute left, 100 is absolute right.</param> /// <param name="yOffset">If both watermark and tiled are false, this indicates the vertical percentage where the image will be placed.</param> /// <returns></returns> public static bool SetBackgroundImage(ListView lv, Image image, bool isWatermark, bool isTiled, int xOffset, int yOffset) { LVBKIMAGE lvbkimage = new LVBKIMAGE(); // We have to clear any pre-existing background image, otherwise the attempt to set the image will fail. // We don't know which type may already have been set, so we just clear both the watermark and the image. lvbkimage.ulFlags = LVBKIF_TYPE_WATERMARK; IntPtr result = NativeMethods.SendMessageLVBKIMAGE(lv.Handle, LVM_SETBKIMAGE, 0, ref lvbkimage); lvbkimage.ulFlags = LVBKIF_SOURCE_HBITMAP; result = NativeMethods.SendMessageLVBKIMAGE(lv.Handle, LVM_SETBKIMAGE, 0, ref lvbkimage); Bitmap bm = image as Bitmap; if (bm != null) { lvbkimage.hBmp = bm.GetHbitmap(); lvbkimage.ulFlags = isWatermark ? LVBKIF_TYPE_WATERMARK : (isTiled ? LVBKIF_SOURCE_HBITMAP | LVBKIF_STYLE_TILE : LVBKIF_SOURCE_HBITMAP); lvbkimage.xOffset = xOffset; lvbkimage.yOffset = yOffset; result = NativeMethods.SendMessageLVBKIMAGE(lv.Handle, LVM_SETBKIMAGE, 0, ref lvbkimage); } return (result != IntPtr.Zero); }
IntPtr SendMessage(IntPtr hWnd, W32_LVM msg, int wParam, ref LVBKIMAGE lParam);
private void SetWaterMark(Boolean show) { LVBKIMAGE backImage = new LVBKIMAGE(); if (show) { backImage.ulFlags = LVBKIF.STYLE_NORMAL | LVBKIF.TYPE_WATERMARK | LVBKIF.FLAG_ALPHABLEND; backImage.hbm = global::ILMergeGui.Properties.Resources.IconDropHere.GetHbitmap(); } else { backImage.ulFlags = LVBKIF.SOURCE_NONE; } IntPtr pointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LVBKIMAGE))); Marshal.StructureToPtr(backImage, pointer, false); SendMessage( ListAssembly.Handle, (int)LVM.SETBKIMAGEW, IntPtr.Zero, pointer); //DefWndProc(ref message); Marshal.FreeHGlobal(pointer); ListAssembly.Invalidate(); }
internal extern static int SendMessage(IntPtr hwnd, uint msg, uint wParam, LVBKIMAGE lParam);
internal static extern int SendMessage( IntPtr hwnd, uint msg, uint wParam, LVBKIMAGE lParam );
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref LVBKIMAGE lParam);
private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, ref LVBKIMAGE lParam);
public static extern IntPtr SendMessageLVBKIMAGE(IntPtr hWnd, int Msg, int wParam, ref LVBKIMAGE lParam);
public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref LVBKIMAGE lParam);
public static Bitmap GetListViewBackgroundImage(IntPtr lvHandle) { LVBKIMAGE lvBkImage = new LVBKIMAGE(); lvBkImage.ulFlags = LVBKIF.STYLE_WATERMARK | LVBKIF.FLAG_ALPHABLEND; SendMessage(lvHandle, LVM_GETBKIMAGE, IntPtr.Zero, ref lvBkImage); if (lvBkImage.hbm == IntPtr.Zero) return null; else return Bitmap.FromHbitmap(lvBkImage.hbm); }
public static void SetListViewBackgroundImage(IntPtr lvHandle, Bitmap bitmap) { LVBKIMAGE lvBkImage = new LVBKIMAGE(); lvBkImage.ulFlags = LVBKIF.STYLE_WATERMARK | LVBKIF.FLAG_ALPHABLEND; lvBkImage.hbm = bitmap.GetHbitmap(); lvBkImage.cchImageMax = 0; lvBkImage.xOffsetPercent = 100; lvBkImage.yOffsetPercent = 100; IntPtr lbkImageptr = Marshal.AllocHGlobal(Marshal.SizeOf(lvBkImage)); Marshal.StructureToPtr(lvBkImage, lbkImageptr, false); SendMessage(lvHandle, LVM_SETBKIMAGE, IntPtr.Zero, lbkImageptr); Marshal.FreeHGlobal(lbkImageptr); }