473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Something Wrong with this CustomDraw ListView?

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.NMC USTOMDRAW));
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
Nov 16 '05 #1
1 3776
Problem pointed out to me by co worker
gdc.ReleaseHdc(nmcd.hdc); // shouldn't have been called, not my dc to destroy

tnx
brian
"Brian Keating EI9FXB" wrote:
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.NMC USTOMDRAW));
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

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: uberderf | last post by:
I have the following web page setup: http://angels.uberderf.com/glossary.html I have a 2 column table layout which is a glossary of terms and their meanings. When you view this page in firefox...
3
by: Charles May | last post by:
I have a listview which checkboxes containing items to invoice. The Create Invoice button (button1) is disabled unless there are items checked. However, I had to use an if..then..else statement to...
4
by: Robert | last post by:
something wrong in wx I wrote program training na Artificial Neural Network. It work well in console mode, but when I try to add GUI there is an error: FANN Error 10: Error reading info from...
3
by: Cor | last post by:
Hi all, I think I do something wrong, but I don't see what. I have made a sample. The sample needs only a form with a combobox and this code. (I can tell you that it took a long time to see...
1
by: Holly | last post by:
One of my clients called me this morning, having trouble with their blog loading. The blog does actually load, but only after such an unusually long wait it would have surely driven everyone else...
9
by: Randy | last post by:
Hi all, I've been working on a simple two column layout for a site, but according to browsershots.org, my desing is not showing up correctly in Win/IE 5.01, 5.5 & 6 ! Please see details here:...
1
by: alvarojaviervera | last post by:
Allways I think Firefox was strong, enough ... and so far THE BEST Web- browser (That what I Think) but, now Im fighting with it, may be Im doing something wrong (of course that is what happend to...
2
by: ssndk123 | last post by:
Hi, I'm trying to include some C functions from IOPort.h/cpp to my C++ program.. i placed the IOPort.h into stdafx, but when I try to compile i get the errors like: ioport.h(8) : error C2065:...
10
by: Guillermo_Lopez | last post by:
Hello All, I am using VBA in access to perform some calculations. There is a particular sumation that is wrong (barely). this code is withing a loop. TDist = TDist + TempDist Both TDist...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.