'How to the width of an existing GDI Pen?

I am working on legacy code that relies on GDI (not GDI+) for drawing. GDI has no provision for variable width pens and you need to create/destroy new ones every time.

Is there any hack that allows to bypass that creation process and directly modify the width of an existing pen ?



Solution 1:[1]

I did not find a way to alter a pen. So the solution I adopted is to keep a permanent pen of with 1 (most often used), and temporarily create a custom one when another width is requested. This at least allows me to mix two different widths without multiple creations/deletions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yves Daoust