|
|
That example uses MFC which I am not using in this program, also what I want to do is ownerdraw the internal scrollbar itself, I don't want to superimpose a new scrollbar control over top of the listbox. Isn't there a way to set the listbox's scrollbar to ownerdraw and handle that?
KR
|
|
|
|
|
|
Thanks, I was able to find what I needed in that article.
KR
|
|
|
|
|
OK everyone, heres the deal.
i have the following code written.
what this program is supposed to do is read from a file "program6.txt".
in that file are lines of text in the following format:
"0 Jack Simpson 330 Maple Overton MO 64155"
the number preceeding the name ranges from 0-2, with 0 meaning that line is student info, 1 meaning teacher info, and 2 meaning staff info.
after reading from the file, the program is supposed to write all students to one text file, all teachers to another, and all staff to another. (creating 3 text files).
i have the program to where it can read in the information, and it determines the classification of each person, and even creates the output files, however, it does not place the information into those text files.
i cannot figure out why.
any help would be greatly appreciated
Zak
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void readFile(int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip);
void printStudent(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip);
void printTeacher(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip);
void printStaff(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip);
int main ()
{
int type, zip, houseNum;
string fName, lName, street, city, state;
readFile(type, fName, lName, houseNum, street, city, state, zip);
system("PAUSE");
return 0;
};
void readFile(int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip)
{
ifstream fin;
ofstream fout;
int count=0;
fin.open("program6.txt");
if(!fin)
{
cerr << "Error: file could not be opened" << endl;
system("PAUSE");
exit(1);
}
if(fin)
{
cout << "FILE OPENED" << endl;
}
do{
fin >> type >> fName >> lName >> houseNum >> street >> city >> state >> zip;
count++;
cout << count << endl;
if(type==0)
{
printStudent(count, type, fName, lName, houseNum, street, city, state, zip);
}
else if (type == 1)
{
printTeacher(count, type, fName, lName, houseNum, street, city, state, zip);
}
else if (type==2)
{
printStaff(count, type, fName, lName, houseNum, street, city, state, zip);
}
}while(!fin.eof());
fin.close();
fout.close();
cout << "End-of-file reached.." << endl;
system("PAUSE");
}
void printStudent(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip)
{
ofstream fout;
fout << "Students: " << endl << "First Name Last Name House Number Street"
<< " City State Zip" << endl;
fout.open("students.txt",ios::app);
fout << fName << lName << houseNum << street << city << state << zip << endl;
fout.close();
}
void printTeacher(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip)
{
ofstream fout;
fout << "Teachers: " << endl << "First Name Last Name House Number Street"
<< " City State Zip" << endl;
fout.open("teachers.txt",ios::app);
fout << fName << lName << houseNum << street << city << state << zip << endl;
fout.close();
}
void printStaff(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip)
{
ofstream fout;
fout << "Staff: " << endl << "First Name Last Name House Number Street"
<< " City State Zip" << endl;
fout.open ("staff.txt",ios::app);
fout << fName << lName << houseNum << street << city << state << zip << endl;
fout.close();
}
</iomanip></string></fstream></iostream>
|
|
|
|
|
I'm no expert at C++ (MASM is my choice), BUT:
You have to do this once for each file at the same time you open the input file - remove the // comment:
Zak Forlow wrote: //fout.open ("students.txt",ios::app);
You don't want to open and close each time - open all of them once at the beginning and close all of them once when all done:
Zak Forlow wrote: fout.open("students.txt",ios::app);
Zak Forlow wrote: fout.close();
You also may need to Create the three files instead of just opening them.
I may be totally wrong, but that is what I'd try.
Dave.
|
|
|
|
|
Zak Forlow wrote: however, it does not place the information into those text files.
Most likely because each time the printXXX() function is called, the file is overwritten. Try adding ios::nocreate to the open() call.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Two thread access a std::list object, either of two will add to/(delete) the std::list.
When make critical section or mutex guard, I know can make the std::list safe.
But does std::list itself implemented thread-safe?
Thanks advanced for helping unlock my mind!
|
|
|
|
|
You failed to mention which implementation of STL you are using as there are several available. These include SGI-STL, STLPort, Dinkumware and other minor vendors. There are some slight differences in how each handle concurrency. With that being said, the C++ standards do not make any guarantees about thread safety with iterator reading/writing to std::list from multiple threads. This essentially means that it is up to the software engineer to ensure thread-safety.
Best Wishes,
-David Delaune
|
|
|
|
|
Really thank you. You do me a big favor!
|
|
|
|
|
Hi,
I got this linking error trying to build a project using GLUI in VisualStudio2005 on a WinXP media center SP2 machine:
warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
All the needed .dll, .lib, .h files are in the correct folders.
The libraries glui32.lib, glut32.lib, etc etc are correctly linked in the project properties.
As shown in http://www.codeproject.com/KB/bugs/linkererrors.aspx[^] I used the option Multi-Threaded Debug DLL in the code generation field of the C/C++ tab, in Project settings.
Last, I tried to add the MSVCRT library to the ignore list, and the program actually builds, but results in a crash when launched.
The only differences I see are that I started as "empty project" (not win32 console application) and I used options for debugging (I used Program database for edit and continue, disabled all the optimizations, and used a x86 machine as a target machine).
I'm getting quite mad to solve this, thank you in advance for any help
L.
|
|
|
|
|
Did you check this link[^]? It seems helpful.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thank you Jijo,
I didn't notice that link but actually it didn't work out..sigh
Any other possible idea? Thanks
|
|
|
|
|
LostPitch wrote: Last, I tried to add the MSVCRT library to the ignore list, and the program actually builds, but results in a crash when launched.
What does the debugger tell you when you run it in Debug mode?
|
|
|
|
|
Thanks for the help Randor,
the debugger tells me
"Unhandled exception at 0x1023201c (msvcr80d.dll) in Robi.exe: 0xC0000005: Access violation writing location 0xcdcdcd00"
even if I ignored the libraries libc.lib, libcmt.lib, msvcrt.lib, libcd.lib, libcmtd.lib, as suggested in the previous reply..
It is possible to obtain the same error downloading the zip available at http://www.css.tayloru.edu/%7Ebtoll/resources/graphics/opengl/xp/msvc/gluiProject.zip[^], and ignoring the libraries as I did...
|
|
|
|
|
Problem solved: I post to help other user that are having the same problem:
If the project uses GLUI, just import the GLUI header file avoiding gl.h, glu.h, glut.h.
Then set c++ -> code generation -> runtime library -> multi-threaded DLL (/MD).
Don't use multi-threaded debug or it will conflict with MSVCRT, ignore the library will not give any result.
That should work fine.
If you're instead working with glut remember to put in the project properties -> c++ -> preprocessor definition use GLUT_BUILDING_LIB: it solves a conflict with the ridefinition of the exit() funcion in stdlib.h (more details on http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/4cf463c1-5fee-4daa-b135-be8b06ab7f8f/[^]).
|
|
|
|
|
Hi everyone.
i wrote a little app which should check every button on the keyboard.
when pressing a key the key image on the screen will disappear.
In order to catch all the key strokes i use the PreTranslateMessage function
When i press the windows key the start menu appears
and then the PreTranslate function is called and the key disappears from the dialog.
I want to block this behaviour, and only remove the button from the dialog
thanks
Simon.
|
|
|
|
|
Try registering the windows key as a hotkey to your application using the RegisterHotKey[^] api call. Might fail though, since RegisterHotKey fails if you try to register keys already assigned to some task by another application and i don't know how windows (or maybe explorer?) uses the windows key.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Hi,
I have created a dialog application. i have rich edit text box in that dialog aplication. when the messages exceeds the size of the edit box, it automatically craetes a scroll bar. i want to keep the scroll bar at the endit selt, not moving up.
thanks,
balaji
SHivBAlAJi
|
|
|
|
|
I assume that you are sending text programatically to the rich edit text box. You need to scroll down using LineScroll . Since LineScroll will not let you scroll past the last line of text you could use MyEdit.LineScroll(MyEdit.GetLineCount(), 0) . That puts the last line of text at the top of the edit control. This probably isn't what you want - I assume that you would want the last line of text at the bottom of the display. To do this you need to the following every time the contents of the edit control is modified:
a) Get the number of visible lines in the edit control
b) Get the number of the first visible line using the GetFirstVisibleLine() method
c) Get the total number of lines in the edit control using the GetLineCount() method
d) If the number of visible lines plus the first visible line is less than the total number of lines then scroll by the difference using the LineScroll() method
The following code will do it
void MakeLastLineVisible(CRichEditCtrl& edit)
{
int LastVisibleLine = edit.GetFirstVisibleLine() - NumberVisibleLines(edit);
if(LastVisibleLine < edit.GetLineCount())
{
edit.LineScroll(edit.GetLineCount() - LastVisibleLine);
}
}
The only problem is how to implement the NumberVisibleLines function. This Microsoft article[^] shows how to do it properly. If the size of the edit control and the font used is fixed then you could just use a constant value (determined by experiment)
Graham
Librarians rule, Ook!
|
|
|
|
|
Hi graham,
Thanks for your resposne.
Sorry, Actually i have Rich text contol present in my dialog. I will get messages from the board, when the messages exceeds the size of the window, scroll bar automatically comes because of i had set the scroll bar(Vertical scroll bar) property of Rich Text Control.
My question is, when message exceeds the window size, the scroll bar automatically goes up. i don want scroll bar to move up rather it should go down, then only i can able to see latest updates form the board at time itself.
Thanks in advance,
Thanks,
Balaji
|
|
|
|
|
This is the question of the program.
Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1.
The function should not make use of any C library function calls.
Can someone help me.Appreciate for your effort
wizard zaw.
|
|
|
|
|
You could find a similar question in this Thread[^] which contains the answer also. Well, you could also look at the C++ implementation of strpos() here[^] and can modify it to match your required stricmp() function.
Well, I have to add one more - getting answers for the assignment by posting in forums will save for only for a while. By doing that you're just spoiling yourself. For this time its okay. But never do it again. I hope, you took it in right sense. Work hard and score marks!
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
|
Hello friends,
As I am beginner in threads utilization in VC++,therefore i need some assignments to go and can help myself.
Thanks In advance!
Sushrut
modified on Sunday, December 7, 2008 4:14 AM
|
|
|
|
|