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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

627 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