<div>You asking me implementation details on code I just put together in 5 mins.</div>
<div> </div>
<div>OK...</div>
<div> </div>
<div>a) Keyboard - well that sucks. I blame MS.</div>
<div>1) Initially was expecting scroll details to be handled by the record structure. Trapping WMNotify instead of CNNotify doesn't work (just tried).</div>
<div>2) I thought I searched the source and couldn't find it. Guess I searched wrong (since I had LVM_??? in the comment).</div>
<div> </div>
<div>I guess the H and V scrolling thing is down to the implementor for why they'd want to differentiate the two. You can get enough detail to distinguish in the message received if needed.</div>
<div> </div>
<div>Also it will only work with ComCtrl version 6 and above (XP+).<br><br></div>
<div class="gmail_quote">On Fri, Feb 25, 2011 at 2:55 PM, Jolyon Smith <span dir="ltr"><<a href="mailto:jsmith@deltics.co.nz">jsmith@deltics.co.nz</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div lang="EN-NZ" vlink="purple" link="blue">
<div>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">A good spot, but this code doesn’t solve it either. It provides a universal way of handling scrollbar or mousewheel scroll notifications, although a bit of extra work is then required to discriminate between H vs V scrolling, but when I added this to my listview class it didn’t get called as the result of keyboard scrolling either.</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">Couple of supplementary questions: </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p style="MARGIN-LEFT: 22.5pt"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"><span>1.<span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="COLOR: #1f497d; FONT-SIZE: 11pt">Where do you get TWMNotifyLV from? Why not just use TWMNotify ?</span></p>
<p style="MARGIN-LEFT: 22.5pt"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"><span>2.<span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="COLOR: #1f497d; FONT-SIZE: 11pt">Why not use the LVN_BEGINSCROLL/LVN_ENDSCROLL constants, rather than literals + comments ?</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<div style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<p class="MsoNormal"><b><span style="FONT-SIZE: 10pt" lang="EN-US">From:</span></b><span style="FONT-SIZE: 10pt" lang="EN-US"> <a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a> [mailto:<a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a>] <b>On Behalf Of </b>Jeremy North<br>
<b>Sent:</b> Friday, 25 February 2011 16:21
<div>
<div></div>
<div class="h5"><br><b>To:</b> NZ Borland Developers Group - Delphi List<br><b>Subject:</b> Re: [DUG] Listview problem</div></div></span>
<p></p></p></div>
<div>
<div></div>
<div class="h5">
<p class="MsoNormal"> </p>
<div>
<p class="MsoNormal">Don't forget "scrolling" also occurs when you use the arrow keys.</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">My contribution (just made up then)...</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">unit ScrollingListView;</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">interface</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">uses<br> Windows, Messages, ComCtrls, CommCtrl, Controls;</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">type<br> TJSListView = class(TListView)<br> private<br> type<br> TJSScrollEvent = procedure (Sender: TObject; const BeginScroll: Boolean) of object;<br> var<br> FOnEndScroll: TJSScrollEvent;<br>
FOnBeginScroll: TJSScrollEvent;<br> protected<br> procedure DoScroll(const AStart: Boolean); virtual;<br> procedure CNNotify(var Message: TWMNotifyLV); message CN_NOTIFY;<br> public<br> property OnBeginScroll: TJSScrollEvent read FOnBeginScroll write FOnBeginScroll;<br>
property OnEndScroll: TJSScrollEvent read FOnEndScroll write FOnEndScroll;<br> end;</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">implementation</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">{ TJSListView }</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">procedure TJSListView.CNNotify(var Message: TWMNotifyLV);<br>begin<br> if Message.NMHdr.code = -180 then // LVM_BEGINSCROLL<br> begin<br> DoScroll(True);<br> end;<br> if Message.NMHdr.code = -181 then // LVM_ENDSCROLL<br>
begin<br> DoScroll(False);<br> end;<br> inherited;<br>end;</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">procedure TJSListView.DoScroll(const AStart: Boolean);<br>var<br> LEvent: TJSScrollEvent;<br>begin<br> if AStart then<br> LEvent := OnBeginScroll<br> else<br> LEvent := OnEndScroll;<br> if Assigned(LEvent) then<br>
LEvent(Self, AStart);<br>end;</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">end.</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal"><br><br> </p></div>
<div>
<p class="MsoNormal">On Fri, Feb 25, 2011 at 2:01 PM, David O'Brien <<a href="mailto:Dave@iccs.co.nz" target="_blank">Dave@iccs.co.nz</a>> wrote:</p>
<div>
<div>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">Sorted it thanks, had mixed versions of code in the component. The events do fire…</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<div>
<div style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<p class="MsoNormal"><b><span style="FONT-SIZE: 10pt" lang="EN-US">From:</span></b><span style="FONT-SIZE: 10pt" lang="EN-US"> <a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a> [mailto:<a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a>] <b>On Behalf Of </b>Jolyon Smith<br>
<b>Sent:</b> Friday, 25 February 2011 3:43 p.m. </span></p>
<div>
<p class="MsoNormal"><span style="FONT-SIZE: 10pt" lang="EN-US"><br><b>To:</b> 'NZ Borland Developers Group - Delphi List'</span></p></div>
<p class="MsoNormal"><b><span style="FONT-SIZE: 10pt" lang="EN-US">Subject:</span></b><span style="FONT-SIZE: 10pt" lang="EN-US"> Re: [DUG] Listview problem</span><span lang="EN-US"> </span></p></div></div>
<div>
<div>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">A WM_VSCROLL message handler works perfectly for me.</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">However, this will only be sent for scrollbar directed scrolling. To also handle mousewheel scrolling you will have to implement a WM_MOUSEWHEEL message handler (and WM_HMOUSEWHEEL if appropriate to your needs). Could it be mouse scrolling that you are missing ?</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">I would also note that you will almost certainly want to distinguish between H and V scrolling, rather than have a “universal” “some sort of scrolling has occurred” notification. You may also wish to be able to respond both before and after scrolling has occurred.</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">In my list view class I have:</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> TScrollNotification = (</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snBeforeHScroll,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snBeforeHWheel,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snBeforeVScroll,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snBeforeWheel,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snHScroll,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snHWheel,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snVScroll,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snWheel</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> );</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> procedure TXListview.WMVScroll(var aMessage: TWMVScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> DoScroll(snBeforeVScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> inherited;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> DoScroll(snVScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> procedure TXListview.WMHScroll(var aMessage: TWMHScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> DoScroll(snBeforeHScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> inherited;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> DoScroll(snHScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">and similar for mousewheel messages of course, where DoScroll:</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> procedure TXListview.DoScroll(const aNotification: TScrollNotification);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> if (aNotification in [snBeforeHScroll, snBeforeVScroll, snBeforeHWheel, snBeforeWheel]) then</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> CancelEdit;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> if Assigned(fOnScroll) then</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> fOnScroll(self, aNotification);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">i.e. my listview also provides a facility for sub-item editing and when scrolling occurs, the first thing I do before doing the actual scrolling is dismiss any sub-item editor that may be active, before then firing the OnScroll event to allow my application code to respond as it may require.</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">hth</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<div>
<div style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<p class="MsoNormal"><b><span style="FONT-SIZE: 10pt" lang="EN-US">From:</span></b><span style="FONT-SIZE: 10pt" lang="EN-US"> <a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a> [mailto:<a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a>] <b>On Behalf Of </b>David O'Brien<br>
<b>Sent:</b> Friday, 25 February 2011 15:09<br><b>To:</b> NZ Borland Developers Group - Delphi List<br><b>Subject:</b> [DUG] Listview problem</span></p></div></div>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">I am working on an application (D2009) where I need to know when a TListView is Scrolled.</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">I have used Application.OnMessage to look for WM_VScroll messages, but they do not happen, also have tried creating the below which I thought should work:</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> TLVScrollEvent = procedure(Sender: TObject) of object;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> TICListView = class(TListView)</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> private</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> FOnScroll: TLVScrollEvent;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> protected</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> Procedure WMVScroll( Var Msg: TMessage ); message WM_VSCROLL;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> Procedure WMHScroll( Var Msg: TMessage ); message WM_HSCROLL;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> property OnScroll: TLVScrollEvent read FOnScroll write FOnscroll ;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">procedure Register ;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">implementation</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">procedure Register;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> RegisterComponents('Dave', [TICListView]);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">procedure TICListView.WMHScroll(var Msg: TMessage);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> OnScroll ;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> inherited;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">procedure TICListView.WMVScroll(var Msg: TMessage);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> OnScroll ;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> inherited;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">which also doesn’t fire. I have written a list of all messages fired when the scrollbar is moved, but there doesn’t seem to be anything useful…</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">Anyone have a solution?</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">Regards,</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">Dave.</span></p></div></div></div></div>
<p class="MsoNormal"><br>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a><br>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz" target="_blank">delphi-request@delphi.org.nz</a> with Subject: unsubscribe</p></div>
<p class="MsoNormal"> </p></div></div></div></div><br>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<br>
</blockquote></div><br>