Solved

How to make the panels of a listview flat?

Posted on 2010-09-12
5
564 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
  • 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
URL for downloading Google Chrome for Win XP 2 232
how to send memory stream from ics Client To ics server ? 11 174
Performance of SQL statement 37 137
Broadcast a message using ICS 2 20
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…
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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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