|
Vipin Aravind wrote: Vipin - Microsoft MVP
Are you an MVP?
Money is the root of all evil. For more information, send $10 to me.
|
|
|
|
|
Wheres error?which line?We cant guess error in your code.
|
|
|
|
|
i wanted to draw 2 circles that intersects with each other using either microsoft C++ or Matlab.. but i guess using C++ is better. then i expect to sumhow figure out the intersect points. thats all. hoped to get the source code ASAP..
txe
|
|
|
|
|
I don't think it works like that dude.
Not many people are going to write your application for you.
look through the MSDN library at "Device Context" or "CDC". there are lots of drawing functions in the class members including Ellipse()
i have a 3d line intersection calculation in my code but i doubt i would work for circles.
|
|
|
|
|
|
txE wrote: thx anyway..
is your problem is not sorted out!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
Hi,
How can I execute command prompt commands using c++?
For example, I want my code to get the dir list of the current directory.
In the command prompt I would use: dir > dir.txt
How can I do that in c++? (without writing the code that enums the files).
Thanks,
David.
|
|
|
|
|
|
<br />
int GetDirectoryContents(CString sPath,CArray<CString,CString> &store,CString ext="*");<br />
int CFileSystem::GetDirectoryContents(CString sPath,CArray<CString,CString> &store,CString ext) {<br />
HANDLE hFind;
WIN32_FIND_DATA FindFileData;<br />
CString t_filenames;<br />
int total_files=0;<br />
<br />
TCHAR DirPath[MAX_PATH];<br />
TCHAR FileName[MAX_PATH];<br />
<br />
_tcscpy(DirPath,sPath);<br />
_tcscat(DirPath,"\\");
_tcscat(DirPath,ext);
<br />
hFind = FindFirstFile(DirPath,&FindFileData);<br />
if(hFind == INVALID_HANDLE_VALUE) return FALSE;<br />
else {<br />
<br />
_tcscpy(FileName,FindFileData.cFileName);<br />
t_filenames.Format("%s",FileName);<br />
store.Add(t_filenames);<br />
++total_files;<br />
}<br />
<br />
while(FindNextFile(hFind,&FindFileData)) {<br />
if( _tcscmp(FindFileData.cFileName,"." ) && <br />
_tcscmp(FindFileData.cFileName,".." ) ) {<br />
_tcscpy(FileName,FindFileData.cFileName);<br />
t_filenames.Format("%s",FileName);<br />
store.Add(t_filenames);<br />
++total_files;<br />
<br />
}<br />
}<br />
FindClose(hFind);
return(total_files-1);<br />
}<br />
|
|
|
|
|
|
ShellExecute doesn't let me do anything I can in command prompt.
For example, I want to get the dir list of the current diretory, how would I do that using ShellExecute?
|
|
|
|
|
Hi,
I'm trying to write a program which copies itself to a different location.
I tried to open the file passed through the arguments (to get my own name), that worked.
Next, I used CreateFile and ReadFile/WriteFile to copy to file.
It worked when I ran it in the Visual Studio enviorment, but failed when I ran in standalone.
Then I tried using CopyFile, and it gave the same results.
I know I can probably use ReadProcessMemory to make it work, but I prefer a cleaner solution.
Any Ideas?
David.
|
|
|
|
|
Have you tried the obvious - in standalone get it to print the location it thinks the executable is in and make sure that is correct. Also make sure it is an absolute path.
Elaine
|
|
|
|
|
thanks, I forgot to remove the second " character from the command line.
|
|
|
|
|
davidbr4 wrote: thanks, I forgot to remove the second " character from the command line.
CopyFile will work too!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
that's what I used, thanks
|
|
|
|
|
Fist Part
I am trying to work on a simple database project which needs to determine if a record is null. I am wanting to do this by using the function isNull() in the classes Personal and Student to determine that a record is null. Then overwrite the record to be deleted by a null record. A null record can be defined as having nonnumeric characters (a tombstone) in the first position of the SSN member.
Second Part
Then I would like to define the function remove() in the Database which should locate the position of a record to be deleted and overwrite it with a null record. Then after a session is finshed. I would like to invoke a database destructor which copies the nonnull records to a new data file, deletes the old data file, and renames the new data file with the name of the old data file.
Here is what I have so far... Any help with code, advice, or tips would be greatly appreciated...
************************ personal.h *********************
public:
Personal();
Personal(char*,char*,char*,int,long);
void writeToFile(fstream&) const;
void readFromFile(fstream&);
void readKey();
int size() const {
return 9 + nameLen + cityLen + sizeof(year) + sizeof(salary);
}
bool operator==(const Personal& pr) const {
return strcmp(pr.SSN,SSN) == 0;
}
protected:
const int nameLen, cityLen;
char SSN[10], *name, *city;
int year;
long salary;
ostream& writeLegibly(ostream&);
friend ostream& operator<<(ostream& out, Personal& pr) {
return pr.writeLegibly(out);
}
istream& readFromConsole(istream&);
friend istream& operator>>(istream& in, Personal& pr) {
return pr.readFromConsole(in);
}
};
#endif
****************** personal.cpp *******************
#include <iostream>
#include "personal.h"
Personal::Personal() : nameLen(10), cityLen(10) {
name = new char[nameLen+1];
city = new char[cityLen+1];
}
Personal::Personal(char *ssn, char *n, char *c, int y, long s) :
nameLen(10), cityLen(10) {
name = new char[nameLen+1];
city = new char[cityLen+1];
strcpy(SSN,ssn);
strcpy(name,n);
strcpy(city,c);
year = y;
salary = s;
}
void Personal::writeToFile(fstream& out) const {
out.write(SSN,9);
out.write(name,nameLen);
out.write(city,cityLen);
out.write(reinterpret_cast<const char*="">(&year),sizeof(int));
out.write(reinterpret_cast<const char*="">(&salary),sizeof(int));
}
void Personal::readFromFile(fstream& in) {
in.read(SSN,9);
in.read(name,nameLen);
in.read(city,cityLen);
in.read(reinterpret_cast<char*>(&year),sizeof(int));
in.read(reinterpret_cast<char*>(&salary),sizeof(int));
}
void Personal::readKey() {
char s[80];
cout << "Enter SSN: ";
cin.getline(s,80);
strncpy(SSN,s,9);
}
ostream& Personal::writeLegibly(ostream& out) {
SSN[9] = name[nameLen] = city[cityLen] = '\0';
out << "SSN = " << SSN << ", name = " << name
<< ", city = " << city << ", year = " << year
<< ", salary = " << salary;
return out;
}
istream& Personal::readFromConsole(istream& in) {
char s[80];
cout << "SSN: ";
in.getline(s,80);
strncpy(SSN,s,9);
cout<<'['<<ssn<<']';
cout="" <<="" "name:="" ";
="" in.getline(s,80);
="" strncpy(name,s,namelen);
="" cout<<'['<<name<<']';
="" "city:="" strncpy(city,s,citylen);
="" cout<<'['<<city<<']';
="" "birthyear:="" in="">> year;
cout<<'['<<year<<']';
cout="" <<="" "salary:="" ";
="" in="">> salary;
cout<<'['<<salary<<']';
cin.ignore();
="" return="" in;
}
****************************="" student.h="" *********************
#ifndef="" student
#define="" student
#include="" "personal.h"
class="" student="" :="" public="" personal="" {
public:
="" student();
="" student(char*,char*,char*,int,long,char*);
="" void="" writetofile(fstream&)="" const;
="" readfromfile(fstream&);
="" int="" size()="" const="" {
="" personal::size()="" +="" majorlen;
="" }
protected:
="" char="" *major;
="" ostream&="" writelegibly(ostream&);
="" friend="" operator<<(ostream&="" out,="" student&="" sr)="" sr.writelegibly(out);
="" }
="" istream&="" readfromconsole(istream&);
="" operator="">>(istream& in, Student& sr) {
return sr.readFromConsole(in);
}
};
#endif
******************************** student.cpp ********************
#include <iostream>
#include "student.h"
Student::Student() : majorLen(10) {
Personal();
major = new char[majorLen+1];
}
Student::Student(char *ssn, char *n, char *c, int y, long s, char *m) :
majorLen(11) {
Personal(ssn,n,c,y,s);
major = new char[majorLen+1];
strcpy(major,m);
}
void Student::writeToFile(fstream& out) const {
Personal::writeToFile(out);
out.write(major,majorLen);
}
void Student::readFromFile(fstream& in) {
Personal::readFromFile(in);
in.read(major,majorLen);
}
ostream& Student::writeLegibly(ostream& out) {
Personal::writeLegibly(out);
major[majorLen] = '\0';
out << ", major = " << major;
return out;
}
istream& Student::readFromConsole(istream& in) {
Personal::readFromConsole(in);
char s[80];
cout << "Major: ";
in.getline(s,80);
strncpy(major,s,9);
return in;
}
***************************** database.h ************************
#ifndef DATABASE
#define DATABASE
template<class t="">
class Database {
public:
Database();
void run();
private:
fstream database;
char fName[20];
ostream& print(ostream&);
void add(T&);
bool find(const T&);
void modify(const T&);
friend ostream& operator<<(ostream& out, Database& db) {
return db.print(out);
}
};
#endif
*********************** database.cpp *************************
#include <iostream>
#include "personal.h"
#include "student.h"
#include "database.h"
template<class t="">
Database<t>::Database() {
}
template<class t="">
void Database<t>::add(T& d) {
database.open(fName,ios::in|ios::out|ios::binary);
database.seekp(0,ios::end);
d.writeToFile(database);
database.close();
}
template<class t="">
void Database<t>::modify(const T& d) {
T tmp;
database.open(fName,ios::in|ios::out|ios::binary);
while (!database.eof()) {
tmp.readFromFile(database);
if (tmp == d) { // overloaded ==
cin >> tmp; // overloaded >>
database.seekp(-d.size(),ios::cur);
tmp.writeToFile(database);
database.close();
return;
}
}
database.close();
cout << "The record to be modified is not in the database\n";
}
template<class t="">
bool Database<t>::find(const T& d) {
T tmp;
database.open(fName,ios::in|ios::binary);
while (!database.eof()) {
tmp.readFromFile(database);
if (tmp == d) { // overloaded ==
database.close();
return true;
}
}
database.close();
return false;
}
template<class t="">
ostream& Database<t>::print(ostream& out) {
T tmp;
database.open(fName,ios::in|ios::binary);
while (true) {
tmp.readFromFile(database);
if (database.eof())
break;
out << tmp << endl; // overloaded <<
}
database.close();
return out;
}
template<class t="">
void Database<t>::run() {
cout << "File name: ";
cin >> fName;
cin.ignore(); // skip '\n';
database.open(fName,ios::in);
if (database.fail())
database.open(fName,ios::out);
database.close();
char option[5];
T rec;
cout << "1. Add 2. Find 3. Modify a record; 4. Exit\n";
cout << "Enter an option: ";
while (cin.getline(option,5)) {
cout<<'['<<option<<']';
if="" (*option="=" '1')="" {
="" cin="">> rec; // overloaded >>
add(rec);
}
else if (*option == '2') {
rec.readKey();
cout << "The record is ";
if (find(rec) == false)
cout << "not ";
cout << "in the database\n";
}
else if (*option == '3') {
rec.readKey();
modify(rec);
}
else if (*option != '4')
cout << "Wrong option\n";
else return;
cout << *this; // overloaded <<
cout << "Enter an option: ";
}
}
int main() {
Database<personal>().run();
// Database<student>().run();
return 0;
}
|
|
|
|
|
Well, for starters, I don't see destructors to clean up those char * you're allocating, so you'll leak memory. HOwever, this is a lot of code to hope for people to read, you should really distill your post to a specific question, and a specific snippet that relates to it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello, I need to draw graphics dnamically during runtime on a dialog box.
Being a VC++ noob, how is it best ot do this? Should I draw directly to the dialog box within a predefined area or draw to some other control. I can do this to a ListView object, but is it possible to use a ListView on a dialog box, or again, is there some other control that I should use?
Thanks much!
|
|
|
|
|
You don't provide enough details for what you are trying to accomplish.
ctroyp wrote: Should I draw directly to the dialog box
Usually no, but you didn't state what you are trying to do. Your mention of the listview is rather confusing since it doesn't sound like you want a listview. You can place controls on a dialog box via the dialog editor, and this would include the listview.
In most cases, if there is no common control that fits your purpose, you write your own custom control. There are various articles on codeproject about doing this.
|
|
|
|
|
Let me begin again... Sometimes it's hard to know how to ask the right question.
I have a dialog box that contains some textboxes and such, but also want to draw graphics in a pre-defined drawing area (canvas) using CPen during runtime. In addition, this canvas needs to be bound to the dialog box and should not change. I am not concerned with how I will actually draw to this canvas at this time (until I know what I am using), but I just need to know what object to use for the canvas. What are my options for this canvas? Or should I just define a section on the dialog itself that can be drawn on with predefined bounds?
Does this make any better sense?
|
|
|
|
|
Create a custom control and place it on your dialog at the size you want.
Here[^] is an article on creating custom controls.
|
|
|
|
|
Thank you, I'll give it a try...
|
|
|
|
|
You could place a static control, there are articles about controls based on statics.
Elaine
|
|
|
|
|