|
If you have the buttons set up with the Tab Stop option, but pressing tab does not cycle the focus, it may be part of your code intercepting the Tab key's message. Do you have any pretranslatemessage functions that may be throwing off the key press messages?
|
|
|
|
|
i wrote the following in pretranslatemessage()
if(pMsg->message==WM_KEYDOWN)
{
if(pMsg->wParam==VK_RETURN)
pMsg->wParam=VK_TAB;
if(pMsg->wParam==VK_ESCAPE)
return false;
}
return CDialog::PreTranslateMessage(pMsg);
tab key is working but i cant view the changes.i used cxSkinbutton
|
|
|
|
|
I do not understand why you have your pretranslate message converting the VK_RETURN messages into VK_TAB, However, if that is necessary, you may have to do the same for WM_KEYUP
|
|
|
|
|
tab is working.am move to button using tab after i place tab on one button, and press enter key that show error what is a problem.
|
|
|
|
|
janpoo wrote: and press enter key that show error what is a problem.
And whats that ?
|
|
|
|
|
I made a simple programme and there is a single compilation error. i am new to inheritance technicalities so, plz anyone can interpret this error for me.
the orror is ->> cannot find default constructor to initialize base class 'baby' in function mybaby::mybaby(int,int).
i am also enclosing the code for your reference -->>
# include "iostream.h"
# include "conio.h"
class baby
{
private:
int weight,age;
char name[20];
public :
int standard;
baby(int age, int weight, int standard):age(age),weight(weight),standard(standard)
{ }
baby(int age, int weight):age(age),weight(weight)
{ }
void get_name()
{
cout<<"\n \n Enter the name of the baby -> ";
cin>>name;
}
void show_data()
{
cout<<"\n \n The name of the baby is -> "<<name;
cout<<"\n \n="" the="" age="" and="" weight="" of="" baby="" is="" -=""> "<<age<<" &="" "<<weight<<"="" respectively";
}
};
class="" mybaby="" :="" baby
{
private:
int="" mybaby_age,mybaby_weight;
char="" mybaby_name;
public:
mybaby(int="" mybaby_age,="" int="" mybaby_weight):mybaby_age(mybaby_age),mybaby_weight(mybaby_weight)
{="" }
void="" get_mybabyname()
{
cout<<"\n="" \n="" the="" name="" of="" my="" baby="" -=""> ";
cin>>mybaby_name;
}
void show_mybabyname()
{
cout<<"\n \n The name of my baby is -> "<<mybaby_name;
cout<<"\n \n="" the="" standard="" of="" my="" baby="" is="" -=""> "<
|
|
|
|
|
I may be wrong, but I would interpret the problem as a lack of default constructor in the class Baby.
You should make a function in Baby that's just Baby() without any parameters.
I believe when you make a new class, like MyBaby, that is based off another class, Baby, that it needs the base class, Baby, to have a default constructor.
This is because when you construct MyBaby, it will inherit all of Baby, and initialize using Baby().
-----
Your code is hard to follow, because I don't quite get what you're trying to do. When you initialize mybaby obj0(7,25); the variable standard is not initialized anywhere in the code. this would make obj0.show_mybabyname(); to print out garbage for "The standard of my baby is -> "
-----
also note the char mybaby_name; is not initialized as an array, and will not store a name.
I think you fail to see the usefulness in inheritance, as you have mybaby_age and mybaby_weight. When you declare a mybaby object, you can use age and weight that is inherited from the baby class to store the same values.
|
|
|
|
|
Firstly, you're using private inheritance (the default for class es); you probably intended this:
class mybaby : public baby
Secondly, the class baby has no default constructor (a constructor that can be called with no arguments). To fix this the derived class needs to explicitly call a constructor, like this:
mybaby(int mybaby_age, int mybaby_weight)
: baby(mybaby_age, mybaby_weight)
{}
Thirdly why has the class mybaby got the members mybaby_age , mybaby_weight and mybaby_name when the members weight , age and name will be inherited from the base and look like they serve the same purpose?
There are other problems but this should point you in the right direction.
Steve
|
|
|
|
|
for the second time :
please respect the forum posting guildelines[^] and use the appropriate <pre></pre> tags when posting code samples.
moreover, a huge piece of code is generaly useless if you sink the lines that really matter into a ocean of code lines that don't bring much infos to the problem.
|
|
|
|
|
i posted the code along with the problem so that someone trying to figure out the problem may understand the issue clearly by running or analysing the code himself/herself over his/her machine.
and regarding the
, i'll take care of that next time i post anything like a code.
|
|
|
|
|
I program on occasion as a past time. I'm very familiar with Visual C++ 6.0 and all my apps are made on it. Soon I will be upgrading to Vista and I am worried about compatibility. Vista says it is not supporting any C++ before 2005. I know I won't be able to take advantage of any new Vista API if I continue using Visual C++ 6.0, my question is will it run at all?
Basically, if I do get Vista installed, can I use Visual C++ 6.0 and still make applications using the XP/98 API that I've been using. Or has Microsoft basically forced an upgrade?
Thanks
|
|
|
|
|
x87Bliss wrote: Basically, if I do get Vista installed, can I use Visual C++ 6.0 and still make applications using the XP/98 API that I've been using.
Yes. You can use VC6 on Vista.
x87Bliss wrote: Or has Microsoft basically forced an upgrade?
VC 6 is no longer supported, so its other way to ask for upgrade.
|
|
|
|
|
VC6 runs fine on Vista, just make sure you install SP6.
|
|
|
|
|
Thanks for both of your responses
|
|
|
|
|
Hi
after freeing a pointer using free() is it required to set it to NULL ?
thanks
|
|
|
|
|
You should set it to NULL, freeing it doesn't do that for you.
-Sean
|
|
|
|
|
No, setting it to NULL is not required. Many people do it because it can help track down dangling pointer problems.
Steve
|
|
|
|
|
Its is not required, but its good practice to set pointer to NULL after deleting.
|
|
|
|
|
Ayman Mashal wrote: after freeing a pointer using free() is it required to set it to NULL ?
it will good programming practice if you set it NULL, it may save you many trouble
|
|
|
|
|
Hey guys,
I guess I need to brush up on my pointers a bit. How do I keep the value of a spot in a pointer from changing when the object it was set with changes? my code looks something like this:
<br />
Node someNode;<br />
Node * nodeArray = new Node[40];<br />
<br />
.<br />
.<br />
.<br />
<br />
for(int i = 0; i < 40; i++)<br />
{<br />
<br />
nodeArray[i] = someNode;<br />
}<br />
I'm looking for a way to keep my array values from all ending up as the final value of someNode.
I know this has something to do with dereferencers and stuff here and there, but it's been quite a while. I checked google and a few other places, but no luck.
Thanks,
Sean
|
|
|
|
|
Write a copy constructor in Node that makes a deep copy. That way, each assignment in
nodeArray[i] = someNode; will make a separate copy of the data.
|
|
|
|
|
That's a really handy little trick . Thanks for the help (I don't think I would have ever remembered that one).
|
|
|
|
|
Hi, I am a total beginner - first time using this forum.
I need to write a fraction calculator program that can do +,-,*,and /. The output format required is like this:
> 1/2 + 3/4
> 5/4
>2 1/2 - 3/4
>1 3/4
Essentially, I need to ask the user to input a valid expression, and be able to output the result on the screen. Notice that I have to be able to do mixed fractions. This is a huge challenge for me. I don't know how to extract key data from user's inputs.
This is an example given in class - but my professor said that we can't have the program menu driven. It means I can't ask the user numerator and denominator separately, for example. A good method/strategy to write this program is appreciated.
Note: something with me posting header files - so the ones really needed: stdlib.h, iostream, math.h, conio.h, string
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <conio.h>
#include <time.h>
#include <string>
using namespace std;
class Fraction
{
public:
Fraction()
{
num = 0;
denom = 1;
}
Fraction(int a, int b) : num(a), denom(b)
{
int div = gcd(num, denom);
num /= div;
denom /= div;
}
Fraction(const Fraction &x)
{
num = x.num;
denom = x.denom;
}
Fraction operator =(const Fraction &x)
{
num = x.num;
denom = x.denom;
return Fraction(num,denom);
}
friend ostream& operator <<(ostream& out, const Fraction &x);
friend istream& operator >>(istream& in, Fraction &x);
friend Fraction operator +(const Fraction &x, const Fraction &y);
friend Fraction operator -(const Fraction &x, const Fraction &y);
friend Fraction operator *(const Fraction &x, const Fraction &y);
friend Fraction operator /(const Fraction &x, const Fraction &y);
private:
int num, denom;
int gcd(int p, int q)
{
return (q==0)? p : gcd(q, p%q);
}
};
Fraction operator +(const Fraction &x, const Fraction &y)
{
int num, denom;
num = x.num*y.denom + y.num*x.denom;
denom = x.denom * y.denom;
return Fraction(num,denom);
}
Fraction operator *(const Fraction &x, const Fraction &y)
{
int num, denom;
num = x.num*y.num;
denom = x.denom * y.denom;
return Fraction(num,denom);
}
Fraction operator -(const Fraction &x, const Fraction &y)
{
int num, denom;
num = x.num*y.denom - y.num*x.denom;
denom = x.denom * y.denom;
return Fraction(num,denom);
}
Fraction operator /(const Fraction &x, const Fraction &y)
{
int num, denom;
num = x.num*y.denom;
denom = x.denom * y.num;
return Fraction(num,denom);
}
ostream& operator <<(ostream& out, const Fraction &x)
{
out<<x.num<<' '<<x.denom;
="" return="" out;
}
istream&="" operator="">>(istream& in, Fraction &x)
{
char junk;
in>>x.num>>junk>>x.denom;
return in;
}
char menu()
{
cout<<"Please make a selection: "<<endl
<<"="" a="" input="" the="" fraction="" a"<<endl
="" b="" b"<<endl
="" +="" add="" and="" -="" subtract="" from="" divide="" by="" *="" multiply="" c="" print="" answer="" c"<<endl
="" 1="" move="" to="" 2="" q="" quit"<<endl
="" <<"your="" selection:="" ";
="" char="" ans;
="" cin="">>ans;
cin.ignore(1000,'\n');
return ans;
}
void operation(char choice, Fraction &a, Fraction &b, Fraction &c)
{
switch(toupper(choice))
{
case 'A' : cout<<"Please enter the fraction A: ";
cin>>a;
break;
case 'B' : cout<<"Please enter the fraction B: ";
cin>>b;
break;
case 'C' : cout<<"The fraction C is: "<
|
|
|
|
|
Are you familiar with the C++ String find and substr functions?
If you are I would use them, if not, I would get familiar and use them
To parse a statement I would have something like this...
String inputExpression;
cin >> inputExpression; // User enters 5 1/4 + 3 3/4 - for this example
int firstStop inputExpression.find_first_of(" /");
if (firstStop == String::npos) cerr << "UH OH!!!"; // This means the user didn't input right
if (inputExpression.at(firstStop) == ' ') //if this is true it must be a mixed number
//use substr to extract the whole number
if (inputExpression.at(firstStop) == '/') //This means it was just a fraction
//use substr to extract the numerator
----
Then you can use find_first_of("+-*/", previousBreak); to find the position of the operator in the String and evaluate that. Good luck, hope this helps.
--- Edit
I realized I didn't explain this well above. The find_first_of(char*) function searches the string for the first occurance of any character passed as the argument. That's why find_first_of(" /") can be used to find either the first space or the first slash.
In the use for finding the operator (you would also use this if the expression was a mixed number) find_first_of(char*, int) the char* again is the list of characters to search for, and the int is the starting position to begin the search. This way it doesn't always find the same thing.
|
|
|
|
|
Here's a stumper for you gurus out there. Have any of you used the file association or drag and drop to drop a file on you application to automatically start your app and open the file? Then you are aware of the CWinApp member, m_lpCmdLine. This member lpstring contains the full path of the file you dropped on the application or double clicked to open. Here's a puzzler for you! Have you ever tried to open the data file using similar code?
CFile File;
File.Open(m_lpCmdLine)
Then you probably are aware the File.Open will fail on a bad path.
However, if you create a CString variable sPath and set it equal exactly to the path m_lpCmdLine contains...presto...it opens.
Does anyone know why?
-- modified at 13:45 Sunday 18th March, 2007
Someone from the CodeGuru board has suggested the following...
The reason for this behavior is the operating system places quotes around the file name so that it can be interpreted as a single command line parameter in case there are spaces in the path.
I haven't investigated exactly where the quotes get stripped off in MFC, but it's probably in CCmdLineInfo or CDocTemplate.
So, in other words, the two strings are not identical. If you want to use CFile to open the command line directly you will have to remove the quotes first.
...this has merit for investigating and I will post the results once I test this.
Here's a snippit of the code.
void CApplicationApp::OnFileNew()<br />
{<br />
UINT nStrLen = 0;<br />
UINT nStrCount = 0;<br />
char lpszCmdStr[_MAX_PATH];<br />
CString strCWD;<br />
CString strFilename;<br />
CFile File;<br />
CError Error;<br />
CMiscUtil Util;<br />
<br />
if (m_lpCmdLine[0] != '\0')<br />
{<br />
strCWD = strFilename = m_lpCmdLine;<br />
}<br />
else<br />
{<br />
strcpy(lpszCmdStr, m_pszHelpFilePath);<br />
nStrLen = strlen(lpszCmdStr);<br />
while (lpszCmdStr[nStrLen] != '\\')<br />
{<br />
lpszCmdStr[nStrLen] = 0;<br />
--nStrLen;<br />
}<br />
g_strProgramPath = lpszCmdStr;<br />
strFilename = g_strProgramPath + "Project" + ".fil";<br />
}<br />
<br />
MessageBox(0, strFilename, "Debug Message #1", MB_OK);<br />
<br />
if (File.Open(strFilename, CFile::modeRead))<br />
{<br />
File.Close();<br />
theApp.OpenDocumentFile(strFilename);<br />
}<br />
else if (File.Open(strFilename, CFile::modeCreate | CFile::modeWrite))<br />
{<br />
File.Write(&Project, sizeof(class CProjectData));<br />
File.Close();<br />
strFilename = g_strProgramPath + "\\Project" + ".idx";<br />
if (File.Open(strFilename, CFile::modeCreate | CFile::modeWrite))<br />
{<br />
File.Close();<br />
strFilename = g_strProgramPath + "\\Project" + ".fdb";<br />
if (File.Open(strFilename, CFile::modeCreate | CFile::modeWrite))<br />
{<br />
File.Close();<br />
}<br />
theApp.OpenDocumentFile(strFilename);<br />
}<br />
}<br />
else<br />
{<br />
Error.Message(47);<br />
}<br />
}
|
|
|
|
|