|
Wait. Okay. Everything works. I lost my thought for a few minutes and was thinking about the dialog box instead of the window. I really wanted the window to be on top, which is exactly what Christian showed me.
Thanks,
Kuphryn
|
|
|
|
|
Hello,
Did you discover anything about setfocus event ??
Thanks,
Cris.
|
|
|
|
|
the following code will not compile but can i load the entire contents of a file into a CString? or is there a better way?
int filelen = 0;
CString Cbuf;
......
if(rfile.Open(openfile,CFile::modeRead | CFile::shareDenyWrite,NULL)){
filelen = rfile.GetLength();
if(filelen>0){
rfile.Read(Cbuf,filelen);
........
thank you.
|
|
|
|
|
jafrazee wrote:
but can i load the entire contents of a file into a CString? or is there a better way?
If it's a file of reasonable length, then the answer is you can. But it's not recommended for binary files.
But say you have some kinda textual config file which you want to parse. Nothing wrong in reading it into a CString even if it goes to 10-20 KB
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
if you use the std library, it's very easy to read the entire contents of a file into a string. I show how in my STL series of articles. If CFile won't do the same then it is more pathetic than I thought. Either way, it's generally better to use the std library.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
Bah, there is nothing (for the most part) wrong with CFile. It is just a wrapper for file IO, nothing more. No point in adding 80k of code to you program just to read a simple file. If that is all he needs to do, then CFile will work just fine.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I guess it depends on your POV. I use STL and iostreams a lot, and a lot within the one project. I could not live without the facilities it offers me, which CFile/CArray does not. The average programmer seems blissfully unaware that such facilities exist, and so will suffer CFile when on a large scale project, where the 80k or so that gets added would be of real benefit to them.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
LPTSTR psz = Cbuf .GetBuffer (filelen);
rfile .Read (psz, filelen);
Cbuf .ReleaseBuffer ();
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
thank you.
after reading on stl i really did not want to add that much overhead to my program when i am only reading a file that would be about 5k max.
|
|
|
|
|
How do I get the IP address of the machine running my application within VC++?
Ed
|
|
|
|
|
I got most of my Winsock programming hints from this program though it was designed for Win2K only and uses Winsock 2.0. You do not need Win2K or Winsock 2.0 to do get the IP address and the code below will work. However, here is the link and some of the code from the sample:
http://www.sometips.com/tips/systemmanagement/213.htm
// Here read all IPs of this host
DWORD dwSize = 0 ;
GetIpAddrTable( NULL , &dwSize, FALSE ) ;
PMIB_IPADDRTABLE pIpAddrTable = (PMIB_IPADDRTABLE )new BYTE [ dwSize ] ;
if( pIpAddrTable )
{
if( GetIpAddrTable( (PMIB_IPADDRTABLE)pIpAddrTable, // // buffer for IP table
&dwSize, // size of buffer
FALSE // sort by IP address
) == NO_ERROR )
{
if( pIpAddrTable->dwNumEntries > 2 ) // Second is MS TCP loopback IP ( 127.0.0.1 )
{
m_Multihomed = TRUE ;
char szIP[16];
for( int i = 0 ; i < (int)pIpAddrTable->dwNumEntries ; i++ )
{
in_addr ina ;
ina.S_un.S_addr = pIpAddrTable->table[i].dwAddr ;
char *pIP = inet_ntoa( ina ) ;
strcpy( szIP , pIP ) ;
if( stricmp( szIP , "127.0.0.1" ) )
m_IPArr.Add(pIpAddrTable->table[i].dwAddr) ;
}
}
}
delete [] pIpAddrTable ;
}
|
|
|
|
|
Sorry, here it is with the checkbox on and formatted beter. I got most of my Winsock programming hints from this program though it was designed for Win2K only and uses Winsock 2.0. You do not need Win2K or Winsock 2.0 to do get the IP address and the code below will work. However, here is the link and some of the code from the sample:
http://www.sometips.com/tips/systemmanagement/213.htm
// Here read all IPs of this host
DWORD dwSize = 0 ;
GetIpAddrTable( NULL , &dwSize, FALSE ) ;
PMIB_IPADDRTABLE pIpAddrTable = (PMIB_IPADDRTABLE )new BYTE [ dwSize ] ;
if( pIpAddrTable )
{
if( GetIpAddrTable( (PMIB_IPADDRTABLE)pIpAddrTable, // // buffer for IP table
&dwSize, // size of buffer
FALSE // sort by IP address
) == NO_ERROR )
{
if( pIpAddrTable->dwNumEntries > 2 ) // Second is MS TCP loopback IP ( 127.0.0.1 )
{
m_Multihomed = TRUE ;
char szIP[16];
for( int i = 0 ; i < (int)pIpAddrTable->dwNumEntries ; i++ )
{
in_addr ina ;
ina.S_un.S_addr = pIpAddrTable->table[i].dwAddr ;
char *pIP = inet_ntoa( ina ) ;
strcpy( szIP , pIP ) ;
if( stricmp( szIP , "127.0.0.1" ) )
m_IPArr.Add(pIpAddrTable->table[i].dwAddr) ;
}
}
}
delete [] pIpAddrTable ;
}
|
|
|
|
|
Howdy all,
So I'm trying to decide which STL container would be more appropriate, a multimap or a list. What I need is a storage class which will be holding a lot of objects (maybe 2000?). Each object will have a unique ID. Every time an object is added it's ID will be one larger than the previously added object. Objects will be accessed and removed pretty much at random.
So basically, objects are always added with an incremented ID, but are accessed and removed randomly, in terms of ID.
Now the fact that the object ID is always increasing make me consider a list ordered on ID, so that I could just shove new objects onto the tail without having to look at the storage.
The fact that the objects are random accessed makes me lean towards a multimap<obj_id, object>.
Oh, and it looks like once the storage is initially filled it will stay /fairly/ constant in size, i.e. addition and removals will be fairly even in number.
The main concern here is speed of access, with speed of insertion/removal second, and memory usage a fairly distant third.
Anyone have any insights, suggestions, comments, etc for me
TIA,
Pete
|
|
|
|
|
Objects will be accessed and removed pretty much at random.
This is a big point here. Straight lists perform very poorly on lookup. The list has to be searched sequentially to find the object.
However, for lists, insertions are very fast. So are removals. But when you compare them to maps, lists insert and removals probably are much faster at all.
IMHO, I see little reason to even bother with a list. Just given that you are doing random lookups, you really need something that is fast.
If available in your STL (i.e. STLPort), you might take a look at a hash map. Since your data set is remaining a constant size, you don't have to worry about the re-hash performance hit. As long as your ID's are well distributed, hash maps should perform very fast.
... IMHO
|
|
|
|
|
>>Since your data set is remaining a constant size, you don't
>>have to worry about the re-hash performance hit.
Is this true, even thought the ID's I'll be hashing on are constantly increasing?
Thinking about it, a list is definately not the way to go. As you rightly say, the lookup times for a random element in a list would /not/ be great, and that's my main priority.
I'm using M$'s STL. I'm not sure about a hash map. Is this similar to a map<obj_id, pObjData>? Forgive my ignorance, I haven't used the STL much.
Thanks,
Pete
|
|
|
|
|
It is hash_map <x,y>. You probably don't have it but no big deal. Map should work just fine.
If you did have have_map, ever increasing IDs wouldn't be a problem since the ID (used as the hash value) would be moduloed by a prime number. Thus as far as the hash is concerned, the values just roll over back to 0. But even that isn't something you have to worry about unless (ID % nHashPrime) is poorly distributed. (Which is probably isn't.)
(FYI: That was my response. Was having cookie problems.)
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Ok, well I guess I'll use map, but thanks for the info
|
|
|
|
|
Anonymous wrote:
If available in your STL (i.e. STLPort), you might take a look at a hash map.
hash_map is also available in VS.NET. Also, since you are not storing key and values you may consider a set or a hash_set.
Best regards,
Alexandru Savescu
|
|
|
|
|
stl::map will work for you.
example for map with GUID* (128 bit) key type and BSTR value:
implement GUIDless to compare GUID's
struct GUIDless : public std::less<GUID*>
{
bool operator()(const GUID* _X, const GUID* _Y) const
{
if(((__int64*)_X)[0] < ((__int64*)_Y)[0])
return true;
if(((__int64*)_X)[0] == ((__int64*)_Y)[0])
{
if(((__int64*)_X)[1] < ((__int64*)_Y)[1])
return true;
else
return false;
}
return false;
}
};
declaration of map with( GUID*, BSTR) pair
std::map< GUID* ,BSTR ,GUIDless > mapGUID_BSTR;
soptest
|
|
|
|
|
or do i need to do some assembly programmin gto achieve that?
Thanks
|
|
|
|
|
Read on http://codeguru.earthweb.com/system/ReadSector.html
Papa
Murex Co
|
|
|
|
|
Hi,
do you know some MFC or Win32 function that could help to determine whether the given file is text or binary?
Thanks
R.
|
|
|
|
|
A text file and a binary file are the same... what exactly do you mean by binary and text?
|
|
|
|
|
i have to find some info (words, sentences) in files on the local disk which is meaningless eg for pictures, and executables.
That why I wanna to check beforhand whether it is meaningful to search for my data.
|
|
|
|
|
hmm, you could search for null, i don't think there's null in normal text files.
|
|
|
|
|