VC++ simple prog HELP
i'm trying to learn to use visual c++ 6.0 and i'm trying to make a simple application that will add two integers and display the result. i found tutorials on how to enter text into a text box and then use a button to display that text in a message box. i can't seem to get to do the same thing to the integers though. does anyone have any links to specific tutorials (couldn't find anything that would help me on the net) or suggestions that i might try. thanx
TheForgers tutorial is a pretty good one...
...or you can post the code you've got and we'll help you get that working.
Remember, if you post your code, to post any resource files and headers you have made, so we can compile the program and run it in a decent debugger.
There is no magic to Windows programming. I recommend exploring the deep ocean even if you do not know how to swim. In the end you will become a very good swimmer.
that was very deep and meaningful kuphryn. but lets help out anyway.
Okay, its sounds like you know how to create the edit boxes and buttons. what you need to do is capture the message that is sent when the button is clicked, and place your code there.
That can be done by checking the LOWORD of the wParam when the WM_COMMAND message occurs, to see if it matches the ID of your button. eg:
The code will have to ensure that there is text in both controls, then convert it to numbers, and add it together. Then convert the sum back to a string and display it. ie:
case ID_BUTTON: //Whatever ID you gave it
and thats it. ill post a full proggy in a tic.
char *str1=new char; //Allocate strings to retrieve the input
char *str2=new char; //ditto
//The above lines retrieve the text of the edit controls hInput1 and hInput2
num1=atol(str1); //converts string to long int, needs stdlib.h
ltoa(num1+num2,str1,10); //convert long int to string. 10 is the radix
SetWindowText(hDisplay,str1); //hDisplay is a control with a caption, ie an edit control
the attached file is the source file for the proggy. what you should do is create a new win32 application, just an empty project, and add the file to it. it should compile fine. it worked for me.
i think that should help me for now