|
hiii i'm making a Calculator in Visual C++ but having sum probs, in code i've created all the buttons n now i don't know how to add two numbers wich are pressed on buttons.. Can neone help me out..
Paritosh Tripathi
B.Tech. (C.S.)
|
|
|
|
|
Take a look at CP, I think you can find some example calculators.
But it is not a trivial problem. You have to keep track of the states that you are in. Look at the book "Practical Statecharts in C/C++" by Miro Samek for a description of how to create a robust solution.
But if all that you are looking for is adding two numbers (i.e. no other functionality for this program) your states can be trivial. If you only have the digits 0-9 and a + and =, I think you can get by doing the following:
For each number pressed: Add that digit to the display field
For +: store the integer in the display and prepare to clear the display when the next number is pressed.
For =: get the number currently displayed and ADD it to the stored number.
Draw a state diagram to make sure you cover various cases, such as pressing 1010 + = : this should have the effect of 1010 + 1010 = 2020.
+ 1010 = : this should have the effect of 0 + 1010 = 1010
And what about 1010 + + = : 1010 + 1010 + 1010 = 3030
The book I mention covers a calculator example and should be very helpful in general for learning how to handle statemachines.
|
|
|
|
|
hi techno,
ok, lets sum up.
there are many ways to make a calculator, that i think my VisualCalc is not exactly what you are designing, am i wrong ?
you're having buttons on the GUI, so, i think you have to store the result in a member each time it is recalculated.
as you seem very beginner, i'll consider you're calculation engine class is written within the UI dialogBox class (still wrong with this ? )
- so, add a member in the class to store the result (lets say float m_fResult; )
- then, when you press an operation button (like '+' ) you have to store somewhere that it is an addition to be performed (design an type which enumerated the possible operations, and make a member of that type (say m_Operation ) in your class which will store the operation to perform (here, ADDITION).
- then, the user types its number, and when then equal button is pressed ('=' ), you test the m_Operation variable.
if m_Operation == ADDITION Then
Add m_Result + lastly typed value
store the new value into m_Result
End If
any more help ?
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
...hello every body,
well the night calmed me down, and all your answers were nice enough.
so, not only i decided do delete the outrageous post, but i too wanted to say this here.
i'm very sorry if some of you didn't understand my reaction. i had to say this, because i was very angry because of thy stupid guy. that's all.
have a good day all of you (yeah, i sad ALL OF YOU, even you, yes, YOUUUU who don't like me )
|
|
|
|
|
tox, I just rated the above-mentioned post a 5, and it still says there's only 1 vote and the score is still 1.0. I don't understand the logic behind that. maybe the math behind that is messed up. But I still think you let someone get you a little too heated for that. People that have been around CP know that you've got some VERY good ideas and wouldn't vote you a 1 even if your answer did sound crazy. To the people who would, f*** them. Don't let them get their jollies by replying back to them like that. You're better than that
My articles
BlackDice
|
|
|
|
|
Hello Tox
While I appreciate why you are upset, I think you should delete your post. It contains profanity that's not fitting this forum or your public profile for that matter.
Regards,
Nish
|
|
|
|
|
Here is a 5 to help offset.
Don't be discouraged, you are helpful to a lot of people around here.
-- modified at 16:34 Monday 16th January, 2006
I agree with Nish, delete that post. It detracts from your character - even if you are justified in being upset.
|
|
|
|
|
mine too correct the Vote Offset
"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
|
|
|
|
|
Nish is correct. I did not expect this from tox. He was honored as one of the most useful members of 2005. I do not understand what is his need to come down to this level. Tox, pls delete that post. Let them vote whatever they want. We know that you have something to contribute to this society.
Regards,
Rajesh R. Subramanian
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
Technobizz wrote: Paritosh Tripathi
B.Tech. (C.S.)
I have heard this name before..Anyways you can look for this article
CONTROL ARRAY[^]
"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
|
|
|
|
|
U have already got the answer to you questions
but u should start refering some good book's
and there is lots of stuff on codeproject to help u
Vikas Amin
Embin Technology
Bombay
|
|
|
|
|
I have a project that I have different configurations which compile different libraries for different versions. Is there a way to link the Version resource to my configuration?
I basically want configuration A to ahve version 7.2, configuration B to ahve version 7.02 etc.
Any ideas? I asked this questions awhile back I think and got the correct answer, and I completely forgot how to do it.
Thanks.
-C
|
|
|
|
|
Wheatbread wrote: I basically want configuration A to ahve version 7.2, configuration B to ahve version 7.02 etc.
You can specify different libraries for different configurations in the project settings.
|
|
|
|
|
I've done that. But when I compile it, I want the DLL that I create to have different version numbers depending on the configuration selected.
|
|
|
|
|
VisualC++ IDE: ResourceView -> Version -> Properties -> Condition ?
|
|
|
|
|
What version of the IDE are you using VC 6.0? VS 200? what?
In VC 6.0, you can specify different preprocessor definitions for each configuration in the project.
Move your version resource into the RC2 header file.
Inside there, use the preprocessor identifiers to filter the file or product version resource data.
|
|
|
|
|
I prepared (in Visual Studio 2003 + MFC) "Dialog Based" Application. Now, I have one dialog window where I want to add two book marks.
I have two objects:
class DlgPage1 : public CPropertyPage
// variable mPage1
class DlgPage2 : public CPropertyPage
// variable mPage2
In the resource window I have done two dialogs with properties:
Style = child
Border = thin
TitleBar = true
Disabled = true
In the OnInitDialog (main window) function I have code:
mPropertySheet = new CPropertySheet("Simple PropertySheet");
mPage1 = new DlgPage1();
mPage2 = new DlgPage2();
mPropertySheet->AddPage(mPage1);
mPropertySheet->AddPage(mPage2);
mPropertySheet->Create(this, WS_CHILD | WS_VISIBLE, 0);
mPropertySheet->ModifyStyleEx(0, WS_EX_CONTROLPARENT);
mPropertySheet->ModifyStyleEx(0, WS_TABSTOP);
mPropertySheet->ModifyStyleEx(0, WS_MAXIMIZE);
// now, I want to resize windows for almost maximum size
CRect rect;
GetClientRect(&rect);
int Width = rect.Width()-7;
int mHeight = rect.Height()-7;
mPropertySheet->SetWindowPos(NULL, 7, 7, mWidth, mHeight, SWP_NOZORDER);
================
The SetWindowPos doesn't do what I expect.
Why the windows doesn't resize?
It has the size - I designed in the Resource.
Regards
mwgomez/Poland
|
|
|
|
|
gomez_a wrote: It has the size - I designed in the Resource.
And this is exactely what you request by doing this:
CRect rect;
GetClientRect(&rect);
int Width = rect.Width()-7;
int mHeight = rect.Height()-7;
mPropertySheet->SetWindowPos(NULL, 7, 7, mWidth, mHeight, SWP_NOZORDER);
If you want to maximize your widows, use GetSystemMetrics to get the screen size, and use SetWindowPos to update your window size:
int cx,cy;
cx=GetSystemMetrics(SM_CXSCREEN);
cy=GetSystemMetrics(SM_CYSCREEN);
mPropertySheet->SetWindowPos(NULL, 7, 7, cx-7, cy-7, SWP_NOZORDER);
~RaGE();
|
|
|
|
|
I have the same effect like before...
Regards
mwgomez
|
|
|
|
|
Does mPropertySheet actually represent a dialog control? Normally in MFC you'll have an instance of a C++ class for a dialog control in the header of the dialog and DDX_Control in your DoDataExchange handler to associate the class with the control. i.e.:
class CMyDialog : public CDialog
{
CEdit m_EditControl;
};
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, m_EditControl);
}
In your code it looks like you're just creating a CPropertySheet but I can't see where you're associating it with a control on your dialog.
Steve
|
|
|
|
|
I was based on the book:
"Visual C++ Bible" Richard C.Leinecker, Tom Archer.
There are samples how to create instance of the classes CPropertyPage, CPropertySheet. There is no associating with a Control and it works.
But there is also a sample - how to create this classes in existing Dialog.
I wrote it in my sample - and there is no right effect
(I think it will be a little problem, but I am interesting in solve it).
Regards
mwgomez
|
|
|
|
|
Hi,
I am not clear about your problem.
Any how, I'll tell you what I feel about this
If nFlags is nonzero in ModifyStyleEx, then the fuction calls the Win32 function SetWindowPos and redraw the window.
So please take a look into all the parameters in ModifyStyleEx function call.
better remove the function calls of ModifyStyleEx and use only SetWindowPos. Once after getting correct try to add the above three function calls of ModifyStyleEx on by one.
regards
Vallikumar A
|
|
|
|
|
It is my code:
// CSheet *sheet: class CSheet : public CPropertySheet
sheet = new CSheet("Sheet");
// CDlg1 and CDlg2 properties:
// style = child
// border = Thin
// Disabled = TRUE
//
//CDlg1 *pg1: class CDlg1 : public CPropertyPage
pg1 = new CDlg1();
//CDlg2 *pg2: class CDlg2 : public CPropertyPage
pg2 = new CDlg2();
sheet->AddPage(pg1);
sheet->AddPage(pg2);
sheet->Create(this, WS_CHILD | WS_VISIBLE, 0);
sheet->SetWindowPos(&CWnd::wndTopMost, 12, 12, 578, 578, SWP_NOZORDER);
sheet->ModifyStyleEx(0, WS_EX_CONTROLPARENT, SWP_NOZORDER);
sheet->ModifyStyleEx(0, WS_TABSTOP, SWP_NOACTIVATE);
But it still desn't work. Have I any mistake?
I thought - it is simple. I have an example from the book: "Visual C++ 6 Bible". (:
Regards
mwgomez
|
|
|
|
|
recently, I want some controls to reside in CFormView, and I want to hide the scroll bar of CFormView during program life, has someone any ideas to hide the scroll bar in CFormView? Thanks in advance.
|
|
|
|
|
|