Drawing Complex Polygons

Posted on 2006-04-11
Last Modified: 2013-11-20

I have an application on Pocket PC running Microsoft Mobile 2003, developed using Embedded Visual C++ 3.0.

I need to draw a few complex polygons (Polygons with 'holes' in them) over a black and white bitmap on a device context.

In normal windows I would use FillRegion() after CreatePolyPolygonRegion(), or set the Polygon fill mode using SetPolyFillMode().

Unfortunately both these methods are unavailable in Windows CE.

Can anyone suggest a simple alternative?

Thanks in advance,

Question by:Attack_Trax
    1 Comment
    LVL 1

    Accepted Solution

    You can do it manually as following:
    - Create a buffer whose width and height are equal or more than the polygon
    - Fill the buffer with  the following recursion
    CRect rect(buffer.width, buffer.height)
      For (int mX=rect.left;mX<rect.right;++mX)
        CPoint point(mX,mY);
        if (point is Inside the polygon)
              Fill this point with the correspoding pixel of bitmap
             Fill it with some color different from black and white (e.g red)
    Once you finished preparing buffer, you just need to draw it on the device context.
     For (int mX=rect.left;mX<rect.right;++mX)
        CPoint point(mX,mY);
        if (pixel is red)
               do nothing
        else // pixel color is the same as bitmap color
              draw on Device context

    With this method, you can draw as many polygons as you like. You just need to compute the buffer once after user changed polygon's size.
    Hope it useful!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Title # Comments Views Activity
    function returning CString in a regular win32 DLL 8 133
    repeateFront java challenge 31 80
    Window placement 17 56
    mapBully challenge 6 53
    Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    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.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now