Recent

Author Topic: How to change PolyLine colour?  (Read 3646 times)

JoshM

  • Jr. Member
  • **
  • Posts: 57
How to change PolyLine colour?
« on: January 02, 2014, 09:37:46 pm »
I'm using the function:

function Polyline(DC: HDC; var Points; Count: Integer): BOOL; external 'gdi32' name 'Polyline';

Using the Canvas.Pen.Color code doesn't work, as (I think) the function I'm using a built-in Windows one, and not a Pascal/Lazarus one. Does anyone know how I could change the colour of the PolyLine, or where I could go about getting this info?

Here's the code I've got, with comments to explain what I want:

Code: [Select]

procedure TNewPageControl.PaintWindow(DC: HDC);
begin
  inherited PaintWindow(DC);
  //set colour = black
  PolyLine(DC, Points, PointNum);
  //set colour = red
  PolyLine(DC, VerVec, PointNumVec);
  //set colour = green
  PolyLine(DC, HorVec, PointNumVec);
end;
         


Thanks.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to change PolyLine colour?
« Reply #1 on: January 02, 2014, 10:20:06 pm »
You use a valid canvas (of a form or other control), setting its Pen/Brush colour as desired, and then pass
Code: [Select]
canvas.Handle
as the first parameter to Polyline(...);

You probably don't need to call PaintWindow() at all.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to change PolyLine colour?
« Reply #2 on: January 02, 2014, 10:23:08 pm »
Canvas.Polyline is not good enough? In short you have to make sure that the dc has everything setup before you try do anything. Try saving the canvas.handle in to a local variable that will force the canvas to set up the dc correctly for you, using its internal brush, pen and font classes. In case that you want to avoid using the canvas all together then you need to use createpen, createbrush etc after that you call the SelectObject function to let the dc know which pen and brush you want to use and then you draw your polyline.

Reference :http://msdn.microsoft.com/en-us/library/windows/desktop/dd162957%28v=vs.85%29.aspx
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018