|
Hi All,
I've created a dialog based application with the dialog having multiple editboxes. What I want to achieve is to call a specific function when I press "Enter" key. Each editbox should trigger its specific function or I should be able to know from which editbox the enter key was pressed.
Please help.
Thanks,
Gajendra
|
|
|
|
|
gajendrakashyap wrote: Each editbox should trigger its specific function or I should be able to know from which editbox the enter key was pressed.
You GetFocus api to get currently focussed Edit box!
"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
|
|
|
|
|
Using this I can get a pointer to the ebox. If I could get the ID number of the ebox in context, it would help me more than having a pointer as my application logic depends on that.
Can you suggest something on obtaining focussed ebox control id number?
Thanks,
Gajendra
|
|
|
|
|
Using this I can get a pointer to the ebox. If I could get the ID number of the ebox in context, it would help me more than having a pointer as my application logic depends on that.
Can you suggest something on obtaining focussed ebox control id number?
|
|
|
|
|
You can override default PreTranslateMessage function of the dialog/window class.
BOOL CBAMBuildToolDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam == VK_RETURN)
{
if (pMsg->hwnd == ::GetDlgItem(*this, IDC_EDITBOXID)
//Replace with proper ID
{
//Handling of the return key for this edit box
return TRUE;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
I hope the above code snippet will help you.
Regards,
Stanly
|
|
|
|
|
stanlymt wrote: IDC_EDITBOXID)
from where this ID will come.. and are you going to check like this, for every Control present on Dilaog box.. this really going to make you PreTranslateMessage Bulky..
"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
|
|
|
|
|
ID is the Editbox ID in the resource file. If you need to handle differently for each edit box in the dialog, you have to handle it seperately. Otherwise,
you can use one button as 'default' button and handle the event there.
|
|
|
|
|
stanlymt wrote: you can use one button as 'default' button and handle the event there.
then I believe his question wrong.. actually that person want currently focused EditBox at the Time of press of enter key
"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
|
|
|
|
|
gajendrakashyap wrote: Can you suggest something on obtaining focussed ebox control id number?
when you got pointer to Window you can easily call function GetDlgCtrlID to retrieve it control id
"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
|
|
|
|
|
Thanks Alok. Actually i tried that, but misspelt the name of function
I could work from your first clue itself.
Thanks for the help !!
Thanks & regards,
Gajendra
|
|
|
|
|
I have a program that is able to take the numbers out of the .txt if it is just a list of numbers. Problem is, I have a file with Names before the grades. I believe i need to set up another array inside the first one to fill with names. The .txt file will look like:
Name
grade
grade
grade
grade
grade
grade
grade
grade
grade
grade
Name
...
Have 15 Names with 10 grades under each. I guess what i'm trying to do is take the strings out of the file. Is there a way to take the strings(there is a string every 11 lines)
Here is what i have now:
#include
#include
#include
#include
#include
#include
using namespace std;
const int TESTS = 10;
const int STUDENTS = 15;
void displayGrades( int [][TESTS] );
void getGrades( int [][TESTS]);
int main()
{
int data[STUDENTS][TESTS] = {0};
getGrades( data );
cout <<fixed <<setprecision(1);
displaygrades(="" data);
#ifdef="" win32
system("pause");
#endif
return="" 0;
}
void="" getgrades(int="" data[]="" [tests])
{
ifstream="" inputfile;
inputfile.open("gradespring07.txt");
if="" (!inputfile)
{
cout="" <<="" "error="" opening="" file!"="" endl;
exit(="" 1="" );
}
for="" (int="" student="0;" student<="" students="" ;="" student++)
{
for="" test="0;" test
{
inputfile="">> data[student][test];
}
}
}
void displayGrades( int data[][TESTS] )
{
double testTotal = 0.0;
double classTotal = 0.0;
double squared = 0.0;
double var = 0.0;
double sdev = 0.0;
int mxm = data[0][0];
int min = data[0][0];
cout << "\nGrade summary" << endl;
cout << "--------------" << endl;
cout << left << setw(7) << "Student"
<< right << setw(5) << right << "Ex1"
<< setw(7) << "Ex2"
<<setw(6) <<="" "ex3"
<<setw(6)="" "qz1"
<<setw(5)="" "qz2"
<<setw(6)="" "qz3"
<<setw(6)="" "qz4"
<<setw(6)="" "qz5"
<<setw(6)="" "pr1"
<<setw(6)="" "pr2"
<<setw(8)="" <<"averg"="" <<endl;
for="" (="" int="" student="0;" <="" students;="" ++)
{
cout="" left="" <<setw(7)="" +="" 1;
for="" test="0;" tests;="" test++)
{
int="" grade="data[student][test];
cout" right="" <<setw(5)="" <<"="" ";
classtotal="" average="(((data[student][0]+data[student][1]+data[student][2])/3)*0.4)+(((data[student][8]+data[student][9])/2)*0.3)+(((data[student][3]+data[student][4]+data[student][5]+data[student][6]+data[student][7])/5)*0.3);
cout" setw(7)="" endl;
}
cout="" "\n"="" "test="" avg";
for="" (int="" test++)
{
for="" student++)
{
testtotal="" setw(6)="" testtotal="" students;
testtotal="0.0;
}
cout" endl;
cout="" "stan="" dev";
for="" student++)
{
squared="" 2.0);
var="(squared" -="" ((testtotal="" *="" testtotal)="" 15)="" )="" 15;
sdev="sqrt(var);
}
cout" sdev;
sdev="0.0;
}
cout" "max";
for="" student++)
{
if="" (data[student][test]=""> mxm)
{
mxm = data[student][test];
}
}
cout << right <
|
|
|
|
|
So what's your actual problem? Does it fail to compile? Does it crash? Does it just act weird?
Is there a particular part that you know isn't working properly? Have you tried stepping through that part in a debugger?
If you can isolate the particular part that's giving you a problem, let us know, and we might be able to help
|
|
|
|
|
there is no problem with the code that i posted. The problem i am facint is that the posted code will only read a list of integers without a student name. The .txt i need to read from is supposed to have the student name then 10 grades after then another name and another 10 grades. Don't know how to retrieve the name.
Thanks
|
|
|
|
|
I have to use a third part extension dll in my vc2003.net project, but to my despond the dll was built with vc6.0. In the book, they say a extension dll should use in a client application with the same version MFC dll. But I want know if there is a solution?
Thanks a lot!
|
|
|
|
|
Link the client application to the old MFC
|
|
|
|
|
Yes, it works. But, is there another way out?
|
|
|
|
|
I'm not sure how safe it would be. If you can link to the extension DLL and it runs then great.
The behavior, at best, would be undefined for any MFC extended classes that you derive from in
your client app though. Old MFC may allocate stuff the new MFC doesn't free, member variables
could be different, etc. Lots of room for things to go wrong
|
|
|
|
|
plus...
Two different MFC frameworks loaded at the same time, global variables for the two are different,
it goes on and on.
|
|
|
|
|
In MSDN, Write() function of CFile class follow:
virtual void Write( const void* lpBuf, UINT nCount );
throw( CFileException );
Remarks
Writes data from a buffer to the file associated with the CFile object.
Write throws an exception in response to several conditions, including the disk-full condition.
But in fact, when disk full and application try write to disk then an unhandled exception occur.(CFileException didn't catch)
What is cause of this problem?
-----------------
Best Regards,
Le Thanh Cong
|
|
|
|
|
Le Thanh Cong wrote: But in fact, when disk full and application try write to disk then an unhandled exception occur.(CFileException didn't catch)
Looking at the CFile::Write() source code, it only throws CFileException (unless maybe you pass
invalid parameters to the function).
How are you catching the exception? Like this?
try
{
file.Write(...);
}
catch (CFileException *e)
{
e->Delete();
}
|
|
|
|
|
I catched the exception follow:
try
{
file.Write(...);
}
catch (CFileException*)
{
AfxMessageBox("xxx");
}
But message didn't display
-----------------
Best Regards,
Le Thanh Cong
|
|
|
|
|
Then the disk isn't full?
Step into CFile::Write() and see if the ::WriteFile(...) call succeeds.
|
|
|
|
|
Thank you, maybe I found cause of this problem.
In normal conditions, CFileException will be thrown.
But in some special conditions, as multi-thread, communication with devices as USB I/O … then other exception has thrown before that.
-----------------
Best Regards,
Le Thanh Cong
|
|
|
|
|
MFC application will be automatically called InitCommonControls() function, so to enable XP visual style we only need add manifest file to resource. That is right or wrong?
-----------------
Best Regards,
Le Thanh Cong
|
|
|
|
|
Ok, this is my 2nd post about C++/CLI.
The answers for the first took me to the right tools needed to learn C++/CLI.
So, I got everything to start to learn C++/CLI: a book, Visual C++ Express Edition and a lot of energy
But, suddenly, a question comes to me and makes me doubt about all this.
Why write with C++/CLI instead of C# in example, (or any .NET language).??
What else I got with C++/CLI??
I understand why to programm in C++, (using MFC, ATL, STL, WTL....) to get a native exe, but I can't see the differents between C++/CLI and C#, (besides the language it self).
What I could see, (maybe I can be wrong), is that it took a lot of headheaches to Microsoft Team to include C++ into the .NET languages, (that's why, first, we have MC++ and then C++/CLI). In other side two languages like C# and VB NET were born and they expose the NET framework naturally.
So, should I spend my money and time to learn C++/CLI?
Do you understand what I mean? (my english, maybe, is not too good enough).
I really appreciate your help.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|