Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CreatePen , how to change color

Posted on 1997-06-01
2
Medium Priority
?
418 Views
Last Modified: 2013-12-03
When i create a pen like CreatePen () , how do i do to change that pens color later ??
using bwc++ 4.02
Write a simple example.
0
Comment
Question by:superabbe
[X]
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
2 Comments
 
LVL 2

Accepted Solution

by:
r parkinson earned 150 total points
ID: 1397781
There is no way to change a pen once it is created, however you can accive a similar effect if you use CreatePenIndirect, which takes a structure, and just modify the color parameter (hence maintaining the other attributes).  You can then 'switch' pens with the code :

// Create the first Pen.
hPen=SelectObject(hdc,CreateFontIndirect(&lgpn));

// Change a property of the pen here ...

//create a new pen, select the font to your DC and
//delete the previous pen.  
DeleteObject(SelectObject(hdc,CreateFontIndirect(&lgpn)));

//Delete the selected pen and replace it to the DC with the
//default pen.
DeleteObject(SelectObject(hdc,hPen));

0
 

Author Comment

by:superabbe
ID: 1397782
In my program the pen will change color when WM_MOUSEMOVE occur .
Is it possible that my GDI-res will be way out of control ??
like 1 % left or so ?
.

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 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