|
I do have one more question, though: What does SetDecimals do in your implementation?
Thanks in Advance
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
It is only used to set the number of decimal places that will be displayed for the ticks label. so, it is not important here.
-- modified at 8:43 Wednesday 26th April, 2006
OT: I'm currently working on an article. Soon, I will share this control on codeproject.
|
|
|
|
|
I'm sorry if the title is a bit off, but what I'm looking for none of my books talk about.
I have a simple shell of a project where I have defined a set of pure virtual functions. Now from what I know to use a class that is derived from the abstract class, you must know the derived class name.
Example:
VirtualTime *pTime;
ptime = new Clock;
So Clock implements all the virtual functions defined in VirtualTime. Straight forward, nothing tricky, ANSI C++ stuff.
Here's my delima. In the code above you must know that "Clock" class exists in the project. This presents a problem when the user specifies the class derived from the abstarct class during runtime.
The obvious solution is to add a simple switch/case logic and list out all the known derived classes. However this is ugly and requires more work for little gain for the developer. What I want is the developer to code up the class implementing the vrtual functions, add the files to the source code base, then compile/link, and then run. No need to add the class name to some internal library of derived classes.
Example:
Developer codes up Clock, Watch, and Timer in three seperate class files. There is no need to change any other code. Then at runtime the user specifies the Watch class and the pTime pointer instaniates the Watch class.
I've read up on dynamic casting, but the problem is you still need to know the derived object name. As with any casting from the articles that I have read.
So I'm looking for a way to dynamically instantiate unknown classes, validate the class exists at runtime, and that the validated class is indeed derived from my virtual function class.
No need to post code (unless you have it handy and feel generous). Links to articles or Google search terms to send me on my way would be appreciated greatly.
|
|
|
|
|
|
I used a technique like that for one of my project, here is how it works (sorry, I don't have any link). You'll have to create a factory class that will manage the construction of the derived classes. This factory is basically a wrapper class around a map (the map link the name or the id of the inherited class and a function that is responsible of the creation of the class). So, when you want to create a class, you call a function from your factory (specifying the name or id, or...) of your class. The factory will then search in the map for the corresponding entry in the map and call the creation function (which is not part of the factory) and return the new instance.
So, as you can see, with this mechanism, you get rid of the switch logic.
Now, of course, your classes need to be registered with the factory. For that, in your factory add a method to register a class, by supplying the name or id of the class and a pointer to the creating function of the class (to keep it OO, this function can be a static function of your class). Like that, your objects can be registered in your factory, and be used anywhere in the code very easily.
The last point is really to register automatically these classes at the program start-up. To do that, you can use a little trick: define a static variable that is initialized by calling a function. This function will be responsible of registering your classes (static variables are evaluated before main gets called):
static int Var = RegisterMyClass();
The RegisterMyClass function will register the class in the factory.
So, in summary, what you have to provide when you want to add a new class: the class itself with a creation function (basically a simple new CMyClass), a function that will register the class (will simply call the Register of the factory and supply the class name and a pointer to the creation function) and a static variable that will only be used to register the class in the factory.
You can use a name to identify the class but you can also use an Id, it's up to you to decide what's the best option.
I hope this is clear. If not, don't hesitate to ask.
|
|
|
|
|
I know of no way to accomplish this in C++, without COM, GUIDs and the like, but that could get ugly real fast. I think you're stuck with writing a class factory (google that) of some kind.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Hi All
Infact I learned from the page
http://www.sysinternals.com/Informa...plications.html
that applications can be run while booting by using native appliocations, here having one problem is that how to build a native application.
So please guide me to build the native application, I have windows 200
Professional .
Please guide me.
Thanks.
|
|
|
|
|
any executable program can be run automatically while booting - not limited to "native app" (what does "native app" mean?).
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|
|
It is an application that uses The Native API[^]. Win32 sits on top of a "Native API". Programs like "chkdsk" which run before the system has fully booted use this API. To a large degree Win32 is implemented in terms of this API so it is more fundamental. For example the Win32 function CreateFile is really a wrapper around the Native API NtCreateFile function.
Steve
|
|
|
|
|
I think you need the DDK to build native apps, but it's been a long time since I tinkered with that kind of thing.
Steve
|
|
|
|
|
This is the first time I write a program after learning C++ for 1 week ago.
I use Dev-C++ and I want my program to do function such as:
Ask person to type two number : 1st number ; 2nd number.
such as: 2 ; 5;
and I want my program to get me the sum : 2 + 3 + 4 + 5 = 14
but I try many times and it always gives me : 2 + 5 = 7
This is my code :
using namespace std;
#include <iostream>
long result(long d , long e)
{
if (d >= 1 , d < e)
{
return (result(d + 1,0));
}
else
return (0);
}
int main()
{
long a,b;
long c;
cout << "1st number : ";
cin >> a;
cout << "2nd number : ";
cin >> b;
c = a + result(a , b) + b;
cout << c;
return 0;
}
Can someone tell what 's wrong with my code, and give me a hint to do it.
Thankz.
|
|
|
|
|
simply write -
int main()
{
long a,b;
long c = 0;
cout << "1st number : ";
cin >> a;
cout << "2nd number : ";
cin >> b;
for (int i = a; i <= b; ++i)
c += i;
cout << c;
return 0;
}
your result() function is wrong which always returns zero.
Manish Agarwal
manish.k.agarwal @ gmail DOT com
|
|
|
|
|
can you tell me why it is wrong and if i follow my way then what is the solution ?
By the way, thank you for your reply. This is my first time, seem that i have a lot of work to do.
|
|
|
|
|
long result(long d , long e)
{
if (d >= 1 , d < e)
{
return (result(d + 1,0));
}
else
return (0);
}
this function is wrong because
result(d + 1,0) = 0 bacause d+1 > 0
if you replace e for 0: result(d + 1,0)->result(d + 1,e), this function still wrong because
result(d,e)=result(d+1,e)=.....=result(e,e)=0
-----------------
conglt
|
|
|
|
|
if (d >= 1 , d < e) is legal syntax, but doesn't do what you want. Use && for "and" in boolean tests.
Look at your exit condition of result() - it only ever returns 0. Recursion is something you should really save for later, when you have more experience with the language.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
long result(long d , long e)
{
if (d >= 1 , d <= e)
{
return d + result(d+1,e);
}
else
return (0);
}
Instead of calling
c = a + result(a , b) + b;
only call
c = result(a,b);
Evaluation of recursive call is -
return 2 + result(2+1,5);
return 2 + 3 + result(3+1,5);
return 2 + 3 + 4 + result(4+1,5);
return 2 + 3 + 4 + 5 + result(6,5);
After if condition became false evaluation is
return 2 + 3 + 4 + 5 + 0;
return 2 + 3 + 4 + 5 ;
return 2 + 3 + 9;
return 2 + 12 ;
return 14 ;
In your code
long result(long d , long e)
{
if (d >= 1 , d < e)// After first iteration e became 0 and condition false and return 0;
{
return (result(d + 1,0));
}
else
return (0);
}
c = a+ result(a,b) + b = 2 + 0 + 5
Write recursive function carefully.
Regards
Amar
|
|
|
|
|
are you student from Viet Nam ???
In your program :
you see again if statement:
if (d >= 1 , d < e)//or (d>=1 && d
|
|
|
|
|
Thankz for all your reply.
I know my problem now.
|
|
|
|
|
I am using the BackColor function, and all the documentation I have seen indicates that you have to let the user choose the color. I am wondering if there is a way to specify which color is used without the user choosing a color?
Thanks
|
|
|
|
|
I'm not sure what "BackColor" function you're referring to or what parameter type it expects, but if it takes a COLORREF, you can make any color with the RGB macro or use any system colors with the GetSysColor() function.
COLORREF clr = RGB(255, 0, 0); // bright red
COLORREF clrWindow = ::GetSysColor(COLOR_WINDOW);
You might also need to use OleTranslateColor, if you're doing COM/OLE_COLOR related stuff.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Tried what you mentioned and it created many more problems that it solved.
The program began acting up and creating many errors with the MessageBox::Show function I am using.
Anyways, on second thought this should have gone in the managed forum but...
I am doing a System::Windows::Forms project, and changing the backcolor with this->BackColor . I have only found ways to let the user selectively change the color, but I would like to specify the color change myself. Do you know of a way to do this?
|
|
|
|
|
Ahh, yeah, the code I mentioned probably wouldn't work in .NET, it's Win32 api.
I think you might need to look up the System::Drawing::Color class and do something like:
BackColor = Color::Red; (or whatever your color choice)
I'm not a .net expert, so hopefully the Color class has a constructor like Color(R, G, B) if you need to do an arbitrary color.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Steve Echols wrote: I think you might need to look up the System::Drawing::Color class and do something like:
BackColor = Color::Red; (or whatever your color choice)
Thanks. That worked.
|
|
|
|
|
Hello
I have a little problem with my app.
I can double click on the assotiated file type (*.app) an the MainFraim of my Prog is started. But to display the information in the file there should also be a ChildFrame opened. And this doesn't happen!
Now how to add this function ?
And/od how to debug this (if Possible)?
THX
|
|
|
|
|
it is ur responsbility to open the file clicked.
check command-line of CWinApp then open a new Doc for the file.
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|