|
-
May 18th, 2002, 10:00 PM
#1
Thread Starter
PowerPoster
Doing something when a variable is changed
I have a CGButton class again and then I have four variables (left, top, width, height). When the user changes any of these variables, I want to move the button using API. Is it even possible or will I have to use a function like "Move", "Resize", or something else?
-
May 19th, 2002, 05:42 AM
#2
Frenzied Member
You can do it with MoveWindow I guess, look it up at MSDN...
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
May 19th, 2002, 03:24 PM
#3
Frenzied Member
Make sure you use Properties rather than just a public variable...
than you should be fine...
you know how to call MoveWindow right, so make a property like this:
PHP Code:
property void set_Left (int value){
//MoveWindow with the new value of Left
}
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
May 19th, 2002, 03:57 PM
#4
Thread Starter
PowerPoster
The keyword "property" doesn't exist.
-
May 19th, 2002, 05:44 PM
#5
Monday Morning Lunatic
__declspec(property) comes into it somewhere.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 19th, 2002, 05:56 PM
#6
You should make a class with get_variable(value) and set_variable(value).
The problem with __declspec(property) is that it is MSVC specific, and thus not portable.
You can use this macro, to make the code portable (and make it look a little more ugly):
Code:
#include <iostream>
// The PPLG macro allows you to
// make public memember variables
// with custom get/let functions
#define PPLG(TYPE, VARNAME) \
private: \
class VARNAME{ \
public: \
inline TYPE operator = (TYPE param) {return let(param);} \
inline operator TYPE () {return get();}; \
private: \
TYPE val; \
TYPE let (TYPE param); \
TYPE get (); \
}; \
public: \
VARNAME VARNAME;
// A test class
class a{
public:
PPLG(int,b); //We have a member 'b', of type int
};
// The get & let functions
int a::b::get(){
return val;
}
int a::b::let(int param){
std::cout << "Variable set to " << param << std::endl;
return val=param;
}
// A sample main function
int main(){
a test_a;
test_a.b = 10;
test_a.b = test_a.b + 1;
return 0;
}
-
May 19th, 2002, 06:02 PM
#7
Monday Morning Lunatic
I always found my preferred method (non-declspec) to be:
Code:
class test {
public:
inline test() : m_propname(0) { }
inline int propname() const { return m_propname; }
void propname(int pn) { m_propname = pn; }
private:
int m_propname;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 19th, 2002, 06:17 PM
#8
parksie: Something like that is probably better. My macro-using solution was only to show that it's posible to do it. It will make the program harder to understand, since it uses sub-classes hidden away in macros.
-
May 19th, 2002, 06:21 PM
#9
Monday Morning Lunatic
Anything is possible Whether you should do it is another matter 
I think macros are "discouraged" in C++ for the reasons you gave.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 19th, 2002, 09:28 PM
#10
Thread Starter
PowerPoster
Ok thanks. I guess I'll the use the method of set_property or get_property because it's pretty straight forward.
-
May 20th, 2002, 05:58 AM
#11
Frenzied Member
hmm I suggest Parksie's way to do it... that looks almost like a property...
the thing I suggested was for Managed C++ (.NET), I didn't realize it was the Managed version... don't use it
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|