Solved

How to make the panels of a listview flat?

Posted on 2010-09-12
5
571 Views
Last Modified: 2012-05-10
Hi,

I have found code on the internet for making the panels of a listview flat.
But I don't know how to implement it? (what event etc.. etc...)
Can someone show me how? I have put the code in the code-section.

Greetings,

Peter Kiers


const
  LVM_GETHEADER = LVM_FIRST + 31;
var
  hHeader: THandle;
  style: dWord;
begin
  {to get the header handle for the listview}
  hHeader := SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);

  {to get the current style attributes for the header}
  style := GetWindowLong(hHeader, GWL_STYLE);

  {to toggle the HDS_BUTTONS style}
  style := style xor HDS_BUTTONS;

  {to apply the new style}
  SetWindowLong(hHeader, GWL_STYLE, style);

  {to invalidate the listview}
  SetWindowPos(ListView1.Handle, Form1.Handle, 0, 0, 0, 0,
               SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME)
end;

Open in new window

0
Comment
Question by:peterkiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
ID: 33658390
That is ready to use code. Just start it on your form's FormCreate method. If it would not work there, then move it to FormShow method, but implement a simple "execute once" mechanism like that:

TForm1 = class()
 ....  
private
  FShownOnce: boolean;
end;

procedure Tform1.FormShow;
begin
  if not FShownOnce then
  begin
     //call mentioned above code
  end;
  FShownOnce := true;
end;

It will prevent code from executing each time form is shown.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33658407
I what event should i put the code that i have posted.

Peter
0
 
LVL 5

Accepted Solution

by:
Mechanic_Kharkov earned 500 total points
ID: 33658486
In FormCreate.
DoubleClick on form, and Delphi will automatically create template for FormCreate method.
Just put this code there.

You'll get this code

procedure TForm1.FormCreate(Sender: TObject);
const
  LVM_GETHEADER = LVM_FIRST + 31;
var
  hHeader: THandle;
  style: dWord;
begin
  {to get the header handle for the listview}
  hHeader := SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);

  {to get the current style attributes for the header}
  style := GetWindowLong(hHeader, GWL_STYLE);

  {to toggle the HDS_BUTTONS style}
  style := style xor HDS_BUTTONS;

  {to apply the new style}
  SetWindowLong(hHeader, GWL_STYLE, style);

  {to invalidate the listview}
  SetWindowPos(ListView1.Handle, Form1.Handle, 0, 0, 0, 0,
               SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME)
end;

And don't forget to add to your Uses clause CommCtrl (there already is CommCtrls but it is a little different).
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33658506
Perfect, it works great.

Greetings,

Peter Kiers
0
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
ID: 33658531
Thank You too for a nice piece of code, Peter. ;-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Comparing dates in Delphi. Greater than/ Less than 3 368
Create a path if not exists 7 125
scroll down TListBox component in Delphi 1 44
QuickReport, Delphi, Shape 12 47
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

738 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