|
If your compiler has RTTI, you can use dynamic_cast, typeid and type_info.
VC does, if you have RTTI enabled.
"In an organization, each person rises to the level of his own incompetence." Peter's Principle
|
|
|
|
|
Is there an API function to query the available com ports on the system.
Thanks
|
|
|
|
|
I don't think so. I usually check the registry like so:
set<CString> Ports;
HKEY hSerialComm=0;
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM",0,KEY_READ,&hSerialComm)==ERROR_SUCCESS||(hSerialComm=0);
DWORD nValues,nLongestName,nLargestValue;
if (hSerialComm && ::RegQueryInfoKey(hSerialComm,0,0,0,0,0,0,&nValues,&nLongestName,&nLargestValue,0,0)==ERROR_SUCCESS && nValues && nLongestName && nLargestValue)
{
CString _Name,_Value;
char* Name=_Name.GetBuffer(nLongestName+1);
char* Value=_Value.GetBuffer(nLargestValue+1);
DWORD NameLen,ValueLen,Type;
for (int i=0;nValues;++i)
{
NameLen=nLongestName+1;
ValueLen=nLargestValue+1;
LONG Result=::RegEnumValue(hSerialComm,i,Name,&NameLen,0,&Type,(BYTE*)Value,&ValueLen);
if (Result==ERROR_NO_MORE_ITEMS)
break;
else if (Result!=ERROR_SUCCESS)
{
break;
}
else
{
--nValues;
if (Ports.find(Value)==Ports.end())
Ports.insert(Value);
}
}
_Name.ReleaseBuffer(0);
_Value.ReleaseBuffer(0);
}
if (hSerialComm)
RegCloseKey(hSerialComm);
Additionally, I will simply just try to open the first few
ports by typical name. (e.g. COM1 ... COM8)
|
|
|
|
|
Hi, all...
==========
Can anyone write a function that returns a list of explorer HWNDs ??
for example:
I have 4 winodows running ....
1- "my computer" (HWND= 0x00AA)
2- "c:\folder1\folder2\" (HWND= 0x00BB)
3- app1 (HWND= 0x00CC)
4- app2 (HWND= 0x00DD)
How can I scan all the HWNDs and identify
explorer windows (HWNDs: 0x00AA & 0x00BB in the example)???
Thanks in advance
|
|
|
|
|
You can enumerate all toplevel windows with EnumWindows and check window class with a call to GetClassName for each HWND you get. You'd have to check Explorer windows class name in Spy++. I'm not sure this name remains unchanged between Win9x/NT/2K/XP.
Your other option is searching for process started by explorer.exe, getting its PID and checking the PID for each HWND with GetWindowThreadProcessId. The problem with this approach is that there's no single process enumeration API working across all 32 bit Windows platforms.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
This is the code I used in one of my apps:
EnumWindows(IEEnumProc, 0);
and the enum proc:
BOOL CALLBACK IEEnumProc(HWND hWnd, LPARAM lParam)
{
char szClass[256];
GetClassName(hWnd,szClass,256);
if(strcmp(szClass,"IEFrame") == 0)
{
}
return TRUE;
}
regards
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
But he's after Windows Explorer, not IE. Class name is 'CabinetWClass', at least on my XP box.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
yes, you're right. It must be CabinetWClass instead of IEFrame .
I thought he wants to find IE windows, not explorer windows
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Gregor S. wrote:
I thought he wants to find IE windows, not explorer windows
Confess, you are fixed on IE
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
I'm using Mozilla
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Explorer also uses 'ExploreWClass' as a class name when it displays the folder tree by default.
people are not very wise / don't know their limitations /
don't know what death means / when they play their dirty games 'Killing Fields' Funker Vogt
|
|
|
|
|
|
i am writing an adventure in vc++6. the problem is, ive include a .ini file, with the possible words that a user could enter. when the user enters a command in the game (at the prompt) the program "scans" this file to see if any words match. the problem lies with the [ ] 's in the .ini file
e.g
[nouns]
1 chair
2 school
etc
so i have used the continue statement to "skip" the headings ([nouns] and so on) the prolem with this is when a user types in a "known" command, the program outputs "Do not recognise command" (its set to do this if the words input arent in the .ini file)
any ideas?
Sas
|
|
|
|
|
Post your code; you have a bug. Just show us the loop that processes comands. remember to wrap the code in <PRE> ... </PRE> tags please.
Signature space for rent. Apply by email to....
|
|
|
|
|
I recomand using
http://www.codeproject.com/cpp/ciniex.asp
or http://www.codeproject.com/cpp/ciniex.asp for ini file acess.
But ur method should work, probably a bug!
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
You should use the GetPrivateProfile* API functions for reading INIs.
"In an organization, each person rises to the level of his own incompetence." Peter's Principle
|
|
|
|
|
I strongly suggest prereading the INI file and putting the words into a CMap.
|
|
|
|
|
Another question about inheritance on operators (such as =):
does it have to apply two object of the same type/class exactly OR can I assign (i.e. '=') an object to another of a sibling class?
Example:
class Base
{
public:
Base& operator = (Base&);
};
class DerivedA
{
public:
DerivedA& operator = (DerivedA&);
};
class DerivedB
{
public:
DerivedB& operator = (DerivedB&);
};
Can I do something like:
DerivedA a;
DerivedB b;
a = b;
?
The reason I m asking is because, I may "exchange" some data fields of object "a" with some of object "b" (actually the data fields shared in Base class!)
Thanks again,
bertrand
|
|
|
|
|
You'd have to provide the following in DerivedA:
DerivedA& operator=(const DerivedB &);
BTW: use const references for arguments of operator =. The right-hand-side object doesn't change when you assign its value.
Also, remember that '=' token (not operator= member function) is used when creating object:
DerivedB b;
DerivedA a = b;
In the case above, the constructor accepting 'const DerivedB&' would be used.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Curious as to why you wont use :
Base* a = new DerivedA
Base* b = new DerivedB.
If the data is defined in base (which it should be) then *a = *b should work. Correct me if I am wrong. (its been so long since i have written any real code....sigh!!!!)
|
|
|
|
|
Ranjan Banerji wrote:
If the data is defined in base (which it should be)
I find this statement strange. Why would you limit yourself in such way? Often it's the other way round - you define base class as abstract interface (all pure virtual functions, no data members) and provide implementation in derived class[es].
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
I agree with you completely. I did not intend to impose such a limitation. However, I do prefer data to be at a lower level (closer to base) class rather than a derived class at the end of the hierarchy. So as much as a base class provides the interface I also like it to provide data. Of course this can vary depending on the design requirements.
If each derived class has its own data defined then to a large extent we loose the benefits of inheritance. Now one may argue that a certain design requires a base class for interface only and not data and that is fine too.
Now if you look at the example provided in this dicussion we were talking about creating an operator= for Derived A and B. If the contents of B are to be assigned to A then I suppose it was fair on my part to assume that they both contain the same data and therefore I would hope that the data was defined in Base.
|
|
|
|
|
Ranjan Banerji wrote:
If each derived class has its own data defined then to a large extent we loose the benefits of inheritance
It depends. If you have a common set of data which can be used by all derived classes, then by all means place then in base class. However, this is quite rare. Usually your derived classes represent different entities which share part of the implementation (including data members) and add their own stuff.
Take the proverbial example with shape hierarchy. You could place 'color' attribute in the base class (assuming that each shape has exactly one color), but surely you won't add 'center' there, because it would be used by cirle, but not by polygon.
Going back to the operator= example - I think it's easy way to shoot yourself in the foot. If you want to copy you should provide the operator= or other method, otherwise adding new members to derived classes will break the program.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Now you are making me respond just for the sake of this discussion .
There is always a design option available for those real life cases, such that data is represented at a lower level, though not necessarily at the abstract base class level.
Taking the shape example one could could have the BaseShape class from which which one could derive single color classes and other color classes etc. From which you derive the various shapes etc.
Now this may be overkill, but there is almost (keyword is almost) always a design solution available.
|
|
|
|
|
I don't see your point. You've started with cast to base class and call to operator= which probably cause slicing. Then you argue that it's viable option, because if you don't store the data in base class then you'll lose the advantages of inheritance.
The approach you propose is IMHO dangerous and applicable in rare case when derived classes differ only in their behavior (do not introduce data members). This rare case can exist for a while in given project, but it's trivial to break it by adding data member(s) to derived class. The program will still compile, but it won't work correctly anymore.
So I can't any advantage of using *a=*b where a and b are cast from derived to base.
Ranjan Banerji wrote:
Taking the shape example one could could have the BaseShape class from which which one could derive single color classes and other color classes etc. From which you derive the various shapes etc
Would you cast to BaseShape and use operator= then?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|