Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


dynamic pen (change color on fly)

Posted on 1999-07-21
Medium Priority
Last Modified: 2013-11-20
Good morning everyone,

I try to find a way in MFC to change the color of a pen dynamically on fly basing on the pixels of the screen (such as hightlighting, etc).  Here is my question:

      Can the color of a pen be changed dynamically according to a logical function based on pixel color of the source and destination at the time the graphics is drawn?

In X window,  this can be done easily by XCreateGC(...) in which one of the argument values provides a way to to logical function such as (exclusive OR) between source pixel (generated by graphics request)  and destination pixel (existing pixel value-current contents of screen) to create a new pixel value (new contents of screen).

example:  XOR

        source                       10001110
        destination                  11001001
         -----------                -----------
         new                         01000111

So basing on this capability, one can manupilate the logical function to produce the drawing(such as a line ) with has a  desired color over a dark or  a white area accordingly.

Please tell me if this can be done in MFC or direct me to any source that may help.   Thank you very much.

Question by:tpnguyen
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
LVL 23

Accepted Solution

naveenkohli earned 800 total points
ID: 1310913
You can do the same thing in MFC too...
Use SetROP2 (nDrawMode) memeber function of CDC. In the draw mode you can specify the logic you want DC to use when doing the drawing like


You can read the documentation on this function for the meaning of this draw options....

Here is piece of code from my application where i was trying to draw the backgound in highlight color..

pDC->SetTextColor (RGB (255, 255, 255));
                  bkBrush.CreateSysColorBrush (COLOR_HIGHLIGHT);
                  pDC->SetROP2 (R2_NOT);

Author Comment

ID: 1310915
Thank you very much.

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

704 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