|
|
In addition to the Naughter article, here is another resource:
http://flounder.com/nomultiples.htm
|
|
|
|
|
Are you trying to limit to only one instance or do you want to limit to some other number?
John
|
|
|
|
|
I would like to run only one instance of my application at anytime.
With Thanks & Regards
--Kamesh
|
|
|
|
|
|
the problem I have is this:
I have a superclass called Figure, then 2 inherited classes from this: Circle and Rectangle. Circle have a variable called Radius and Rectangle 2 variables called Length and Height. all this variables are public.
if I declare an array of pointers like this:
Figure *obj[100];
and then I put in a loop for example:
obj[i] = new Circle;
How can I access to the variable Radius from this array?
for example: obj[i]->radius
it seems like the compiler doesn´t know then that obj[i] is a Circle, it just knows it´s a Figure.
Hope you can help me, thanks in advance!
|
|
|
|
|
This is what dynamic_cast was invented for:
Circle* pC=dynamic_cast<Circle *>(obj[i]);
if(pC!=0){
}
else{
...
} For dynamic_cast to work, it is necessary that Figure has at least one virtual member function. If there is none so far, make the destructor virtual, which is probably a good idea anyway:
class Figure
{
...
virtual ~Figure(){}
}; Good luck. To know more about dynamic casting, take a look at (for instance) Marshall Cline's excellent C++ FAQ Lite[^].
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
while dynamic_cast is proper C++ option, many windows programmers prefer not to use it for performance reasons (you have to compile with RTTI etc.)
To solve your problem you might use virtual functions
class Figure
{
...
virtual int Radius() const {return 0;}
...
};
class Circle : public Figure
{
...
virtual int Radius() const {return m_radius;}
...
};
class Rectangle: public Figure
{
... //no changes
};
|
|
|
|
|
I think that an object of a derived class can be referenced by a pointer to the parent class, in which case instead of writing
obj[i] = new Circle;
you should write
obj[i] = (Figure *)new Circle;
This makes the obj array hold pointers to Figure, and both Circle and Rectangle can be referenced.
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
The old-fashioned way (not typesafe, but no performance hit) is to typecast the code this as:
int x = ((Circle *)obj[i])->radius;
|
|
|
|
|
a user about my freeware program:
"After performing any calculation, and then after closing DeskCalc SE it locks out the computer from opening up any other program, including DeskCalc SE. If I just open DeskCalc SE, and then close it without performing any calculations it causes no problems. Only when I perform calculations does it prevent me from opening any further programs, including DeskCalc SE. A reboot is the only way to solve this problem."
well this has happend now a few times with win98/2000/XP, and i cant simulate it on
my computers. i spend many hours to find the problem, but i'am giving up now, maybe sombody of you can help me with this strange problem.
|
|
|
|
|
Threads not being terminated ? A Hook which hooks too much ?
~RaGE();
|
|
|
|
|
i use no threads in this program, but i use keyboard hooks, is it possible that key_events can couse this problems. cause one user told me that if he has this problem and is pressing "ESC" afterwards the problem is solved ?
|
|
|
|
|
Hello,
do you know a method how to slow down the network connection of a computer (LAN and internet)? I know that such tools exist but I haven't found any source code on how it's done...
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
I've developed a SDI application using the SwitchToView method
described in:
http://www.codeproject.com/docview/switchingviews.asp?target=switchtoview
I've also follewed articles infos to create View classes to
supply to SwitchToView method.
My problem is the following:
windows messages are only sent to Default View class.
When I switch to another View, this class doesn't receive
any windows messages.
How can I solve this problem ?
Thanks a lot!
|
|
|
|
|
Hi,
I've created two diaglogs with one dialog(child) in transparent modeless mode. (kinda like a picture overlayed onto the background) However, when i try to set the modeless dialog with SetLayeredWindowAttributes it creates another process(like another application running) is there anyway to get ride of this?
|
|
|
|
|
hi,
I want to make a prg to check whenever an application end to writes data to a
file (.txt), so i can open it afterwards.
I tried the (_access) but it didn't worked...
any suggestion?
Many thanks in advance
Aenaos
|
|
|
|
|
You want to know when another application has ended, right? If you created an instance of this other application using CreateProcess(), then you'll want to use WaitForSingleObject().
|
|
|
|
|
It is an external application. It runs on background continusly...
When it receives data from a third application it writes them to a file,
the only thing I can check is whenever this application will stop writting the data to a specific text file. Nothing else.
Have you any suggestion?
Aenaos
|
|
|
|
|
What application? Are you referring to a program that checks the status of a file?
What "application end?"
Kuphryn
|
|
|
|
|
Sounds like the writer program needs to set an Event and the monitoring program can WaitForSingleObject on that Event.
|
|
|
|
|
Hi, I'm writing a function which will create a copy of a tree. The traversal code for source tree is fine, but there is some problem assigning parent node in the destination tree. Please Help!!
extern const CTreeCtrl* m_pSourceTree;
CTreeCtrl m_DestTree;
HTREEITEM m_hDest;
TreeTraverse(m_pSourceTree->GetRootItem());
TREEITEM CKleenCachePage::TreeTraverse(HTREEITEM hStart)
{
HTREEITEM theItem;
if ( hStart == NULL )
return NULL;
if( m_pSourceTree->GetParentItem(hStart) == NULL)
m_hDest= NodeCopy(hStart,NULL);
if ((theItem = m_DestTree.GetChildItem(hStart)) != NULL)
{
m_hDest = NodeCopy(theItem,m_hDest);
theItem = TreeTraverse(theItem);
if (theItem != NULL)
return theItem;
}
if ((theItem = m_DestTree.GetNextSiblingItem(hStart)) != NULL)
{
m_hDest = NodeCopy(theItem,m_hDest);
theItem = TreeTraverse(theItem);
if (theItem != NULL)
return theItem;
}
return theItem;
}
<BR>
HTREEITEM CKleenCachePage::NodeCopy(HTREEITEM hSource, HTREEITEM hDest)
{
int nImage = 0, nSelectedImage = 0;
CString csText = m_pSourceTree->GetItemText(hSource);
m_pSourceTree->GetItemImage(hSource,nImage, nSelectedImage);
return m_DestTree.InsertItem(csText,nImage,nSelectedImage,hDest,TVI_LAST);
}
|
|
|
|
|
I want to build executable with shared MFC dlls to reduce the final size.
But VS7 link my exe file with shared mfc70.dll which is not available on default win98.
So I think I need to link my exe against mfc42.dll which is available on most systems.
What I should gonna do?
|
|
|
|
|
The usual thing to do is distribute the DLL along with your program. It's simple to do if you're packing everything into an intallation executable.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you. But in my situation the final size is critical. The aplication is just a some free add-on to some other application. So all should be kept in one executable and size should be no more then 100kB.
|
|
|
|