-
July 18th, 2010, 08:13 AM
#1
winctrl1.cpp line 39 -> OwnerDraw problem
I have a picturebox control with OwnerDraw set to true.
In the CDialog1 class I wrote code to draw onto it in the function
Code:
void CDialog1 ::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if(lpDrawItemStruct->itemID = IDC_PICBOX)
{
//drawcode...
}
CDialogEx::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
I tried to create a class CPicBox derived from CStatic and to subclass
Code:
void CPicBox ::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CStatic::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
but in DEBUG mode I keep getting the assertion failure on winctrl1.cpp at line 39 alias "OnDrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) is not overloaded and the virtual base function is called where ASSERT(FALSE); is located"
Can someone help me please?
-
July 18th, 2010, 08:43 AM
#2
Re: winctrl1.cpp line 39 -> OwnerDraw problem
Problem solved, excuse me.
I solved putting a simple "else" in this position:
Code:
void CDialog1 ::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if(lpDrawItemStruct->itemID = IDC_PICBOX)
{
//drawcode...
}
else <-
CDialogEx::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
Thank you anyway, you are always ready to help people for free
-
July 18th, 2010, 09:55 PM
#3
Re: winctrl1.cpp line 39 -> OwnerDraw problem
Fine if it works now, but shouldn't
Code:
if(lpDrawItemStruct->itemID = IDC_PICBOX)
better be
Code:
if(lpDrawItemStruct->itemID == IDC_PICBOX)
?
In case you retyped that code snipped manually and your actual code is like the second sample, everything's fine. But if not your else clause will pretty sure never be executed.
HTH
-
August 4th, 2010, 04:07 AM
#4
Re: winctrl1.cpp line 39 -> OwnerDraw problem
You're right that the else code is never executed.
But seems like you cannot modify into "==" because the code gets executed only when a WM_OWNERDRAW control needs redraw. Since my dialog has only one WM_OWNERDRAW control in it, the IF clause and the ELSE could be cut out: the code needs to be executed every time the onDrawItem function gets called (in my case at least)
Last edited by pm44xl23; August 4th, 2010 at 04:16 AM.
-
August 4th, 2010, 08:35 AM
#5
Re: winctrl1.cpp line 39 -> OwnerDraw problem
So it was intentionally meant to be an assignment instead of a comparison? But then again, as IDC_PICBOX is a constant, the controlling if statement is redundant and you can execute the drawing code unconditionally.
Ok, if this function is only called for a single control and lpDrawItemStruct->itemID is already equal to IDC_PICBOX in any case, the assignemnt - whether intended or not - at least does no harm. (But that might not be the case anymore when you change your code later on.)
But then the assertion faiure you get must have another reason that I can't spot, at least now.
-
August 4th, 2010, 08:19 PM
#6
Re: winctrl1.cpp line 39 -> OwnerDraw problem
You won't believe me but I solved it creating a CStatic subclass for the control we were talking.
Just adding the code for the ownerdraw method (empty and unused), solves the assertion. This isn't professional but... at least it works.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|