|
What you are experiencing is a warning that you probably have a design problem.
If you are working on objects via pointers to a base class, generally all that the code that uses the base class pointer should care about is the base class interface, irregardless of whether the actual object is of base class or derived type.
The immediate questions that your post brings up are: Why are you using a pointer to a dynamically allocated object here? Is there a better design available?
If you are really stuck with this yucky situation the next questions are: How do I know the what the actual type of object this pointer is pointer to is? What do I do in which case of what derived type it is? Can't I come up with a better design that avoids the mess I may be creating?
The best thing to do would probably be to share the situation & your design goal, so that people can give you advice on other ways of dealing with it.
If all my ranting and raving doesn't dissuade you, then you probably want to look up and familiarize yourself with the C++ dynamic_cast<> operator.
|
|
|
|
|
You are absolutely right Avi and I'm glad you brought this up. This design is typical for simple, graphical elements that are not typically modified (easier to delete and create a new one). However, I extended it to more complex elements that should have the capability to be modified since there is a lot of dialog setup. The real value of the base class implementation is that it allows the use of virtual functions, especially the draw function without which the View class draw routine becomes very complex.
Currently, if the user wants to modify the element(with a dialog), my code deletes it and replaces it with a new element (transparent to the user). The problem arises when the user creates 2 of the same kinds of elements but with different settings. Then, when the dialog corresponding to the element is opened, the dialog settings do not always correspond to the instance that was selected since the dialog will just retain the last settings. So my intent was to set the dialog controls based on the dialog data stored with the element when the dialog init function is called. I can't use a virtual function from CIndicator since there are other elements (besides CInd1) that have different dialogs and thus different set up vars.
There must be an accepted way to design this function, since many engineering tools allow lots of copies of elements to be used yet they can still be modfied. I'll give it some thought.
|
|
|
|
|
I think the (sort of) obvious answer here is that the derived class should generate it's own dialog, i.e.
m_pIndicator->IndDialog();
The IndDialog() function would be a virtual function. This way the class is completely self contained.
Currently the dialog for each element is instantiated in an unrelated class.
|
|
|
|
|
Now that I've gotten back here to look at this again and as far as I understand your situation, it sounds like you've come up with a reasonable plan. You are (obviously) entirely right in not wanting to bring up a dialog displaying the wrong initial data.
In addition, it seems to solve another (potential) problem. I don't know how you are having the user indicate which object to modify, but without something like this, you might have also had a problem determining which dialog to create. Now, at least as I am imagining it, you can hit test to determine what object has responsibility and not additionally need the user to specify the type of thing he wants to deal with. Perhaps this isn't an issue in your current UI, but with design changes, who knows what will come up?
Good luck with this.
|
|
|
|
|
Why not instantiate m_pIndicator to be a CInd1() object? This gives you access to all of the variables and methods in the base (except private) and derived class.
MVP 2010 - are they mad?
|
|
|
|
|
I didn't really state the problem very well -
The whole point of this code is polymorphism to allow one virtual function to be called on the base class for various operations but especially drawing. This way a huge switch statement is avoided every time you want to draw an object (i.e. CInd1, CInd2.. etc.) and you don't have to modify the View class when adding a new object. It seems to be fairly standard - it's described very well in Horton's "Beginning Visual C++".
The downside appears to be the difficulty modifying existing elements but I solve that by a delete and replace operation (transparent to the user). My only difficulty was populating the CInd setup dialog to reflect the selected element but I think I have solved that by instantiating the dialog in the CInd1 class and calling a CIndicator display dialog virtual function.
|
|
|
|
|
Can you add a virtual method to CIndicator that returns the value of CIndicator 's member variables?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thanks all,
I know which element to modify because the CIndicator class has a couple of vars, CString ElementName and int ElementId.
I also realized that I can solve this by casting the pIndicator to the derived class (I had a serious hole in my knowledge with regards to casting pointers of derived classes). Then I think I can add a function to the dialog to update the controls by passing the derived class pointer, ie.
CInd1* pInd1 = static_cast<cind1*>pIndicator); //cast from base to derived class
Ind1Dlg.UpdateDlg(pInd1);
|
|
|
|
|
Hi,
I have developed an installer application in Visual C++ 6.0. It runs in admin login. While it creates program folder, I want to assign specific rights. The rights I want to assign are as under.
Everybody should be allowed for Modify + Read & Execute + List folder content + Read + Write.
On advance security tab, "Apply to" field for Everybody should be set to "This folder, subfolders and files". In addition "Apply these permissions to objects and/or containers within this container only" tick box shoud be checked.
Right now, the code I have used for this is,
--------------------------------------------------------------
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE);
SetSecurityDescriptorGroup(&sd,NULL, FALSE );
SetSecurityDescriptorSacl(&sd, FALSE, NULL, FALSE );
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = TRUE;
CreateDirectory( m_strDestinationDir, &sa );
--------------------------------------------------------------
This gives full control to Everybody but does not have setting on Advance tab as I mentioned above. Due to that files created by one user in this folder becomes unaccessible for another user.
I will be very much thankful if someone can help me out to resolve this problem.
Thanks & Regards,
Chintan.
C.R.Naik
|
|
|
|
|
Hello folks!
Do you know of any good guide about writing a shell replacement for windows in VC++? I tried to google around but i didn't find anything usefull really, maybe i am not looking for the right terms...i tried to search here on CP too of course but no luck...so if any of you knows where to look or at least what i should search for, please give suggestions, thanks a lot in advance.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
It all depends on what you want your replacement to do. If you mean a complete replacement of Windows then you have about 500 years of development ahead of you. If you mean just one small part then perhaps you could expand on your requirements.
MVP 2010 - are they mad?
|
|
|
|
|
Thanks for the answer. Of course i know that writing a complete replacement that can do at least what explorer.exe can do and more is not a one man job, or a one man job for the coming 2 centuries. But i have no such ambitious plans, i am just after learning something new, to expand my knowledge, see what could be possible and what not.
Richard MacCutchan wrote: If you mean just one small part then perhaps you could expand on your requirements.
-i don't understand what you mean by expanding requirements, i probably lack the "proper english" here...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Code-o-mat wrote: -i don't understand what you mean by expanding requirements,
Well your original question was "Do you know of any good guide about writing a shell replacement for windows in VC++". So what do you mean by a Shell replacement? What do you expect your version to do? You might like to take a look at some of the open source projects around to see what they offer and whether reading some of that code will help you.
MVP 2010 - are they mad?
|
|
|
|
|
i think Saurabh.Garg (here's his post[^]) got it right, i am/was looking for some general guide, something that would explain exactly what tasks a replacement for the graphical shell has to fullfill, i mean from the system's point of view, not the user's, i guess it isn't simply just replacing explorer.exe with something else (changing the registry entry that points windows at explorer.exe to make it run some other program instead upon logon) and done, i read on some forum that the shell has to perform some special initializations in order to work (and of course these were not listed). Looking thorough those codes is a good idea, it might be very hard though to understand it without any basic idea of what exactly the intent of the whole thing is...hmm, they however might have comments in the code that might be very usefull and shed a lot of light onto the whole thing, thanks.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Code-o-mat wrote: i think Saurabh.Garg (here's his post[^]) got it right
Strange, that's what I said!
MVP 2010 - are they mad?
|
|
|
|
|
You mean a replacement for explorer.exe? Take a look at qmmander[^] - not an instruction, but at least it is open source.
|
|
|
|
|
Thanks for the answer, however, i am not exactly after yet another file commander program (althorough qmmander does look interesting ), i would just like to learn a bit about how windows' graphical shell ticks and how one would go about replacing it with something else, i just feel like experimenting some (probably on a virtual windows install).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
|
Hi,
Sorry for intruding on this thread, but I'm following it with interest.
Your list gives only alternative shells for the older OS's.
I would be most interested in an alternative shell for Vista and Win7, mainly one that will roll back the security settings and look and feel to something similar to Windows XP.
Regards
Bram van Kampen
|
|
|
|
|
You can always change Win7 to use Windows Classic and turn off UAC.
|
|
|
|
|
Hi,
Thanks.
Well, to tell you the truth, I have not even tried Windows 7 yet. All our customers are running on either Win98, or Win XP. We tried to run on Vista, that was a disaster, even with UAC turned off. Maybe Win7 is better.
I am preparing an article about the larger issues at hand for applications which are not cutting edge technology driven, and could survive live quite well with older technology.
Licencing terms and MS Monopoly will be the main issue there.
Regards,
Bram van Kampen
|
|
|
|
|
Thank you.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I don't think there is a general guide like one you are seeking. You should list the features you want in your shell and if during implementation you encounter problems I am sure people here can help you out.
-Saurabh
|
|
|
|
|
Thanks for the reply, i don't have any specific plans for it (yet), currently i am only curious about the means and hows of doing such a project, the basic idea of it all, what such a replacement has to do to work with the system from the point of the system itself, now really from the point of the user, for example i read on some forum that the shell has to perform certain initializations (these were of course not listed) in order to work right, so i guess it isn't just a simply replacing a program (explorer.exe) with anything else...oh well, i guess as Richard MacCutchan suggested[^], i will have to study some opensource projects.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Hi,
I am beginner to VC++. Now I want to develop an application where window divided into two parts. left side i am having tree view and right side display information.
I already implemented tree view using SDI application (CTreeView).
Now I want to implement a tree in CFormView. How can i write a tree implementation in CForm View.
Please suggest me the solution. Also If you have any references related to this please send me.
Thanks in advance........
To invent something, you need a mountain of junk in your mind.
---------------------Thomas alva edison
|
|
|
|