How can I create a dialog box which request data from the user and pass it to a function and then print on the screen the result given by the function?
You can create a form in Visual C++ that is shown, once the submit button is pressed the value is passed into a function. You will need to know the basics of Visual C++ (or another C++ GUI Toolkit)
There are a few paths to follow in Windows™ programming, but broadly speaking there are two main paths, Native and .NET
Native
First you have Windows API [win] (also call Win API, often called Win32 API), this is core set of application programming interfaces (APIs) available int the Windows™ operating system. This is the base of all windows programming. There are a number of 'wrapper' libraries that are designed to allow the programmer to use the APIs in a more abstract manner, eg:
~ Microsoft Foundation Class Library[mfc] (also Microsoft Foundation Classes or MFC)
~ Windows Template Library[wtl] (WTL)
.NET
The Common Language Runtime[clr] (CLR) is the virtual machine component of Microsoft's .NET initiative. To use this you will have to write your programs in C++/CLI [cli], Microsoft's language specification standardized by Ecma as ECMA-372 (available in Visual C++ 2005 and 2008) not to be confused with command line interface. There is also Manage extensions for C++[mc++] but I think that is considered obsolete.
A good Visual C++ tutorial?
For native (Windows API) you could start here:
http://www.winprog.org/tutorial/start.html
then go on to Microsoft Developers Network[msdn] (MSDN)
MSDN may be a good place to start of .net stuff, I have yet to find a good 'tutorial' site for C++/CLI.
INT_PTR CALLBACK Sqrt(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ int number;
double res;
HWND hwnd;
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case IDC_SQRTVAL:
BOOL bSuccess;
number = GetDlgItemInt(hwnd, IDC_SQRTVAL, &bSuccess, FALSE);
res=Sroot(number);
case IDC_SQRTRES:
SetDlgItemText(hwnd, IDC_SQRTRES,//?????//);
case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
double Sroot(double a)
{double f;
if(a>=0)
f=sqrt(a);
else
f=-1;
return(f);
}
I have this code for a dialog box with two edit text fields:IDC_SQRTRES and IDC_SQRTVAL
i'm trying to take an integer value from IDC_SQRTVAL and pass it to the Sroot function and get a value to res.in the place of //???//
i must put a string to display or i can display directly the int?What shall I do?
I've tried this:
1 2
case IDC_SQRTRES:
SetDlgItemText(hwnd, IDC_SQRTRES,result.c_str());
but i don't really know how to transform res into the result string and i get the following error:
1>.\Mathematical Calculator.cpp(236) : error C2664: 'SetDlgItemTextW' : cannot convert parameter 3 from 'const char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
I use Visual C++ 2005