Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • Last Modified:

500 points for - Get message in ListView component

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
gshep
Asked:
gshep
  • 10
  • 9
2 Solutions
 
LRHGuyCommented:
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
 
gshepAuthor Commented:
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
 
gshepAuthor Commented:
oops, should be

type
tLV=class(tListView)
  procedure WndProc(var Msg: TMessage);   override;
end;
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
gshepAuthor Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
gshepAuthor Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
gshepAuthor Commented:
nope, didn't work either
0
 
gshepAuthor Commented:
this looks like it's an impossible task - yes?
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
mmm...nothing is impossible.....just wait a little....looking for a working solution
0
 
gshepAuthor Commented:
thanks
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
gshepAuthor Commented:
nope - that didn't work either.

Would the ListView being in report view have anything to do with it?
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
gshepAuthor Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
> 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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
gshepAuthor Commented:
>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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Thanks for the points :)
Glad to have helped you :)

F68 ;-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now