[DUG] Listview problem
Jeremy North
jeremy.north at gmail.com
Fri Feb 25 17:20:57 NZDT 2011
The first line proves that friday arvo drinks are fast approaching...
On Fri, Feb 25, 2011 at 3:20 PM, Jeremy North <jeremy.north at gmail.com>wrote:
> You asking me implementation details on code I just put together in 5 mins.
>
> OK...
>
> a) Keyboard - well that sucks. I blame MS.
> 1) Initially was expecting scroll details to be handled by the record
> structure. Trapping WMNotify instead of CNNotify doesn't work (just tried).
> 2) I thought I searched the source and couldn't find it. Guess I searched
> wrong (since I had LVM_??? in the comment).
>
> 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.
>
> Also it will only work with ComCtrl version 6 and above (XP+).
>
> On Fri, Feb 25, 2011 at 2:55 PM, Jolyon Smith <jsmith at deltics.co.nz>wrote:
>
>> 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.
>>
>>
>>
>> Couple of supplementary questions:
>>
>>
>>
>> 1. Where do you get TWMNotifyLV from? Why not just use TWMNotify ?
>>
>> 2. Why not use the LVN_BEGINSCROLL/LVN_ENDSCROLL constants, rather
>> than literals + comments ?
>>
>>
>>
>>
>>
>> *From:* delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
>> *On Behalf Of *Jeremy North
>> *Sent:* Friday, 25 February 2011 16:21
>>
>> *To:* NZ Borland Developers Group - Delphi List
>> *Subject:* Re: [DUG] Listview problem
>>
>>
>>
>> Don't forget "scrolling" also occurs when you use the arrow keys.
>>
>>
>>
>> My contribution (just made up then)...
>>
>>
>>
>> unit ScrollingListView;
>>
>>
>>
>> interface
>>
>>
>>
>> uses
>> Windows, Messages, ComCtrls, CommCtrl, Controls;
>>
>>
>>
>> type
>> TJSListView = class(TListView)
>> private
>> type
>> TJSScrollEvent = procedure (Sender: TObject; const BeginScroll:
>> Boolean) of object;
>> var
>> FOnEndScroll: TJSScrollEvent;
>> FOnBeginScroll: TJSScrollEvent;
>> protected
>> procedure DoScroll(const AStart: Boolean); virtual;
>> procedure CNNotify(var Message: TWMNotifyLV); message CN_NOTIFY;
>> public
>> property OnBeginScroll: TJSScrollEvent read FOnBeginScroll write
>> FOnBeginScroll;
>> property OnEndScroll: TJSScrollEvent read FOnEndScroll write
>> FOnEndScroll;
>> end;
>>
>>
>>
>> implementation
>>
>>
>>
>> { TJSListView }
>>
>>
>>
>> procedure TJSListView.CNNotify(var Message: TWMNotifyLV);
>> begin
>> if Message.NMHdr.code = -180 then // LVM_BEGINSCROLL
>> begin
>> DoScroll(True);
>> end;
>> if Message.NMHdr.code = -181 then // LVM_ENDSCROLL
>> begin
>> DoScroll(False);
>> end;
>> inherited;
>> end;
>>
>>
>>
>> procedure TJSListView.DoScroll(const AStart: Boolean);
>> var
>> LEvent: TJSScrollEvent;
>> begin
>> if AStart then
>> LEvent := OnBeginScroll
>> else
>> LEvent := OnEndScroll;
>> if Assigned(LEvent) then
>> LEvent(Self, AStart);
>> end;
>>
>>
>>
>> end.
>>
>>
>>
>>
>>
>>
>>
>> On Fri, Feb 25, 2011 at 2:01 PM, David O'Brien <Dave at iccs.co.nz> wrote:
>>
>> Sorted it thanks, had mixed versions of code in the component. The events
>> do fire…
>>
>>
>>
>> *From:* delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
>> *On Behalf Of *Jolyon Smith
>> *Sent:* Friday, 25 February 2011 3:43 p.m.
>>
>>
>> *To:* 'NZ Borland Developers Group - Delphi List'
>>
>> *Subject:* Re: [DUG] Listview problem
>>
>>
>>
>> A WM_VSCROLL message handler works perfectly for me.
>>
>>
>>
>> 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 ?
>>
>>
>>
>> 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.
>>
>>
>>
>>
>>
>> In my list view class I have:
>>
>>
>>
>> TScrollNotification = (
>>
>> snBeforeHScroll,
>>
>> snBeforeHWheel,
>>
>> snBeforeVScroll,
>>
>> snBeforeWheel,
>>
>> snHScroll,
>>
>> snHWheel,
>>
>> snVScroll,
>>
>> snWheel
>>
>> );
>>
>>
>>
>>
>>
>> procedure TXListview.WMVScroll(var aMessage: TWMVScroll);
>>
>> begin
>>
>> DoScroll(snBeforeVScroll);
>>
>> inherited;
>>
>> DoScroll(snVScroll);
>>
>> end;
>>
>>
>>
>> procedure TXListview.WMHScroll(var aMessage: TWMHScroll);
>>
>> begin
>>
>> DoScroll(snBeforeHScroll);
>>
>> inherited;
>>
>> DoScroll(snHScroll);
>>
>> end;
>>
>>
>>
>>
>>
>>
>>
>> and similar for mousewheel messages of course, where DoScroll:
>>
>>
>>
>>
>>
>> procedure TXListview.DoScroll(const aNotification: TScrollNotification);
>>
>> begin
>>
>> if (aNotification in [snBeforeHScroll, snBeforeVScroll,
>> snBeforeHWheel, snBeforeWheel]) then
>>
>> CancelEdit;
>>
>>
>>
>> if Assigned(fOnScroll) then
>>
>> fOnScroll(self, aNotification);
>>
>> end;
>>
>>
>>
>>
>>
>> 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.
>>
>>
>>
>> hth
>>
>>
>>
>>
>>
>> *From:* delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
>> *On Behalf Of *David O'Brien
>> *Sent:* Friday, 25 February 2011 15:09
>> *To:* NZ Borland Developers Group - Delphi List
>> *Subject:* [DUG] Listview problem
>>
>>
>>
>> I am working on an application (D2009) where I need to know when a
>> TListView is Scrolled.
>>
>> 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:
>>
>>
>>
>> TLVScrollEvent = procedure(Sender: TObject) of object;
>>
>>
>>
>> TICListView = class(TListView)
>>
>> private
>>
>> FOnScroll: TLVScrollEvent;
>>
>> protected
>>
>> Procedure WMVScroll( Var Msg: TMessage ); message WM_VSCROLL;
>>
>> Procedure WMHScroll( Var Msg: TMessage ); message WM_HSCROLL;
>>
>> property OnScroll: TLVScrollEvent read FOnScroll write FOnscroll ;
>>
>> end;
>>
>>
>>
>> procedure Register ;
>>
>>
>>
>> implementation
>>
>>
>>
>> procedure Register;
>>
>> begin
>>
>> RegisterComponents('Dave', [TICListView]);
>>
>> end;
>>
>>
>>
>> procedure TICListView.WMHScroll(var Msg: TMessage);
>>
>> begin
>>
>> OnScroll ;
>>
>> inherited;
>>
>> end;
>>
>>
>>
>> procedure TICListView.WMVScroll(var Msg: TMessage);
>>
>> begin
>>
>> OnScroll ;
>>
>> inherited;
>>
>> end;
>>
>>
>>
>> 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…
>>
>>
>>
>> Anyone have a solution?
>>
>>
>>
>> Regards,
>>
>> Dave.
>>
>>
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
>> unsubscribe
>>
>>
>>
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
>> unsubscribe
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20110225/71e720c0/attachment-0001.html
More information about the Delphi
mailing list