Solved

How to make the panels of a listview flat?

Posted on 2010-09-12
5
530 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Perfect, it works great.

Greetings,

Peter Kiers
0
 
LVL 5

Expert Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

11 Experts available now in Live!

Get 1:1 Help Now