G
Guest
Hello there,
I've been playing with custom draw and am having a bit of difficulty,
Namely the graphics function in this function throws invalid arg exception.
Im pretty sure this is correct cause the rect part of the nmcd seems to be
nonsence
public int OnItemPrePaint(int idCtrl, ref Win32.NMCUSTOMDRAW nmcd)
{
using (Graphics gdc = Graphics.FromHdc(nmcd.hdc)){
gdc.ReleaseHdc(nmcd.hdc);
}
return (int)Win32.CDRF.CDRF_SKIPDEFAULT;
}
Now i handle this in my WndProc of the MyCustListView : ListView, class.
protected override void WndProc(ref Message m)
{
IntPtr ret = IntPtr.Zero;
MessageHandled = false;
if (msg.Msg == (int)Win32.OCM.OCM_NOTIFY)
{
Win32.NMHDR hrd = (Win32.NMHDR)msg.GetLParam(typeof(Win32.NMHDR));
if ((hrd.code == (int)Win32.NM.NM_CUSTOMDRAW) && (hrd.hwndFrom ==
this.Handel))
{
MessageHandled = true;
Win32.NMCUSTOMDRAW nmcd =
(Win32.NMCUSTOMDRAW)msg.GetLParam(typeof(Win32.NMCUSTOMDRAW));
msg.Result = (IntPtr)OnCustomDraw((int)msg.WParam.ToInt32(), ref nmcd);
}
}
.. . .
}
private int OnCustomDraw(int idCtrl, ref Win32.NMCUSTOMDRAW nmcd)
{
switch (nmcd.dwDrawStage)
{
case (int)Win32.CDDS.CDDS_ITEMPREPAINT:
nResult = m_interfaceCustDraw.OnItemPrePaint(idCtrl, ref nmcd);
break;
....
}
public int OnItemPrePaint(int idCtrl, ref Win32.NMCUSTOMDRAW nmcd)
{
using (Graphics gdc = Graphics.FromHdc(nmcd.hdc)){
gdc.ReleaseHdc(nmcd.hdc);
}
return (int)Win32.CDRF.CDRF_SKIPDEFAULT;
}
///structures used
[StructLayout(LayoutKind.Sequential)]
public struct NMHDR
{
public IntPtr hwndFrom;
public int idFrom;
public int code;
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
public struct NMCUSTOMDRAW
{
public NMHDR hdr;
public int dwDrawStage;
public IntPtr hdc;
public RECT rc;
public int dwItemSpec;
public int uItemState;
public int lItemlParam;
}
Any ideas on what i'm doing wrong?
As far as i can see the structures are the same as the win32, i'm handling
the correct messages.
Gonna do a win32 sample just to check what happen there maybe i'll see
something
thanks for any help
brian
I've been playing with custom draw and am having a bit of difficulty,
Namely the graphics function in this function throws invalid arg exception.
Im pretty sure this is correct cause the rect part of the nmcd seems to be
nonsence
public int OnItemPrePaint(int idCtrl, ref Win32.NMCUSTOMDRAW nmcd)
{
using (Graphics gdc = Graphics.FromHdc(nmcd.hdc)){
gdc.ReleaseHdc(nmcd.hdc);
}
return (int)Win32.CDRF.CDRF_SKIPDEFAULT;
}
Now i handle this in my WndProc of the MyCustListView : ListView, class.
protected override void WndProc(ref Message m)
{
IntPtr ret = IntPtr.Zero;
MessageHandled = false;
if (msg.Msg == (int)Win32.OCM.OCM_NOTIFY)
{
Win32.NMHDR hrd = (Win32.NMHDR)msg.GetLParam(typeof(Win32.NMHDR));
if ((hrd.code == (int)Win32.NM.NM_CUSTOMDRAW) && (hrd.hwndFrom ==
this.Handel))
{
MessageHandled = true;
Win32.NMCUSTOMDRAW nmcd =
(Win32.NMCUSTOMDRAW)msg.GetLParam(typeof(Win32.NMCUSTOMDRAW));
msg.Result = (IntPtr)OnCustomDraw((int)msg.WParam.ToInt32(), ref nmcd);
}
}
.. . .
}
private int OnCustomDraw(int idCtrl, ref Win32.NMCUSTOMDRAW nmcd)
{
switch (nmcd.dwDrawStage)
{
case (int)Win32.CDDS.CDDS_ITEMPREPAINT:
nResult = m_interfaceCustDraw.OnItemPrePaint(idCtrl, ref nmcd);
break;
....
}
public int OnItemPrePaint(int idCtrl, ref Win32.NMCUSTOMDRAW nmcd)
{
using (Graphics gdc = Graphics.FromHdc(nmcd.hdc)){
gdc.ReleaseHdc(nmcd.hdc);
}
return (int)Win32.CDRF.CDRF_SKIPDEFAULT;
}
///structures used
[StructLayout(LayoutKind.Sequential)]
public struct NMHDR
{
public IntPtr hwndFrom;
public int idFrom;
public int code;
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
public struct NMCUSTOMDRAW
{
public NMHDR hdr;
public int dwDrawStage;
public IntPtr hdc;
public RECT rc;
public int dwItemSpec;
public int uItemState;
public int lItemlParam;
}
Any ideas on what i'm doing wrong?
As far as i can see the structures are the same as the win32, i'm handling
the correct messages.
Gonna do a win32 sample just to check what happen there maybe i'll see
something
thanks for any help
brian