---------------------------
Microsoft Visual C++
---------------------------
Unhandled exception in Draw.exe (MFC42D.DLL): 0xC00000FD: Stack Overflow.
---------------------------
确定   
---------------------------
今天作了个区域填充函数,结果一测试发现上面的错误,程序如下:
DrawFilling(int x,int y,int fill_color,int boundary_color)
{
    CClientDC dc(this);
    dc.SetROP2(R2_NOT);
    int c;    c=dc.GetPixel(x,y);     if((c!=boundary_color)&&(c!=fill_color))  
{
     //dc.SetPixel(x, y, fill_color); 
     DrawFilling(x, y+1, fill_color, boundary_color);
 DrawFilling(x, y-1, fill_color, boundary_color);
 DrawFilling(x+1,y, fill_color, boundary_color);
     DrawFilling(x-1,y, fill_color, boundary_color);
     
     
}}有好的建议题题啊~~!

解决方案 »

  1.   

    DrawFilling(int x,int y,int fill_color,int boundary_color)
    {
        if(x<0 | x>x最大值 | y<0 | y>y最大值)
            return;
        CClientDC dc(this);
        dc.SetROP2(R2_NOT);
        int c;
      

  2.   

    我晕,你把CClientDC dc(this);也放进第归函数来了?
    你在其他地方定义再传进来。
    DrawFilling(int x,int y,int fill_color,int boundary_color,CClientDC *dc)
    {
        if(x<0 | x>x最大值 | y<0 | y>y最大值)
            return;
        dc->SetROP2(R2_NOT);
        int c;
        c=dc->GetPixel(x,y);     if((c!=boundary_color)&&(c!=fill_color))  
    {
         //dc.SetPixel(x, y, fill_color); 
         DrawFilling(x, y+1, fill_color, boundary_color,dc);
     DrawFilling(x, y-1, fill_color, boundary_color,dc);
     DrawFilling(x+1,y, fill_color, boundary_color,dc);
         DrawFilling(x-1,y, fill_color, boundary_color,dc);
    }}