|
I can send you the source code for the program for chapter 5, slide 50. Will that do? My program was rated very highly by Consumer Reports, but I don't know about the producer part.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
nivsah wrote:
chapter 5 slide 51
You don't seriously expect us to do your homework for you, do you?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I have a help file that I wrote and saved as a .pdf file. I want to be able to click a help button and have the file pop-up in Acrobat reader. I have coded a system command as follows:
system("start help.pdf");
and this works but it is slow and always pops up a DOS command window. Is there a better way to do this?
|
|
|
|
|
use the windows shell: ShellFileExecute
|
|
|
|
|
Can use ShellExecuteEx / ShellExecute. Have a look @ MSDN
|
|
|
|
|
Thanks, this works great!
|
|
|
|
|
Hi all,
I am relatively new to api programming.I am trying to automate a process and am using EnumWindows to get all window handles. I am then using GetWindowText and strcmp to check which of the window handles corresponds to the relevent window. However it doesnt seem to work i.e., it doesnt simulate the push of the button....
I have pasted the code snippet below.. Any suggestions on how to resolve this will be terrific.
In the main program i have
EnumWindows((WNDENUMPROC) WinCallback, 0);
My function is:
BOOL CALLBACK WinCallback(HWND win, LPARAM nadda)
{
char temp[512];
GetWindowText(win, temp, 512);
printf("%s",temp);
if(!strcmp(temp,"RBNal_Optocomm"))
{
HWND hcomm = FindWindowEx((HWND) win,NULL,"BUTTON","COM 1");
LRESULT lResult2;
lResult2 = SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0);
return FALSE;
}
}
Please let me know of any suggestions.
D
|
|
|
|
|
BM_CLICK message will fail if the window that will recieve the is not active. Try the code below.
if(!strcmp(temp,"RBNal_Optocomm"))
{
HWND hcomm = ::FindWindowEx((HWND) win,NULL,"BUTTON","COM 1");
if (hcomm)
{
::SetActiveWindow(hcomm);
LRESULT lResult2;
lResult2 = ::SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0);
return FALSE;
}
}
|
|
|
|
|
Thanks.. It still isnt working though.. I have passed an LPARAM value of 0 into the function.. Would this matter??
D
|
|
|
|
|
Hi,
try calling SetActiveWindow(win) before the line SetActiveWindow(hcoom). It should look like this
if (hcomm)
{
::SetActiveWindow(win);
::SetActiveWindow(hcomm);
LRESULT lResult2;
lResult2 = ::SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0);
return FALSE;
}
I had tested this and i had sent a sample applications (sender and receiver) in your email.
|
|
|
|
|
Hi
Thanks.. it worked....
Deepak
|
|
|
|
|
Hi all,
here is some interesting problem.... the problem setup goes like this...
a plane paper is placed on a table and a sphere is placed over it at some height and on that sphere at certain height a light was placed.
Noow as we all know it produces a shadow on the paper which will be some what elliptical if the light is not on the center line of the sphere. In this condition if we assume the paper as a 2D image then how can we calculate the pixels tht are covered under the elliptical shadow ( or to put it in other way while scannin form top how can we decide whether a pixel falls under the shadow).
any ideas ot thoughts are appreciated.
thanks in advance,
Suman
|
|
|
|
|
Google ray tracing.
Or DirectX will do it for you, if that's all you need.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
the shadow is the intersection of the plane of the paper and the cone whose apex is at the light and whose sides are tangent to the sphere.
The distance from apex (light) to center of sphere is the hypotenuse of a triangle whose side opposite the apex angle is the radius of the sphere. This is enough to determine the cone.
|
|
|
|
|
Hi Scott,
yep u r right....i understood ur point. But the problem is how to tell whether a pixel lies in the shadow or not. I mean r there any techniques or approach to find it out.
becos i was given a sphere of some radius and the height at which it is and the pixel at which the center of the sphere lies. and i have to figure out all the pixels covering under its shadow...and then i have to do some other calcualtins for those pixels... but first of all i have to find those pixels.
hope i am clear to u.
thanks in advance,
Suman
|
|
|
|
|
Dear sirs:
I am learning VC++ and am having trouble compiling my project. The project includes several classes that inherit properties from other classes. I ran into just 3 "unresolved external symbol errors - LNK2019".
I am using the Visual Studio .NET 2003 platform to develop the application with. I have included the source files with this post and you can recreate the project by creating a new Win32 Console Application project named "use_student", and simply add the files into your project.
Any help would be much appreciated!
Thank you,
Rob Hyland
NOTE: if you just see a line of code that says "#include" all by itself it should read
"#include (bracket symbol) iostream (bracket symbol)"
***************************************************************************************************
*********************************** Header Files **************************************************
//
//////////////////////////////////////////////////////////////
// Listing 13.3 studentc.h. /
// studentc.h -- defining a Student class using containment /
//////////////////////////////////////////////////////////////
//
//
#ifndef _STUDNTC_H_
#define _STUDNTC_H_
#include <iostream>
#include "arraydb.h" // -- ArrayDB objects.
#include "strng2.h" // -- String objects (from Chapter 11).
using namespace std;
class Student
{
private:
String name;
ArrayDb scores;
public:
Student() : name("Null Student"), scores() {} // -- Use initialization syntax to init. objects.
Student(const String & s) : name(s), scores() {}
Student(int n) : name("Nully"), scores(n) {}
Student(const String & s, int n) : name(s), scores(n) {}
Student(const String & s, const ArrayDb & a) : name(s), scores(a) {}
Student(const char * str, const double * pd, int n) : name(str), scores(pd, n) {}
~Student() {}
double & operator[](int i);
const double & operator[](int i) const;
double Average() const;
// friends
friend ostream & operator<<(ostream & os, const Student & stu);
friend istream & operator>>(istream & is, Student & stu);
};
#endif
//
/////////////////////////////////////////
// strng1.h -- string class definition /
/////////////////////////////////////////
//
//
#include <iostream>
using namespace std;
#ifndef _STRNG1_H_
#define _STRNG1_H_
class String
{
private:
char * str; // pointer to string
int len; // length of string
public:
String(const char * s); // constructor
String(); // default constructor
String(const String & st);
//~String(); // destructor
int length() const { return len; } // -- Return the length of a stored string.
// overloaded operators
String & operator=(const String & st); // Assignment operator
String & operator=(const char * s); // Assignment operator #2
// friend functions
friend bool operator>(const String &st1, const String &st2);
friend bool operator<(const String &st, const String &st2);
friend bool operator==(const String &st, const String &st2);
friend ostream & operator<<(ostream & os, const String & st);
friend istream & operator>>(istream & is, String & st);
};
#endif
//
/////////////////////////////
// Listing 13.1 arraydb.h. /
// arraydb.h -- array class /
/////////////////////////////
//
//
#ifndef _ARRAYDB_H_
#define _ARRAYDB_H_
#include <iostream>
using namespace std;
class ArrayDb
{
private:
unsigned int size; // -- Number of array elements.
double * arr; // -- Address of first element.
public:
ArrayDb(); // -- Default constructor.
// -- Explicit keyword used to catch assignment errors (i.e. incorrect number of arguments).
explicit ArrayDb(unsigned int n, double val = 0.0); // -- Create an ArrayDb of n elements, set each to val.
ArrayDb(const double * pn, unsigned int n); // -- Create an ArrayDb of n elements, initialize to array pn.
ArrayDb(const ArrayDb & a); // -- Copy constructor.
virtual ~ArrayDb(); // -- Destructor.
// -- Returns array size.
unsigned int ArSize() const
{
return size;
}
double Average() const; // -- Return array average.
//
//////////////////////////
// Overloaded operators. /
//////////////////////////
//
virtual double & operator[](int i); // -- Array indexing; allow modifications.
virtual const double & operator[](int i) const; // -- Array indexing; read-only.
ArrayDb & operator=(const ArrayDb & a); // -- Assignment.
friend ostream & operator<<(ostream & os, const ArrayDb & a);
};
#endif
***************************************************************************************************
************************************** Source Files ***********************************************
***************************************************************************************************
//
//////////////////////////////////////////////////////
// Listing 13.4 studentc.cpp. /
// studentc.cpp -- Student class using containment /
//////////////////////////////////////////////////////
//
//
#include "studentc.h"
double Student::Average() const
{
return scores.Average(); // use ArrayDb::Average()
}
double & Student::operator[](int i)
{
return scores[i]; // use ArrayDb::operator[]()
}
const double & Student::operator[](int i) const
{
return scores[i];
}
// friends
// use String and ArrayDb versions
ostream & operator<<(ostream & os, const Student & stu)
{
os << "Scores for " << stu.name << ":\n";
os << stu.scores;
return os;
}
// use String version
istream & operator>>(istream & is, Student & stu)
{
is >> stu.name;
return is;
}
//
///////////////////////////////////////////
// Listing 13.2 arraydb.cpp. /
// arraydb.cpp -- ArrayDb class methods /
///////////////////////////////////////////
//
//
#include <iostream>
#include "arraydb.h"
using namespace std;
#include (bracket symbol) cstdlib (bracket symbol) // exit() prototype
//
//
/////////////////////////////////////////
// Default constructor -- no arguments. /
/////////////////////////////////////////
//
//
ArrayDb::ArrayDb()
{
arr = NULL; // -- Empty.
size = 0; // -- No value.
}
//
//
/////////////////////////////////////////////////////
// Constructs array of n elements, each set to val. /
/////////////////////////////////////////////////////
//
//
ArrayDb::ArrayDb(unsigned int n, double val)
{
arr = new double[n]; // -- Create new array.
size = n; // -- Number of elements in array.
// -- Loop through array.
for (int i = 0; i < size; i++)
arr[i] = val; // -- Place variable in array.
}
//
//
////////////////////////////////////////////////////
// Initialize ArrayDb object to a non-class array. /
////////////////////////////////////////////////////
//
//
ArrayDb::ArrayDb(const double *pn, unsigned int n)
{
arr = new double[n]; // -- Create new array.
size = n; // -- Number of elements in array.
// -- Loop through array.
for (int i = 0; i < size; i++)
arr[i] = pn[i]; // -- Assign value from one array to another.
}
//
//
/////////////////////////////////////////////////////////
// Initialize ArrayDb object to another ArrayDb object. /
/////////////////////////////////////////////////////////
//
//
ArrayDb::ArrayDb(const ArrayDb & a)
{
size = a.size; // -- Size of array dictated by ArrayDb object.
arr = new double[size]; // -- Create new array.
// -- Loop through array.
for (int i = 0; i < size; i++)
arr[i] = a.arr[i]; // -- Assign value from object-array to array.
}
//
//
///////////////////
// Deconstructor. /
///////////////////
//
//
ArrayDb::~ArrayDb()
{
delete [] arr; // -- Free-up memory created with new.
}
//
//
////////////////////////////
// Take average of grades. /
////////////////////////////
//
//
double ArrayDb::Average() const
{
double sum = 0; // -- Initialize sum-of-grades variable.
int i; // -- Counter variable.
int lim = ArSize(); // -- Get array size.
// -- Loop through array.
for (i = 0; i < lim; i++)
sum += arr[i]; // -- Summation of grades.
// -- If counter is true, then take average.
if (i > 0)
return sum / i;
// -- Else there were no grades to average.
else
{
cerr << "No entries in score array\n";
return 0;
}
}
//
//
////////////////////////////////////////////////////////////
// Let user access elements by index (assignment allowed). /
////////////////////////////////////////////////////////////
//
//
double & ArrayDb::operator[](int i)
{
// -- Check index before continuing.
if (i < 0 || i >= size)
{
cerr << "Error in array limits: "
<< i << " is a bad index\n";
exit(1);
}
return arr[i]; // -- Return with array-value.
}
//
//
///////////////////////////////////////////////////////////////
// Let user access elements by index (assignment disallowed). /
///////////////////////////////////////////////////////////////
//
//
const double & ArrayDb::operator[](int i) const
{
// --Check index before continuing.
if (i < 0 || i >= size)
{
cerr << "Error in array limits: "
<< i << " is a bad index\n";
exit(1);
}
return arr[i]; // -- Return with array-value (read-only).
}
//
//
/////////////////////////////
// Define class assignment. /
/////////////////////////////
//
//
ArrayDb & ArrayDb::operator=(const ArrayDb & a)
{
// -- Check to see if the object is assigned to itself.
if (this == &a)
return *this; // -- If it is, don't change anything.
delete [] arr; // -- Free-up memory.
size = a.size; // -- Get new size from object.
arr = new double[size]; // -- Create new array.
// -- Loop through array.
for (int i = 0; i < size; i++)
arr[i] = a.arr[i]; // -- Assign value from object-array to array.
return *this;
}
//
//
//////////////////////////////////////
// Quick output, 5 values to a line. /
//////////////////////////////////////
//
//
ostream & operator<<(ostream & os, const ArrayDb & a)
{
int i;
for (i = 0; i < a.size; i++)
{
os << a.arr[i] << " ";
if (i % 5 == 4)
os << "\n";
}
if (i % 5 != 0)
os << "\n";
return os;
}
//
///////////////////////////////////////////////////////////////////////////
// use_student.cpp : Defines the entry point for the console application. /
///////////////////////////////////////////////////////////////////////////
//
//
#include <iostream>
#include "stdafx.h"
#include "studentc.h"
using namespace std;
//
//
/////////////////////////
// Function prototypes. /
/////////////////////////
//
//
void set(Student & sa, int n);
//
//
///////////////////////////
// Variable declarations. /
///////////////////////////
//
//
const int pupils = 3;
const int quizzes = 5;
//
//
///////////////////////////
// Start of main program. /
///////////////////////////
//
//
int _tmain(int argc, _TCHAR* argv[])
{
Student ada[pupils] = {quizzes, quizzes, quizzes}; // -- Create student object arrays.
int i;
for (i = 0; i < pupils; i++)
set(ada[i], quizzes);
for (i = 0; i < pupils; i++)
{
cout << "\n" << ada[i];
cout << "average: " << ada[i].Average() << "\n";
}
return 0;
}
//
//
/////////////////////////////////////////
// Function to register pupil's scores. /
/////////////////////////////////////////
//
//
void set(Student & sa, int n)
{
cout << "Please enter the student’s name: ";
cin >> sa;
cout << "Please enter " << n << " quiz scores:\n";
for (int i = 0; i < n; i++)
cin >> sa[i];
while (cin.get() != '\n')
continue;
}
***************************************************************************************************
****************************** End of Source Files ************************************************
***************************************************************************************************
|
|
|
|
|
Hi,
i wrote a program in vc++ and it generates some data values which i am writing it into a .txt file. Now for ploting a graph for tht data I am importing this file in excel and plotting the graph. But what i want is to open an excel sheet directly from my proram while executing and write the data whenever generated into it or to open an excel file at the end of program and import all the data in the txt file into it directly.
Plz remember I am not talkin about writing into an .xls file, but how to start the excel application and open a new file (anyway we will get a new blank sheet only when we start it)and then do all this stuff.
is it possible to implement this?.. if it is, is it very hard doin by writing handler programs or so...? and how can i start writing values into tht file from a specific starting point from which i am interested to write?
any suggestions or advices r appreciated.
thanks in advance,
Suman
|
|
|
|
|
You want to develop an application that will talk to MS Excel, correct?
Kuphryn
|
|
|
|
|
yep u got my point.....but how can we make it....
Suman
|
|
|
|
|
Yes that can be done by using OLE AUTOMATION. Just search on net for key word "Office Automation" VC++. You'll get lots of articles.
|
|
|
|
|
thanks Sujan..,
I will look over thru some of those articles and if I am not able to figure it out... then i will let u know...i hope u understood my problem clearly...
though i am able to open an excel sheet in my vc++ program... i must be able to write the values tht my program generates into it from whereever i want to in tht sheet (i.e in some way i must be able to switch between rows and columns of the excel sheet).
cheers,
Suman
|
|
|
|
|
Hi
the better way to start is to use the macro option in office products. Record a macro, open it in visual basic editor, convert it to a VC++ structure, and use it. But converting the visual basic code to VC++ code will take some time.
I haven't worked with excel, but with ms word and outlook.
Hope this helps you
Sujan
|
|
|
|
|
|
Hi Azam,
thanks for ur advice, I have gone through the link tht u have given and created an example project based upon those tutorial. Actually its an MFC application and it creates a dialog box on which we have to click on 'run' which then activates the excel.
but wht i am trying to do is .. my program is a pire c++ source file. it generates certain values in the time of its execution and at present i am writing them into an text file. But i want to open an excel sheet (just like i opened a text file) and then i have to write the values tht i generate..into the excel sheet (just like i write the values whenever generated into a text file). and then i have at the end of the execution i have show up the excel sheet.
one more thing is I'm willing to write the data in the sheet from a particular row and column. My data is a 2D data (256x256).
hope i am clear to u...if u r having any ideas lemme know i'll work on it.
thanks in advance,
Pavan.
Suman
|
|
|
|
|
ya i got it but wud you plz confirm me one thing, what kind of application you are developing, i mean is it a MFC based application (using CFile or some derivative of it for opening and writing text file) or a WIN32 application (using HFILE for opening and writing text file) or core C++ (using FILE structure for opening and writing text file).
As far as i know in either case you can use COM (or specifically Automation) for your application.
Also the link that i sent to you shows how you can write data in cells of excel sheet. were you able to run that program since if you are using excel 2002 or above then i suppose you have to change the line range.SetValue(COleVariant(saRet)); to range.SetValue2(COleVariant(saRet)); in your run method
any ways will try to figure out some thing for you
regards
Azam
|
|
|
|