The programme is as follows:
#include <windows.h>
#include <stdio.h> // swprintf
#include <math.h> // sqrt
#include "Resource.h"
using namespace std;
//---------------------------------------------------------------------------
HWND hWnd;
HINSTANCE hInst;
const int bufSize = 1024;
LPWSTR MyString = new WCHAR[bufSize];
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK DlgProc2(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE,LPSTR lpCmdLine, int nCmdShow)
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
//hInst = hInstance;
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MyDialog),
hWnd, reinterpret_cast<DLGPROC>(DlgProc));
delete MyString;
return FALSE;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_DESTROY:
EndDialog(hWndDlg, 0);
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
// get text from the input
HWND hwndText;
hwndText = GetDlgItem(hWndDlg, IDC_MyEdit);
GetDlgItemText(hWndDlg, IDC_MyEdit, MyString, bufSize);
OutputDebugString(MyString);
DialogBox(hInst, MAKEINTRESOURCE(IDD_MyDialog2),hWnd, reinterpret_cast<DLGPROC>(DlgProc2));
return TRUE;
case IDCANCEL:
EndDialog(hWndDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
LRESULT CALLBACK DlgProc2(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_INITDIALOG:
float temp, sqrtRoot;
temp = _wtof(MyString);
sqrtRoot = sqrt(temp);
wchar_t ms[100];
swprintf(ms, 100, L"The quare root is %g !", sqrtRoot);
SetDlgItemText(hWndDlg, IDC_MyStatic2, ms);
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
EndDialog(hWndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hWndDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
//---------------------------------------------------------------------------