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
Solved

How to make the panels of a listview flat?

Posted on 2010-09-12
5
557 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 221
Show Listview image from database (String field) 5 135
HTML text in the body of an email (delphi code) 12 167
MS Access from Delphi 31 60
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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