|
Does anybody knows how to open a txt file and display the results in a Listbox or edit box. The txt file contains 6 to 8 lines.
Any help will be greatly ppreciated
|
|
|
|
|
1. Take a look at CFile and CArchive in order to easily read the contents of the file.
2. ListBox: Create a var for the ListBox using the class wizard (Ctrl + W) and use Listbox.AddString this should do the thing.
3. EditBox: Create a var for the editctrl it can be a CString and then you can use that CString to modify the content of the control; read about UpdateData(); if you want, you can also declare a var of type CEditCtrl (control type in the class wizard) and then use controlvar.SetWindowText("...)...
Hope this helps...
|
|
|
|
|
Hi. I have a CMapWordToPtr object, the pointers in the CMap point to CStringArray.
The problem is, when i want to empty the cmap i don't free the memory. By MS documentation CStringArray::RemoveAt or RemoveALL should be enough, but it doesn't seem to work:
--------------------------
CMapWordToPtr *MyMap
...blablabla...
int size,i;
word key:
CStringArray *MyArray;
void *temp;
POSITION p=MyMap->GetStartPosition();
while(p){
MyMap->GetNextAssoc(p,key,temp);
MyArray= (CStringArray) temp;
size=MyArray->GetSize();
for(i=0;i<size;i++){
myarray-="">RemoveAt(0);
MyArray->FreeExtra();
}
}
MyMap->RemoveAll();
...blablabla
--------------------------
It's a major memory leak, I've tried a lot of ways and only managed to bang my head to the wall.
|
|
|
|
|
RemoveAll doesn't delete what the pointer points to. You need to go through and call "delete" on everything you called "new" on.
|
|
|
|
|
Heyas all,
Newbie Windows programmer here, I'm attempting to run an external batch file from within my console app like so:
ShellExecute(NULL, "open", "s:\\dir\\file.bat",NULL, NULL, SW_SHOWNORMAL);
The program works perfectly testing it locally, but when I run it on the target machine, the program runs but fails to run the specified batch file. s:\ is a mapped network drive.
Anyone have an info that may help me? Anything is greatly appreciated.
Thanks!
Digital Khaos
"Diplomacy is dead. Feel my wrath!"
|
|
|
|
|
Try to use WinExec( filename, SW_SHOW ) [check the parameters]. It's easier to use this until you learn how to use ShellExecute.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
Check the return value!
I would not recommend you to use WinExec() becuse it is an old API for 16 bit system.
Rickard Andersson8
Here is my card, contact me later!
UIN: 50302279
E-Mail: nikado@pc.nu
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
How are you confirming that the batch file indeed did not run? Why are you not checking the return value of ShellExecute()?
As much as the S: drive has to be mapped on the other machine, so does the file.bat file need to exist.
HINSTANCE hInstance;
if (_access("s:\\dir\\file.bat", 0) == 0)
hInstance = ShellExecute(NULL, "open", "s:\\dir\\file.bat", NULL, NULL, SW_SHOWNORMAL);
To get more detailed information, you might consider using ShellExecuteEx().
|
|
|
|
|
Dear all,
I need to use an array of Book pointers (BookList) and Member (MemberList). Both of them are compound (container) classes.
The component objects are books and members (up to 10)for each list respectively. Is the below implementation of the array.h file correct?
#ifndef _ARRAY
#define _ARRAY
const int MAX_VALUE=10;
template<class Object>
class Array
{
public:
Array(int maximum=10);
~Array();
......
private:
Object* array_list[MAX_VALUE];
//To keep track of the elements into the list.
int num_of_elements;
};
#endif
Regards,
grscot
|
|
|
|
|
It looks OK, but does it compile? If it compiles, the rest is a matter of making sure it has no bugs, which the debugger will help you determine.
Now, as far as what I would do if I were you, I'd try to use a container class from one of the available libraries, be it MFC or STL. STL is more sophisticated and portable, but also more difficult for beginners. MFC is simpler and better documented. So take your pick:
MFC: typedef CTypedPtrArray<CPtrArray, Book> BookList;
STL: typedef vector< auto_ptr<Book> > BookList;
Regards,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
Thanks a lot
Alvaro Mendez
Regards,
grscot
|
|
|
|
|
std::vector s of auto_ptr s are a no-no. There are tons of articles explaining why this is not safe --briefly put, STL assumes objects inside a container have standard copy semantics, which auto_ptr s do not have.
Instead, one can use boost::shared_ptr (see www.boost.org[^]).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Wow, I had no idea.
Could you point me to one of those articles you mention? I mean, I'd like to see under what circumstances a vector of auto_ptrs does not work as expected, so that I can steer clear of such scenarios. The auto_ptr class has a simple and straightforward copy constructor/assignment operator; it's hard to imagine that it wouldn't work as expected under typical usage.
Thanks,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
|
Microsoft Access has an option where you can compact a database and I would like to do that with ADO. There is a function in CDaoWorkspace that can do that but I am using ADO in my application. Does anyone know how implement this compact option with ADO?
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
I want to write a CdialogBar like in AutoCad 2002. So if the DiologBar is dock to the top or button it should use the window width automaticlly. In the DiolagBar there are other object, that should also resized when it's docked.
by(t)E
sändy
|
|
|
|
|
Ok. I have a regular dll that calls an MFC extension. I know - an old thing but I got new complication (new for me at least). So I have that export from the extension with CDynLinkLibrary in it to add extension to the resource chain of the regular, right?
And I call it only once and everything is just fine UNTIL I create my own new worker thread in the extension using _beginthreadex . This thread can't find resources of the extension in which it was created - now what? Anybody have any ideas?
Thanks a lot in advance!
|
|
|
|
|
This is part of faq
add infront every function that accessing resources in dll.
AFX_MANAGE_STATE(AfxGetModuleState());
|
|
|
|
|
I know about faqs and I know about this basic stuff. I'm not that dumb. Eveybody knows it.
But the thing you are refering to is about regular dlls, right? But but but but but....
Please reread my post. The problem is NOT in regular dll it is in the extension dll that is used by regular dll. AND it is not a part of a call from regualr dll - it is in a thread that was started by EXTENSION dll.
|
|
|
|
|
Hi @all,
maybe a simple question to most of you, but I never did this before while coding...
What's the easiest and best way to copy all files inside a folder to a target device (e.g. drive D: )? And what classes or functions do you use? MFC stuff is welcome!
Thx a lot!
Stefan
When I was young my mother told me to clean up my room, I told her -1!
|
|
|
|
|
One solution is to loop through all files inside a directory via FindFirstFile() and FindNextFile() and then call MoveFile() and/or CopyFile().
Kuphryn
|
|
|
|
|
Use the SHFileOperation function for easy copying.
|
|
|
|
|
_Theo_ wrote:
Use the SHFileOperation function for easy copying
Great. That's exactly I was looking for... Thanks!
When I was young my mother told me to clean up my room, I told her -1!
|
|
|
|
|
How do I detect end of file using CFile..
e.g CFile infile;
while( ???????????????? )
{
// do something
}
Thanks.
|
|
|
|
|
See the documentation of CFile::Read() . If its return value is less than the amount of bytes requested, you've reached EOF. This method can also throw a CFileException , whose m_cause member contains the cause of the exception. Compare it with CFileException::endOfFile to check for attempts to read past EOF.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|