setlinestyle
This function is used to set current device line style.
void setlinestyle(
const LINESTYLE* pstyle
);
void setlinestyle(
int style,
int thickness = 1,
const DWORD *puserstyle = NULL,
DWORD userstylecount = 0
);
Parameters
pstyle
A pointer to line style LINESTYLE.
style
Draw line style. See remarks for details.
thickness
The width of the line, in pixels.
puserstyle
The user customizes an array of styles, which is valid only if the line type is PS-USERSTYLE.
The first element of the array specifies the length of the drawing line, the second element specifies the length of the blank, the third element specifies the length of the drawing line, the fourth element specifies the length of the blank, and so on.
userstylecount
The number of elements of the user-defined style array.
Return Value
None
Remarks
The parameter style specifies a line style, which consists of a line style, an endpoint style, and a connection style. Can be a combination of one or more classes. Only one style can be specified in the same type.
The line style can be the following value:
Value | Description |
---|---|
PS_SOLID | The line is solid. |
PS_DASH | Line is:------------ |
PS_DOT | Line is:············ |
PS_DASHDOT | Line is:-·-·-·-·-·-· |
PS_DASHDOTDOT | Line is:-··-··-··-·· |
PS_NULL | The line is not visible. |
PS_USERSTYLE | The linear style is user-defined and specified by the parameters puserstyle and userstylecount. |
A macro, PS-STYLE-MASK, is a mask for a line style that allows you to separate a line style from a line style.
The endpoint style can be the following value:
Value | Description |
---|---|
PS_ENDCAP_ROUND | The endpoint is circular. |
PS_ENDCAP_SQUARE | The endpoint is square. |
PS_ENDCAP_FLAT | The endpoint is flat. |
The macro PS-ENDCAP-MASK is the mask of the endpoint style, which allows you to separate the endpoint style from the line style.
The connection style can be the following value:
Value | Description |
---|---|
PS_JOIN_BEVEL | The connection style can be the following value: |
PS_JOIN_MITER | The connection is an oblique connection. |
PS_JOIN_ROUND | The connection is an arc. |
The macro PS-JOIN-MASK is a mask for a connection style that allows you to separate the connection style from the draw style.
The mask macro represents all the bits occupied by the corresponding style group. For example, for a style variable that has mixed multiple styles, you can do this if you want to change the line style only to dot sashes:
style = (style & ~PS_STYLE_MASK) | PS_DASHDOT;
Examples
The following snippet sets the line style as a dotting:
setlinestyle(PS_DASHDOT);
The following snippet sets the line style to a dashed line with a width of 3 pixels and the end point is flat:
setlinestyle(PS_DASH | PS_ENDCAP_FLAT, 3);
The following snippet sets the line style to a solid line with a width of 10 pixels and a bevel at the connection:
setlinestyle(PS_SOLID | PS_JOIN_BEVEL, 10);
The following snippet sets the line style as a custom style (draw 5 pixels, skip 2 pixels, draw 3 pixels, skip 1 pixel...), the endpoint is flat:
DWORD a[4] = {5, 2, 3, 1};
setlinestyle(PS_USERSTYLE | PS_ENDCAP_FLAT, 1, a, 4);