Dialog boxes

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)
Can someone tell me a site where i can find a good Visual C++ tutorial?
And can I somehow design the main window like like I create a dialog box?
Last edited on
closed account (z05DSL3A)
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.




References
[win] http://en.wikipedia.org/wiki/Win32_API
[mfc] http://en.wikipedia.org/wiki/Microsoft_Foundation_Class_Library
[wtl] http://en.wikipedia.org/wiki/WTL
[clr] http://en.wikipedia.org/wiki/Common_Language_Runtime
[cli] http://en.wikipedia.org/wiki/C%2B%2B/CLI
[mc++] http://en.wikipedia.org/wiki/Managed_C%2B%2B
[msdn] http://msdn.microsoft.com/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
INT_PTR CALLBACK Sqrt(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{   
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;
    	case WM_COMMAND:
		if (LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		else if(LOWORD(wParam) == IDCAL)		//new Button"Calculate"
		{
			int number = GetDlgItemInt(hDlg, IDC_SQRTVAL, &bSuccess, FALSE);
			double res = Sroot(number);
			WCHAR txt[100]=L"";
			wsprintf(txt, L"%f", res);
            		SetDlgItemText(hDlg, IDC_SQRTRES,txt);
		}
		break;
	}
	return (INT_PTR)FALSE;
}
Last edited on
The GetDlgItemInt() function can somehow take negative numbers?
Topic archived. No new replies allowed.