how use a new class on functions?

how use a new class on functions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class test
{
  
	
  public:
	int a=0;
  	test()
       	{
        	a=10;
	}
};

test test1;


int sum(test a, int b)
{
	return (a.a+b)
}

int main()
{
	int a=sum(test1,20);
	return 0;

} 

i did something like these with my image class, but i get wrong results.
why?
Last edited on
Works fine for me after putting a semi colon on your line 18. return (a.a+b);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>

class test
{
  
	
  public:
	int a=0;
  	test()
       	{
        	a=10;
	}
};

test test1;


int sum(test a, int b)
{
	return (a.a+b);
}

int main()
{
	std::cout << sum(test1,20) << std::endl;
	return 0;

} 
image class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
image& operator= (const image &cSource)
    {
        framecount=cSource.framecount;
        framedelay=cSource.framedelay;
        clrBackColor=cSource.clrBackColor;
        FileName=cSource.FileName;
        imageweight=cSource.imageweight;
        imageheight=cSource.imageheight;
        strfilename=cSource.strfilename;
        btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);
        obj = SelectObject(hdcimage, btBitmap);
        BitBlt(hdcimage,0,0,imageweight,imageheight,cSource.hdcimage,0,0,SRCCOPY);
        return *this;
    }


and now Picture from label class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
void Picture(image imgIcon)
    {
       imgtest=imgIcon;
       if(imgtest.FramesCount>1)
       {
           animation.Interval=imgtest.FrameDelay;
           animation.timerprocedure=[this]()
           {
                static int a;
                a=a+1;

                if(a==imgtest.FramesCount)
                    a=0;
                imgtest.SelectFrame=a;
                //InvalidateRect(hwnd,NULL,TRUE);
                RECT d;
                GetClientRect(hwnd,&d);
                RedrawWindow(hwnd,&d,nullptr,RDW_NOERASE | RDW_FRAME | RDW_INTERNALPAINT | RDW_NOCHILDREN);

           };
           animation.Start();
       }
       else
       {
           animation.Stop();
       }
       if(blnAutoSize==true)
            setAutoSize(true);
        else if(imgtest.FramesCount==0)
            InvalidateRect(hwnd,NULL,FALSE);
    }

why the FramesCount, allways, is zero?
Probably because cSource's framecount is 0?
or not.. i'm using animated gif's.
i changed the image to string and now works fine. but i need use the image instead string
Last edited on
if you need i can share the entire class for you see ;)
but i must do it with a link
i must use the 'const' and the '&' for avoid the object been changed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
image (const image &cSource)
    {
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        framecount=cSource.framecount;
        clrBackColor=cSource.clrBackColor;
        strfilename=cSource.strfilename;
        framedelay =cSource.framedelay;
        imageweight=cSource.imageweight;
        imageheight=cSource.imageheight;
        img=new Image(towstring(strfilename).c_str());
        btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);
        obj = SelectObject(hdcimage, btBitmap);
        BitBlt(hdcimage,0,0,imageweight,imageheight,cSource.hdcimage,0,0,SRCCOPY);
    }

    image& operator= (const image &cSource)
    {
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        framecount=cSource.framecount;
        clrBackColor=cSource.clrBackColor;
        strfilename=cSource.strfilename;
        framedelay =cSource.framedelay;
        imageweight=cSource.imageweight;
        imageheight=cSource.imageheight;
        img=new Image(towstring(strfilename).c_str());
        btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);
        obj = SelectObject(hdcimage, btBitmap);
        BitBlt(hdcimage,0,0,imageweight,imageheight,cSource.hdcimage,0,0,SRCCOPY);
        return *this;
    }

//.........
void Picture(const image &imgIcon)

can i avoid the 'const' and '&'? for string, for exemple, i don't need them
Topic archived. No new replies allowed.