CDC 帮助为对象着色

发布于 2024-10-30 23:19:11 字数 1117 浏览 6 评论 0原文

你好 C++ Visual studio 中有一个函数 CDC::ExtFloodFill(int x, int y, COLORREF crColor,UINT nFillType);

我的问题是我们应该写什么来代替

int x , int y, COLORREF crColor, UINT nFillType

就像我有一个我想要着色的对象如何做

enter code here
                 #include "afxwin.h"

    class fr : public CFrameWnd
             {

               public:

CPoint st;
CPoint en;

fr()
{

    Create(0,"First Frame");
}


//////////////////////
void OnLButtonDown(UINT fl,CPoint p )

{
    st.x=p.x;
    st.y=p.y;
}

//////////////////////
void OnLButtonUp(UINT fl,CPoint r)
{

    en.x=r.x;
    en.y=r.y;




    CClientDC d(this);

    d.Ellipse(st.x,st.y,en.x,en.y);

      }
      void OnRButtonDown(UINT fl,CPoint q)
      {
        CClientDC e(this);


    e.ExtFloodFill(............);
      }
    DECLARE_MESSAGE_MAP()
 };
    BEGIN_MESSAGE_MAP(fr,CFrameWnd)
ON_WM_LBUTTONDOWN()
    ON_WM_RBUTTONDOWN()
    END_MESSAGE_MAP()

   class app : public CWinApp
 {


    public:
int InitInstance()
{   

    fr*sal;
    sal=new fr;
    m_pMainWnd=sal;
    sal->ShowWindow(1);

    return true;
}

  };

  app a;

hi
There is a function in C++ Visual studio CDC::ExtFloodFill(int x, int y, COLORREF crColor,UINT nFillType);

my question is that what we suppose to write in place of

int x , int y, COLORREF crColor, UINT nFillType

Like if I have a Object Which I want to Color How to do it

enter code here
                 #include "afxwin.h"

    class fr : public CFrameWnd
             {

               public:

CPoint st;
CPoint en;

fr()
{

    Create(0,"First Frame");
}


//////////////////////
void OnLButtonDown(UINT fl,CPoint p )

{
    st.x=p.x;
    st.y=p.y;
}

//////////////////////
void OnLButtonUp(UINT fl,CPoint r)
{

    en.x=r.x;
    en.y=r.y;




    CClientDC d(this);

    d.Ellipse(st.x,st.y,en.x,en.y);

      }
      void OnRButtonDown(UINT fl,CPoint q)
      {
        CClientDC e(this);


    e.ExtFloodFill(............);
      }
    DECLARE_MESSAGE_MAP()
 };
    BEGIN_MESSAGE_MAP(fr,CFrameWnd)
ON_WM_LBUTTONDOWN()
    ON_WM_RBUTTONDOWN()
    END_MESSAGE_MAP()

   class app : public CWinApp
 {


    public:
int InitInstance()
{   

    fr*sal;
    sal=new fr;
    m_pMainWnd=sal;
    sal->ShowWindow(1);

    return true;
}

  };

  app a;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥醉 2024-11-06 23:19:11

对于您的示例,ExtFloodFill(或 FloodFill 的任何其他版本)实际上并不是正确的选择。

相反,您通常希望将当前画笔设置为您想要的颜色/图案,然后绘制对象(并且它将自动用当前画笔填充)。例如,假设您想绘制一个红色椭圆:

CMyView::OnDraw(CDC *pDC) { 
    CBrush red_brush;

    red_brush.CreateSolidBrush(RGB(255, 0, 0));

    pDC->SelectObject(red_brush);
    pDC->Ellipse(0, 0, 100, 50);
}

编辑:好的,如果您真的坚持它必须是洪水填充,并且您这样做是为了响应按钮点击,你可能会做这样的事情:

void CYourView::OnRButtonDown(UINT nFlags, CPoint point)
{
    CClientDC dc(this);
    CBrush blue_brush;
    blue_brush.CreateSolidBrush(RGB(0, 0, 255));
    dc.SelectObject(blue_brush);
    dc.ExtFloodFill(point.x, point.y, RGB(0, 0,0), FLOODFILLBORDER);
    CView::OnRButtonDown(nFlags, point);
}

For your example, ExtFloodFill (or any other version of FloodFill) isn't really the right choice.

Instead, you normally want to set the current brush to the color/pattern you want, then draw your object (and it'll automatically be filled with the current brush). Let's say, for example, that you want to draw a red ellipse:

CMyView::OnDraw(CDC *pDC) { 
    CBrush red_brush;

    red_brush.CreateSolidBrush(RGB(255, 0, 0));

    pDC->SelectObject(red_brush);
    pDC->Ellipse(0, 0, 100, 50);
}

Edit: Okay, if you really insist it has to be a flood-fill, and you're doing it in response to a button click, you'd probably do something like this:

void CYourView::OnRButtonDown(UINT nFlags, CPoint point)
{
    CClientDC dc(this);
    CBrush blue_brush;
    blue_brush.CreateSolidBrush(RGB(0, 0, 255));
    dc.SelectObject(blue_brush);
    dc.ExtFloodFill(point.x, point.y, RGB(0, 0,0), FLOODFILLBORDER);
    CView::OnRButtonDown(nFlags, point);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文