cambalinho 142 Practically a Posting Shark

but how can i create a class dirived from other, without redeclare the functions?

cambalinho 142 Practically a Posting Shark

sorry if i mistake something.. now i remember the MFC(98) that i used, with windows messages, i created a new class.
but how these class are done?
because we use what messages we need and not all in class

cambalinho 142 Practically a Posting Shark

my objective is understand that function header, for do the same in C++ ;)

cambalinho 142 Practically a Posting Shark

if the code is cool, try these functions:

COLORREF GetWindowBackColor(HDC WindowDC)
{
    return GetDCBrushColor (WindowDC);
}



void SetWindowBackColor(HDC WindowDC, COLORREF BackColor)
{
    HWND HandleWindow= WindowFromDC(WindowDC);
    RECT WindowClientRectangle;
    GetClientRect(HandleWindow,&WindowClientRectangle);
    SelectObject(WindowDC, GetStockObject(DC_BRUSH)); //selecting the brush
    SetDCBrushColor(WindowDC,BackColor);
    SetDCPenColor(WindowDC,BackColor);
    Rectangle(WindowDC,WindowClientRectangle.left, WindowClientRectangle.top,WindowClientRectangle.right,WindowClientRectangle.bottom);
}

what you think? ;)

cambalinho 142 Practically a Posting Shark

"MFC is not a language; it is a native (unmanaged) class library which is a thin wrapper around the Win32 API."
now see these header function:

void CMyAxUICtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& /*rcInvalid*/)

i belive the CMyAxUICtrl is the instance\object name but it's used outside of main function: can i do these in C++?
(like you see: the OnDraw is used, but imagine that the programmer don't use it)
(sorry if my question is confused... but i'm trying)

cambalinho 142 Practically a Posting Shark

heres my actual code in WM_PAINT message:

case WM_PAINT:
            HDC hdc;
            RECT rect, textrect;
            PAINTSTRUCT a;

            HGDIOBJ original;

            GetClientRect(hwnd,&rect); //getting the actual client rectangle

            hdc=BeginPaint(hwnd,&a); //for getting DC for start using the GDI functions

            original=SelectObject(hdc,GetStockObject(DC_PEN)); //Getting the original pen(i don't know if includes the brush)

            SetBkMode(hdc,TRANSPARENT); //i must put it transparent, or the text will show me it's rectangle backcolor

            SelectObject(hdc, GetStockObject(DC_BRUSH)); //selecting the brush
            SetDCBrushColor(hdc, RGB(0, 0, 255)); //changing the brush color (in these case is the backcolor)

            SelectObject(hdc, GetStockObject(DC_PEN)); //selecting the pen
            SetDCPenColor(hdc,RGB(255,0,0)); // changing the pen color (remember these is the shapes lines and not text\foreground colors

            SetTextColor(hdc,RGB(0,0,255)); //changing the text color

            Rectangle(hdc,rect.left, rect.top,rect.right,rect.bottom); //show us a rectangle with green backcolor (the SetDCBrushColor()), with red line (the SetDCPenColor())

            DrawText(hdc,"hello world\nhi\thello mother\nhello my dog",-1, &textrect, DT_CALCRECT); // getting the text rectangle

            rect.top=rect.bottom/2-textrect.bottom/2; //change is rectangle for show us in vertical center too

            SetTextColor(hdc,RGB(0,255,0)); //changing the text color

            DrawText(hdc,"hello world\nhi\thello mother\nhello my dog",-1, &rect, DT_CENTER | DT_EXPANDTABS); //draw the text

            EndPaint(hwnd,&a); //the BeginPaint() must be ended with EndPaint()

            SelectObject(hdc,original); //i save the original PEN and now i select it

            DeleteObject(original); //the SelectObject() must be deleted with DeleteObject()

            return 0;
  • when we speak about brush is like speak about the background\backcolor;
  • when we speak about the pen is like speak about the shaped lines;
  • so when we use DrawText() the SetTextColor() change the text color, but the SetBkColor() change the the text backcolor and not windows backcolor, that's why:

    SetBkMode(hdc,TRANSPARENT);

for don't show us the text backcolor

cambalinho 142 Practically a Posting Shark

thanks, but can you give me a nice link about SetDCBrushColor() and SetDCPenColor()?
anotherthing: if we use SelectObject(), we must DeleteObject(), right?

cambalinho 142 Practically a Posting Shark

it's a nice thot ;)
but i belive the FillRect(), isn't the same of backcolor, right?

cambalinho 142 Practically a Posting Shark

the

WindowClass.hbrBackground=(HBRUSH) CreateSolidBrush(RGB(0,255,0));

change the all windows backcolor, registed with these class(WindowClasss).
and for change the DC\window backcolor we need use WM_ERASEBKGND or other messages for do it(i don't remember how).
but the SetDCBrushColor() do the job, right? but seems be ignored :(
i'm using it in WM_PAINT messages.
can anyone advice me more for change backcolor?

cambalinho 142 Practically a Posting Shark

problem resolved:
1 - we must get the hdc and the string(with DT_CALRECT flag) rectangle:

RECT rect, textrect;
GetClientRect(hwnd,&rect);
DrawText(hdc,"hello world\nhi\thello mother\nhello my dog",-1, &textrect, DT_CALCRECT);

now we change the top of hdc rectangle(rect):

rect.top=rect.bottom/2-textrect.bottom/2;// remember the rect is, always, less than textrect, or we can get negative values ;)

now we can show the text in vertical center:

DrawText(hdc,"hello world\nhi\thello mother\nhello my dog",-1, &rect, DT_CENTER | DT_EXPANDTABS);

thanks for all

cambalinho 142 Practically a Posting Shark

see these sample:

case WM_PAINT:
            HDC hdc;
            SIZE TextRect;
            RECT rect;
            GetClientRect(hwnd,&rect);
            PAINTSTRUCT a;
            hdc=BeginPaint(hwnd,&a);
            SetBkMode(hdc,TRANSPARENT);
            DrawText(hdc,"hello world\nhi",-1, &rect, DT_CENTER | DT_EXPANDTABS | DT_VCENTER);
            EndPaint(hwnd,&a);
            return 0;

i get the new line and horizontal center, but not the vertical center :(
why?

cambalinho 142 Practically a Posting Shark

yes, but it can't be combined with DT_VCENTER:
"Centers text vertically. This value is used only with the DT_SINGLELINE value."
i read it: msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx

cambalinho 142 Practically a Posting Shark

the DrawText() function is for draw text with a rectangle size.
but if the DT_VCENTER is used with DT_SINGLELINE, how can i use the "\n" and "\t" strings formats?

cambalinho 142 Practically a Posting Shark

thanks.. i did that ;)

cambalinho 142 Practically a Posting Shark

yes i have the C extension that's why i get that warning.
thanks for all. thanks for correct me. thanks for all

cambalinho 142 Practically a Posting Shark

yes... works. but why the double don't accept integers?
my code, give me, only, these warning: command line option '-std=c++11' is valid for C++/ObjC++ but not for C [enabled by default]
nothing more

cambalinho 142 Practically a Posting Shark

see these entire code:

/*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
SCRNSIZE.C −− Displays screen size in a message box
(c) Charles Petzold, 1998
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <string.h>

int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
    TCHAR szBuffer [1024] ;
    va_list pArgList ;

    // The va_start macro (defined in STDARG.H) is usually equivalent to:
    // pArgList = (char *) &szFormat + sizeof (szFormat) ;
    va_start (pArgList, szFormat) ;

    // The last argument to wvsprintf points to the arguments
    _vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR), szFormat, pArgList) ;

    // The va_end macro just zeroes out pArgList for no good reason
    va_end (pArgList) ;

    return MessageBox (NULL, szBuffer, szCaption, 0) ;
}

int MessageBoxF(char *FormatedText,...)
{
    char text[1024];
    va_list ArgumentList;
    va_start (ArgumentList,FormatedText);
    _vsnprintf(text,sizeof (text) / sizeof (char),FormatedText,ArgumentList);
    va_end(ArgumentList);
    return MessageBox(NULL,text,"hi",MB_OK);
}

double average ( double num, ... )
{
  va_list arguments;                     // A place to store the list of arguments
  double sum = 0;

  va_start ( arguments, num );           // Initializing arguments to store all values after num
  int x = 0;
  for ( x = 0; x < num; x++ )        // Loop until all numbers are added
    sum += va_arg ( arguments, double ); // Adds the next value in argument list to sum.
  va_end ( arguments );                  // Cleans up the list

  return sum / num;                      // Returns the average
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
    double a=average(3,10,50,6);
    MessageBoxF("%f",a);
    return 0 ;
}

like you see, i …

cambalinho 142 Practically a Posting Shark

i see i'm doing several errors.

double average ( int num, ... )
{
  va_list arguments;                     // A place to store the list of arguments
  double sum = 0;

  va_start ( arguments, num );           // Initializing arguments to store all values after num
  for ( int x = 0; x < num; x++ )        // Loop until all numbers are added
    sum += va_arg ( arguments, double ); // Adds the next value in argument list to sum.
  va_end ( arguments );                  // Cleans up the list

  return sum / num;                      // Returns the average
}

the num is for tell us how many numbers\arguments are used. that's why my big problem :(

cambalinho 142 Practically a Posting Shark

true... sorry. but even so the for loop isn't correct :(
i'm testing the sum value with prinf and i continue with 0(zero)

cambalinho 142 Practically a Posting Shark

now i change the function and works, but i always get 0 (zero) :(

double MessageBoxSum(double number,...)
{
    double sum=0;
    va_list ArgumentList;
    va_start ( ArgumentList, number );
    int x = 0;
    for ( x=0; x < sum; x++ )
    {
        // Loop until all numbers are added
        sum += va_arg ( ArgumentList, double );
    }
    va_end(ArgumentList);
    char text[1024];
    sprintf(text,"%f",sum);
    return MessageBox(NULL, text,TEXT("hi"),MB_OK);
}
cambalinho 142 Practically a Posting Shark

sorry, you have right.
is these line:

_vscprintf(text,sizeof (text) / sizeof (char),"%f",sum);

but i continue with errors :(

cambalinho 142 Practically a Posting Shark

ok.... thanks
anotherthing: i'm trying understand more the arguments list:

double MessageBoxSum(double number,...)
{
    double sum;
    va_list ArgumentList;
    va_start ( ArgumentList, number );
    int x = 0;
    for ( x=0; x < sum; x++ )
    {
        // Loop until all numbers are added
        sum += va_arg ( ArgumentList, double );
    }
    va_end(ArgumentList);
    char text[1024];
    _vscprintf(text,sizeof (text) / sizeof (char),number,ArgumentList);

   return MessageBox(NULL, text,TEXT("hi"),MB_OK);
}

i get 2 errors:
- warning: passing argument 2 of '_vscprintf' makes pointer from integer without a cast [enabled by default];

  • note: expected 'va_list' but argument is of type 'unsigned int';
  • error: too many arguments to function '_vscprintf'

(these function, for learn, is just add several numbers and show the sum in MessageBox)
but what i'm doing wrong? :(
(some informations are confused and never tell us about these type of errors :( )

cambalinho 142 Practically a Posting Shark

the exemple that you give me is diferent, because uses the for loop... but maybe it's the same.
the _vsntprintf() link isn't working: http://msdn.microsoft.com/en-us/library/1kt27hek.aspx
"_cdecl is the default calling convention for Micosoft Visual Studio. There is no need to explicitly use CDECL."
but why use it? what means?
thanks for correct me. thanks

cambalinho 142 Practically a Posting Shark

i'm learning win32 from Programming Windows Fifth Edition book, but i need ask something about these code:

/*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
SCRNSIZE.C −− Displays screen size in a message box
(c) Charles Petzold, 1998
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/
#include <windows.h>
#include <tchar.h>
#include <stdio.h>

int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
    TCHAR szBuffer [1024] ;
    va_list pArgList ;

    // The va_start macro (defined in STDARG.H) is usually equivalent to:
    // pArgList = (char *) &szFormat + sizeof (szFormat) ;
    va_start (pArgList, szFormat) ;

    // The last argument to wvsprintf points to the arguments
    _vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR), szFormat, pArgList) ;

    // The va_end macro just zeroes out pArgList for no good reason
    va_end (pArgList) ;

    return MessageBox (NULL, szBuffer, szCaption, 0) ;
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
    int cxScreen, cyScreen ;
    cxScreen = GetSystemMetrics (SM_CXSCREEN) ;
    cyScreen = GetSystemMetrics (SM_CYSCREEN) ;
    MessageBoxPrintf (TEXT ("ScrnSize"), TEXT ("The screen is %i pixels wide by %i pixels high."),cxScreen, cyScreen) ;
    return 0 ;
}
  • why using 'CDECL' in MessageBoxPrintf() function declaration? i can ignore it, but why use it?
  • the _vsntprintf(), in 2nd argument, we can use -1, right?(for the function calculate the size automatic)
  • can anyone explain to me how the MessageBoxPrintf() function works? i'm confused between the args 'loop' functions and the return value :(
cambalinho 142 Practically a Posting Shark

i'm using the data control with mask edit box control.
when i click on next button, the mask edit box isn't updated. but why show us the 1st element from data?

cambalinho 142 Practically a Posting Shark

1 question: can i do the copy constructor in my property class or must be inside of property test?

cambalinho 142 Practically a Posting Shark

i have 1 class that have members dependents of the class pointers. when i do the Copy Construtor with assignment operator, how can i use the instance class this, instead copy from 1 instance to another?
i don't want 1 instance member be pointed to another instance

cambalinho 142 Practically a Posting Shark

depending on compiler options... i'm using Code Blocks... honestly it's better than Dev C++ and i had used it before, but by some information, i give up on it (isn't updated and have some errors);)
i'm trying test more your code, but i can't find the solution... maybe another person can help you more.
but why not use '[]' instead '*'? at least your code will be working like a sharm ;)
sorry that i can't help more

cambalinho 142 Practically a Posting Shark

Minimalist: you have right. sorry....
but if you test with:

e.SuppressKeyPress = True

we didn't ear the beep.
sorry if i was rude

cambalinho 142 Practically a Posting Shark

1 - for use getch(), i must include the conio.h ;
2 - you did some mistakes when you inicializade the c-style string:

char str[]="Hello World!!";

heres your code correted:

#include<stdio.h>
#include<conio.h>

int main()
{
    char str[]="Hello World!!";
    puts(str);
    printf("\nEnter a new string: ");
    gets(str); // Is this right ?
    printf("\nString after entering: ");
    puts(str); // And this one ?
    getch();
    return 0;
}

instead use '*', use the '[]'(c strings are 1 array of chars) ;)
i hope these helps you more or someone give you more information

cambalinho 142 Practically a Posting Shark

sorry if i was rude... but i thot the:

e.SuppressKeyPress = True

prevent the key down continues

cambalinho 142 Practically a Posting Shark

Minimalist: i can be mistaked, but i think that you code isn't completed:

 e.SuppressKeyPress = True

i belive these line avoid the enter key continues be pressed.

anotherthing: these line

Me.SelectNextControl(Me.ActiveControl, True, True, True, True)

select the next control by tabindex order.

Reverend Jim: thanks for tell that ;)

cambalinho 142 Practically a Posting Shark

easy:

If e.KeyCode = Keys.Return And e.Alt = False Then
            e.SuppressKeyPress = True
            Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
        End If

why i use the Alt key teste?
imagine that you need put a new line in textbox ;)
anotherthing: use the key down instead keypress... or you can't use some keys

cambalinho 142 Practically a Posting Shark

but you can create instances\objects of structurs, enums, types(int, double...) and others

cambalinho 142 Practically a Posting Shark

anotherthing: don't forget the compiler read everything by order from top to bottom(inclued that header files). for exemple: if you use 1 function before been created, you will get an error that don't exists or something.

"So why shouldn't I put everything in PCHs?"
you can make your own headers files and include their everything that you neeed. then you just need include these header file to your main.cpp file.

cambalinho 142 Practically a Posting Shark

problem resolved... for resolve it, i did a Copy Constructor, but works only between properties and not others class's. so, in class test, i did another constructor and works fine ;)
see the entire code:

//porperty.h
/*
- how use create 1 property with macro:

      PROPERTY(TypeName,PropertyName,getfunction, setfunction)

- never forget to do 1 Copy Constructor inside of class's, that uses the property,
         for avoid copy the 'this' value\adress and use a diferent memory adress
*/

#ifndef PROPERTY_H
#define PROPERTY_H

#include <iostream>
#include <functional>

using namespace std;

template <typename T>
class property
{
private:
    T PropertyValue;
    std::function<T(void)> getf;
    std::function<void(T)> setf;
public:

    property(const T value)
    {
        this->getf=nullptr;
        this->setf=nullptr;
        this->PropertyValue=value;
    };

    property(const property &value)
    {
        PropertyValue=value.PropertyValue;
    };

    property(std::function<T(void)> GetFunction=nullptr,std::function<void(T)> SetFunction=nullptr)
    {
        this->setf=SetFunction;
        this->getf=GetFunction;
    }

    property& operator=(const T &value) const
    {
        if(this->getf==nullptr || this->setf==nullptr)
            this->PropertyValue=value;
        else
            this->setf(value);
        return *this;
    }

    T& operator=(const property &value) const
    {
        if(value.getf==nullptr || value.setf==nullptr)
            return value.PropertyValue;
        else
            return value.getf();
        return *this;
    }

    friend ostream& operator<<(ostream& os, property& dt)
    {
        if(dt.getf==nullptr && dt.setf==nullptr)
            os << dt.PropertyValue;
        else if (dt.getf!=nullptr)
            os << dt.getf();
        return os;
    }

    friend istream& operator>>(istream &input, property &dt)
    {
        input >> dt.PropertyValue;
        if (dt.setf!=nullptr)
            dt.setf(dt.PropertyValue);
        return input;
    }

    friend istream &getline(istream &in, property &dt)
    {
        getline(in, dt.PropertyValue);
        if (dt.setf!=nullptr)
            dt.setf(dt.PropertyValue);
        return in;
    }
};

template<typename T, typename Fnc1_t, typename Fnc2_t, typename classthis>
property<T> GetProperty(Fnc1_t Getter, Fnc2_t Setter, classthis clsthis)
{
    return property<T>(std::bind(Getter, clsthis), std::bind(Setter, clsthis, std::placeholders::_1));
}

#define PROPERTY(TypeName,PropertyName,getfunction, setfunction) \
property<TypeName> PropertyName{std::bind(&getfunction, this),std::bind(&setfunction, this, std::placeholders::_1)}

#endif //PROPERTY_H

//main.cpp
#include <iostream>
#include <sstream>
#include "property.h" …
cambalinho 142 Practically a Posting Shark

"and notifications about new posts are always delayed by up to an hour." they never came. but you said, yesterday, that is if have seen the post(like you said: "before an hour") then i don't need receive the mail notification.
to be honest these is a bad thing :(
sometimes i think that anyone can answer me and then i must refresh the page for sure.
sorry.. i think is a bad thing

cambalinho 142 Practically a Posting Shark

sorry... realy sorry... i will say it in diferent way:
- i'm logined: i don't receive the mail notifications about posts\answers... only about PM(i had tested too, by case);
- i'm log off: i receive mail notifications normaly.

cambalinho 142 Practically a Posting Shark

ok... i only refresh now and i see your answers but not my mails notifications :(
but i bet, that if you answer, tomorrow i will receive an mail notification, because i will be log off...
sorry if i'm, now, only me seen these. if both of you are logined and recive these mail notification, i must test with a normal user... because you are Moderator and Administrator(i don't know... i'm guessing that's why you recieve the mail notifications)

cambalinho 142 Practically a Posting Shark

you posted, but i din't get the notification mail, because i'm logined.
i will trying test more.
have you reciving the mail notification about these post?

cambalinho 142 Practically a Posting Shark

heres the code corrected for give us the text rectangule and more 2(for we never lose 1 or 2 pixles of the letter):

//Getting the DC Font amd select it
            HDC hdc = GetDC(hwnd);
            HFONT hFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
            HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);


            //Getting the
            RECT c = { 0, 0, 0, 0 };

            //Getting the text rectangle from actual caption
            char a[256];
            GetWindowText(this->hwnd,a,256);
            DrawText(hdc, a, strlen(a), &c, DT_CALCRECT | DT_EXPANDTABS);

            //add 2 to the size
            TEXTMETRIC v;
            GetTextMetrics (hdc,&v);
            c.right=c.right+(v.tmAveCharWidth / 2);
            c.bottom=c.bottom+(v.tmAveCharWidth / 2);

            //Clean the Font DC
            ReleaseDC(hwnd,hdc);
            DeleteFont(hOldFont);
            DeleteFont(hFont);

            //Getting the actual styles
            LONG s=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
            LONG g=GetWindowLongPtr(hwnd,GWL_STYLE);

            //change the rectangle size for borders
            AdjustWindowRectEx (&c,g,FALSE,s );

            //Update the control            
            intWidth=c.right-intLeft;
            intHeight=c.bottom-intTop;            
            SetWindowPos(hwnd, 0, 0, 0, c.right, c.bottom,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE |SWP_NOCOPYBITS);

these code is excelent for do autosize of the control... very cool

cambalinho 142 Practically a Posting Shark

when i do:

test b = a;

i copy everything in 'a' to 'b'. even the 'this'...
now i know the problem is my property class.(i did a test just with the class test and works fine).
so the problem is when the compiler copy my property class(assignment operator... maybe overloading property &operator=(property &instancename).
but i need more advices, please.

cambalinho 142 Practically a Posting Shark

i found 1 error with code:

#ifndef PROPERTY_H
#define PROPERTY_H

#include <iostream>
#include <functional>

using namespace std;

template <typename T>
class property
{
private:
    T PropertyValue;
    std::function<T(void)> getf;
    std::function<void(T)> setf;
public:

    property(T value)
    {
        PropertyValue=value;
    };

    property(std::function<T(void)> GetFunction=nullptr,std::function<void(T)> SetFunction=nullptr)
    {
        setf=SetFunction;
        getf=GetFunction;
    }

    property& operator=(T value)
    {
        if(getf==nullptr || setf==nullptr)
            PropertyValue=value;
        else
            setf(value);
        return *this;
    }

    T& operator=(property value)
    {
        if(value.getf==nullptr || value.setf==nullptr)
            return value.PropertyValue;
        else
            return value.getf();
        return *this;
    }


    friend ostream& operator<<(ostream& os, const property& dt)
    {
        if(dt.getf==nullptr && dt.setf==nullptr)
            os << dt.PropertyValue;
        else if (dt.getf!=nullptr)
            os << dt.getf();
        return os;
    }

    friend istream& operator>>(istream &input, property &dt)
    {
        input >> dt.PropertyValue;
        if (dt.setf!=nullptr)
            dt.setf(dt.PropertyValue);
        return input;
    }

    friend istream &getline(istream &in, property &dt)
    {
        getline(in, dt.PropertyValue);
        if (dt.setf!=nullptr)
            dt.setf(dt.PropertyValue);
        return in;
    }
};

template<typename T, typename Fnc1_t, typename Fnc2_t, typename classthis>
property<T> GetProperty(Fnc1_t Getter, Fnc2_t Setter, classthis clsthis)
{
    return property<T>(std::bind(Getter, clsthis), std::bind(Setter, clsthis, std::placeholders::_1));
}

#define PROPERTY(TypeName,PropertyName,getfunction, setfunction) \
property<TypeName> PropertyName{std::bind(&getfunction, this),std::bind(&setfunction, this, std::placeholders::_1)}
#endif //PROPERTY_H

and the main.cpp:

#include <iostream>
#include "property.h"
#include <sstream>

using namespace std;

class test
{
public:
    int x;
    int y;
    int getx()
    {
        return x;
    }
    void setx(int value)
    {
        x=value;
    }
    int gety()
    {
        return y;
    }
    void sety(int value)
    {
        y=value;
    }
    std::string go()
    {
        std::ostringstream out;
        out << '(' << x << ',' << y << ')' << ':' << x + y << '\n';
        return(out.str());
    }
public:

    test()
    {

    }
    PROPERTY(int, X,test::getx, test::setx);
    PROPERTY(int, Y,test::gety, test::sety);
};

int main()
{
    test a;
    cout …
cambalinho 142 Practically a Posting Shark

let me ask anotherthing about these and other macro:

#define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname

using these macro in a class and do:

classobjectname.

members builded by that macro are showed in list, but why not the property macro?
they are both '#define'

cambalinho 142 Practically a Posting Shark

thanks for all

cambalinho 142 Practically a Posting Shark

sorry, but why the macros must be in upper case letters and not like other names?
i like the names like functions or others(that's why i did 'Property')... but the upper case way make easy the programmer see what he is using.
to be honest, i belive the macros are very cool and can avoid us very things to write(sorry it's my opinion).
i don't like very big things for do the same thing, that's why i use macros ;)
i think you remember the other property code, i must use 2 lines of code(1 for constructor and other outside of it)... but, if i can, i love be more simple, and i think these is a nice code for be simple.

thanks for all

cambalinho 142 Practically a Posting Shark

1 question: when i do:

a.

is showed a list of class members. but the Age isn't showed. why isn't showed? it's because is a macro?

cambalinho 142 Practically a Posting Shark

i did that ;)
heres the entire with 1 nice macro:

#include <iostream>
#include <functional>

using namespace std;

template <typename T>
class property
{
private:
    T PropertyValue;
    std::function<T(void)> getf;
    std::function<void(T)> setf;
public:

    property(T value)
    {
        PropertyValue=value;
    };

    property(std::function<T(void)> GetFunction=nullptr,std::function<void(T)> SetFunction=nullptr)
    {
        setf=SetFunction;
        getf=GetFunction;
    }

    property& operator=(T value)
    {
        if(getf==nullptr || setf==nullptr)
            PropertyValue=value;
        else
            setf(value);
        return *this;
    }

    T& operator=(property value)
    {
        if(value.getf==nullptr || value.setf==nullptr)
            return value.PropertyValue;
        else
            return value.getf();
    }

    friend ostream& operator<<(ostream& os, const property& dt)
    {
        if(dt.getf==nullptr && dt.setf==nullptr)
            os << dt.PropertyValue;
        else if (dt.getf!=nullptr)
            os << dt.getf();
        return os;
    }

    friend istream& operator>>(istream &input, property &dt)
    {
        input >> dt.PropertyValue;
        if (dt.setf!=nullptr)
            dt.setf(dt.PropertyValue);
        return input;
    }

    friend istream &getline(istream &in, property &dt)
    {
        getline(in, dt.PropertyValue);
        if (dt.setf!=nullptr)
            dt.setf(dt.PropertyValue);
        return in;
    }
};

#define Property(TypeName,PropertyName,getfunction, setfunction);   property<TypeName> PropertyName{std::bind(&getfunction, this),std::bind(&setfunction, this, std::placeholders::_1)};

class test
{
private:
    int age;
    int getage()
    {
        return age;
    }
    void setage(int value)
    {
        age=value;
    }
public:

    test()
    {

    }
    property<string> Name ;
    Property(int, Age,test::getage, test::setage);

};

test a;

int main()
{
    a.Name="joaquim "  "Miguel";
    a.Age=10+15;
    cout << a.Age << endl;
    cout << "what is your name?\n";
    //getline(cin, a.Name);
    cin >> a.Age;
    cout << "your name is: " << a.Age << endl;
    return 0;
}

see how i declare the Age property and the macro defined.
true that you help me very for fix these code, but what you think about it? and the macro?

cambalinho 142 Practically a Posting Shark

now i did a new test: i was log off and i recive a mail notification.
i hope you see the problem.
thanks for all

cambalinho 142 Practically a Posting Shark

thanks for all... realy.. thanks
for finish i need the property inicialization:
from:

test(): Name(), Age(std::bind(&test::getage, this),std::bind(&test::setage, this, std::placeholders::_1))
    {

    }
    property<string> Name ;//i need be possible inicializate them here
    property<int> Age;

to:

test()
    {

    }
    property<string> Name ;//i need be possible inicializate them here
    property<int> Age(std::bind(&test::getage, this),std::bind(&test::setage, this, std::placeholders::_1));

how can i change that?
i'm using '()', but can be '{}' or other