Solved

500 points for - Get message in ListView component

Posted on 2004-09-20
20
474 Views
Last Modified: 2012-05-05
Hi all

I am making a component derived from a TListView and all is working well so far.  My problem is that i now want to grab any messages that are sent to the ListView and process them.  I am especially looking on how to get the scrollbar messages so i can stop them being shown.

I am using Delphi 4 Professional

My question is:

Does anyone have some code sample that will allow me to hook the messages within the component i am making?
0
Comment
Question by:gshep
  • 10
  • 9
20 Comments
 
LVL 7

Assisted Solution

by:LRHGuy
LRHGuy earned 250 total points
ID: 12109145
There are probably several ways to do it.

One, you can override the WndProc procedure:

type
  tLV=class(tListView)
    procedure WndProc(var Message: TMessage);
      override;
  end;

Procedure WndProc;
begin
  { trap any messages based on Message.Msg code }
  inherited; {call (or not) the inherited handler)}
end;

or, you could trap specific messages:

tLV=class(tListView)
    procedure WMHScroll(var Message: TWMHScroll);
      message WM_HSCROLL;
end;

and then handle it yourself.
0
 

Author Comment

by:gshep
ID: 12109247
LRHGuy - capturing the WM_HSCROLL message doesn't seem to stop the scrollbar from appearing - any ideas why the horizontal scrollbar always appears?

Im using this

type
 tLV=class(tListView)
   procedure WndProc(var Message: TMessage);
     override;
 end;

Procedure WndProc;

{ trap any messages based on Message.Msg code }
   With Msg do
             Case Msg of

             WM_HSCROLL : ShowScrollBar(self.Handle, SB_HORZ, false);



             else
               inherited; {call (or not) the inherited handler)}
             end;

end;

0
 

Author Comment

by:gshep
ID: 12109337
oops, should be

type
tLV=class(tListView)
  procedure WndProc(var Msg: TMessage);   override;
end;
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12109801
The WM_HSCROLL Msg is sent when a scroll event occurs. This means that the scrollbar is already painted and visible....

You should trap the WM_CTLCOLORSCROLLBAR or the WM_Paint of the listview itself....

 

From SDK help:
The WM_CTLCOLORSCROLLBAR message is sent to the parent window of a scroll bar control when the control is about to be drawn. By responding to this message, the parent window can use the given display context handle to set the background color of the scroll bar control.

WM_CTLCOLORSCROLLBAR  
hdcSB  = (HDC) wParam;   // handle of scroll-bar display context
hwndSB = (HWND) lParam;  // handle of scroll bar
0
 

Author Comment

by:gshep
ID: 12109897
ah, now i see why the scrollbars still appeared.

I have no idea how to use WM_CTLCOLORSCROLLBAR  or WM_PAINT - well, safely that is.

I assume there is no easy way to stop a ListView from displaying the scroll bars?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12110134
use simply

Procedure TLV.WndProc(var Msg: TMessage);
begin
   If Msg.Msg = WM_Paint then
      ShowScrollBar(self.Handle, SB_HORZ, false)
   else
      inherited;
end;
0
 

Author Comment

by:gshep
ID: 12110436
Nope - that made things go really weird.

I thought it might be because it was in design mode so changed the code to:

If (Msg.Msg = WM_Paint) and not (csDesigning in ComponentState)  then...

But when i compiled and ran the program, the ListView was blank and the CPU usage went through the roof
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12110485
change it to
Procedure TLV.WndProc(var Msg: TMessage);
begin
inherited;
   If Msg.Msg = WM_Paint then
      ShowScrollBar(self.Handle, SB_HORZ, false);
end;
0
 

Author Comment

by:gshep
ID: 12110593
nope, didn't work either
0
 

Author Comment

by:gshep
ID: 12110597
this looks like it's an impossible task - yes?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12110610
mmm...nothing is impossible.....just wait a little....looking for a working solution
0
 

Author Comment

by:gshep
ID: 12110678
thanks
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 250 total points
ID: 12110857
well, this should do the trick....
It traps the calcsize message and just removes the Horz scrollbar from the control style before to redraw it

type
  Tlistview1 = Class(Tlistview)
  private
    { Private declarations }
    procedure WMNCCalcSize(var msg: TMessage); message WM_NCCALCSIZE; //during the paint
  protected
    { Protected declarations }
  public
    { Public declarations }
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
   RegisterComponents('ExEx', [Tlistview1]);
end;

constructor Tlistview1.Create(AOwner: TComponent);
begin
      inherited Create(AOwner);
end;

destructor Tlistview1.Destroy;
begin
      inherited Destroy;
end;
Procedure Tlistview1.WMNCCalcSize(var msg: TMessage);
var
  style: Integer;
begin
  style := getWindowLong( handle, GWL_STYLE ); //let's get the style
  if (style and WS_HSCROLL) <> 0 then //if it wawnt to add the HScrollBar
      SetWindowLong( handle, GWL_STYLE, style and not WS_HSCROLL );  //we simply remove it
   inherited;
end;

F68 ;-)
0
 

Author Comment

by:gshep
ID: 12110960
nope - that didn't work either.

Would the ListView being in report view have anything to do with it?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12111004
For me is working in every viewstyle: the horizontal scrollbar is never showed!

Are you tolking about the Horizontal only or both the bars?

in case of both just do:

Procedure Tlistview1.WMNCCalcSize(var msg: TMessage);
var
  style: Integer;
begin
  style := getWindowLong( handle, GWL_STYLE ); //let's get the style
  if (style and WS_HSCROLL) <> 0 then //if it wawnt to add the HScrollBar
      SetWindowLong( handle, GWL_STYLE, style and not WS_HSCROLL );  //we simply remove it
  if (style and WS_VSCROLL) <> 0 then
      SetWindowLong( handle, GWL_STYLE, style and not WS_VSCROLL );
   inherited;
end;


I repeat: for me it's working fine!
0
 

Author Comment

by:gshep
ID: 12111139
nope, that didn't work either - But thank you very much for trying.

Something tells me that Delphi 4 professional is missing something since you are able to do it.

So i think i'll drop the idea and not waste your valuable time.

I'm going to up the points to the 500 as promised.

Will it be ok if i split some points with you and LRHGuy?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12111171
> Something tells me that Delphi 4 professional...
Sorry, i've forgotten about that. Yes, i'm using D6 so it can be for that....

BTW if you haven't got a workable answer by me you don't need to accept my comments :)

And about the split you are able to do whatever you want, for me everything is ok :)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12111200
Just in addition: i've found that the WMNCCalcSize proc was added in controls.pas since D3 and D4...
Try doing a search there to see how it's declared (maybe some differences in Style)....

F68 ;-)
0
 

Author Comment

by:gshep
ID: 12111374
>BTW if you haven't got a workable answer by me you don't need to accept my comments
But you did a lot of work trying to help so you deserve it

>Just in addition: i've found that the WMNCCalcSize proc was added in controls.pas since D3 and D4...
>Try doing a search there to see how it's declared (maybe some differences in Style)....

Thanks for the tip - i'll give it a shot.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12111459
Thanks for the points :)
Glad to have helped you :)

F68 ;-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now