Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OwnerDraw ListView

61 views
Skip to first unread message

Kevin

unread,
May 24, 2010, 11:28:26 AM5/24/10
to
I have a ControlNotify method on a DataWindow. What I want to do is use
change the colour of items in a ListView depending on a value. The
method code is shown below and compiles without any problem.

When the program runs it never gets in to the code to handle the
colouring, oEvent:NotifyCode is never NM_CUSTOMDRAW. This is on a
DataWindow, but it does not work on a dialog either.

Can anyone tell me what I am missing? I have search the newsgroups and
found links to examples which no longer exists. The articles don't tell
me what I may be missing.

Thanks in advance.

Kevin

method ControlNotify( oEvent ) class MainWindow
//
// Control notify event handler
//
local p_NMCD as _winNMLVCustomDraw
local dwDrawStage as dword
local dwIndex as dword
local oLV_Item as ListViewItem
//local oFont as Font

if oEvent:NotifyCode == NM_CUSTOMDRAW
p_NMCD := ptr( _cast, oEvent:lParam )
dwDrawStage := p_NMCD.nmcd.dwDrawStage

do case
case dwDrawStage == CDDS_PREPAINT
self:EventReturnValue := _or( CDRF_NOTIFYITEMDRAW,
CDRF_NOTIFYPOSTPAINT )

case _and( dwDrawStage, CDDS_ITEMPREPAINT ) > 0
dwIndex := p_NMCD.nmcd.dwItemSpec
oLV_Item := self:oDClvStructure:GetItemAttributes( dwIndex + 1 )

if IsNil( oLV_Item )
if self:lDragActive
if _and( p_NMCD.nmcd.uItemState, CDIS_SELECTED ) == CDIS_SELECTED
// White on dark blue / highlight
p_NMCD.clrText := dword(RGB(255, 255, 255))
p_NMCD.clrTextBk := dword(RGB( 0, 0, 128))

else
// black on white
p_NMCD.clrText := dword(RGB( 0, 0, 0 ))
p_NMCD.clrTextBk := dword(RGB( 255, 255, 255 ))
endif

elseif _and( p_NMCD.nmcd.uItemState, CDIS_SELECTED ) ==
CDIS_SELECTED
// white on dark blue / highlight color
p_NMCD.clrText := dword(RGB( 255, 255, 255 ))
p_NMCD.clrTextBk := dword(RGB( 0, 0, 128 ))

else
// black on white
p_NMCD.clrText := dword(RGB( 255, 255, 255 ))
p_NMCD.clrTextBk := dword(RGB( 255, 255, 255 ))
endif

else
// (p_NMCD.iSubItem) % 8 will give you the
// 0 base column #
// (i.e. 0 means column 1 on the screen)
if (p_NMCD.iSubItem ) % 8 == 1 .and. ;
oLV_Item:GetValue( #F_NAME ) == "PUR_DATE"
//oFont := Font{, 10, "Arial" }
//oFont:Bold := true
//SelectObject( p_NMCD.nmcd.hdc, oFont:Handle() )
// White on dark blue
p_NMCD.clrText := dword(RGB( 255, 255, 255 ))
p_NMCD.clrTextBk := dword(RGB( 0, 0, 255 ))
else
// black on white
p_NMCD.clrText := dword(RGB( 255, 255, 255 ))
p_NMCD.clrTextBk := dword(RGB( 0, 0, 0 ))

endif

endif

// Return this again for all subitems
self:EventReturnValue := _or( CDRF_NOTIFYITEMDRAW,
CDRF_NOTIFYPOSTPAINT )

otherwise
self:EventReturnValue := _or( CDRF_NOTIFYITEMDRAW,
CDRF_NOTIFYPOSTPAINT )

endcase

SetWindowLong( self:Handle(), DWL_MSGRESULT, self:EventReturnValue )

endif

return self:EventReturnValue

Malcolm Gray

unread,
May 24, 2010, 12:24:23 PM5/24/10
to
On 24/05/2010 16:28, Kevin wrote:
>
>
> I have a ControlNotify method on a DataWindow. What I want to do is use
> change the colour of items in a ListView depending on a value. The
> method code is shown below and compiles without any problem.
>
> When the program runs it never gets in to the code to handle the
> colouring, oEvent:NotifyCode is never NM_CUSTOMDRAW. This is on a
> DataWindow, but it does not work on a dialog either.

OK - well our draw code looks very similar.
What version of VO are you using?
(i seem to remember in this area some casting problems so
getting -12 vs getting 0xFFFFFFF4)

John Martens

unread,
May 24, 2010, 12:35:38 PM5/24/10
to
Kevin,

Make it:
IF DWORD(oEvent:NotifyCode) = NM_CUSTOMDRAW

John


Op 24-5-2010 17:28, Kevin schreef:

Kevin

unread,
May 24, 2010, 1:44:47 PM5/24/10
to
Malcolm,

I am using VO2.8 and intended putting that it my original post. Casting
was something I was thinking I had heard of but could not remember
exactly what it was. John's answer gave me the solution. Just need to
figure out some of the other logic to get exactly what I want.

Thanks.

Kevin

"Malcolm Gray" <malcolm-...@jobstream.com> wrote in message
news:pqlqc7-...@malcolmdesk.malph.dyndns.org.malph.dyndns.org:

Kevin

unread,
May 24, 2010, 1:48:41 PM5/24/10
to
John,

Thanks that worked.

Do you know how to identify the actual control involved? I am new to
coding at this level.

Kevin


"John Martens" <adsl6...@tiscali.nl> wrote in message
news:4bfaaacf$0$30707$5fc...@news.tiscali.nl:

John Martens

unread,
May 24, 2010, 2:22:19 PM5/24/10
to
I'm using it only in sub-windows which have one control.

I do not know if this works: oEvent:Control:Name

John

Op 24-5-2010 19:48, Kevin schreef:

Kevin

unread,
May 24, 2010, 2:28:52 PM5/24/10
to
John,

Scrap that last question, I found the answer.

What is the difference between a dialog window and a DataWindow for this
method? I modified the method in a dialog window and it works fine. But
when I add the method to a DataWindow the app (which is just a
datawindow) starts and then quits straight away?

Kevin

"Kevin" <kdmu...@eircom.net> wrote in message
news:WZyKn.52$K4....@news.indigo.ie:

John Martens

unread,
May 24, 2010, 3:42:09 PM5/24/10
to
Kevin,

I think it is in the last lines for a data-window.
This is my (simplified)code in a data-window

John

LOCAL pNMCustomDraw AS _WINNMLVCUSTOMDRAW
LOCAL dwDrawStage AS DWORD
LOCAL dwItem AS DWORD
LOCAL cStatus := '' AS STRING

DO CASE
CASE DWORD(oEvent:NotifyCode) = NM_CUSTOMDRAW
pNMCustomDraw := PTR( _CAST , oEvent:lParam )
dwDrawStage := pNMCustomDraw.nmcd.dwDrawStage
DO CASE
CASE dwDrawStage = CDDS_PREPAINT
SELF:EventReturnValue := CDRF_NOTIFYITEMDRAW
CASE dwDrawStage = CDDS_ITEMPREPAINT
dwItem := pNMCustomDraw.nmcd.dwItemSpec
// dwItem contains the 0-based item and
// pNMCustomDraw.iSubItem contains the 0-based subitem == column (runs
only till 0 when full-row-select is on)
// White RGB( 255 , 255 , 255 )
// Green RGB( 0 , 255 , 0 )
// Red RGB( 255 , 0 , 0 )
// Yellow RGB( 255 , 255 , 0 )
// Grey RGB( 192 , 192 , 192 )
*
* get status and color


SELF:EventReturnValue := CDRF_NEWFONT
OTHERWISE
SELF:EventReturnValue := CDRF_DODEFAULT
ENDCASE
SetWindowLong( SELF:__GetFormSurface():Handle() , DWL_MSGRESULT ,
SELF:EventReturnValue )
SELF:__GetFormSurface():EventReturnValue := SELF:EventReturnValue
RETURN SELF:EventReturnValue
ENDCASE
RETURN SUPER:ControlNotify(oEvent)


Op 24-5-2010 20:28, Kevin schreef:

Geoff Schaller

unread,
May 24, 2010, 6:19:42 PM5/24/10
to
Kevin.

Let me introduce you to bBrowser. Just does all this as par for the
course....

Geoff

"Kevin" <kdmu...@eircom.net> wrote in message

news:pWwKn.49$K4...@news.indigo.ie:

Kevin

unread,
May 25, 2010, 7:39:53 AM5/25/10
to
Geoff,

I am well aware of bBrowser and use it. This is simply something I was
experimenting with.

Kevin


"Geoff Schaller" <geo...@softxwareobjectives.com.au> wrote in message
news:2YCKn.26920$pv.2...@news-server.bigpond.net.au:

0 new messages