#include <windows.h>
#include "resource.h"

extern BOOL bUseIdentityData ;
extern WCHAR wUserName [], wDomain [], wPassword [] ;

BOOL CALLBACK IdentityDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_INITDIALOG:
		{
			char out [256] ;

			WideCharToMultiByte(CP_ACP, 0, wUserName, -1, out, sizeof(out), NULL, NULL) ;
			SetDlgItemText (hDlg, IDC_USER, out) ;
			WideCharToMultiByte(CP_ACP, 0, wDomain, -1, out, sizeof(out), NULL, NULL) ;
			SetDlgItemText (hDlg, IDC_DOMAIN, out) ;
			WideCharToMultiByte(CP_ACP, 0, wPassword, -1, out, sizeof(out), NULL, NULL) ;
			SetDlgItemText (hDlg, IDC_PASSWORD, out) ;

			if (bUseIdentityData == TRUE)
			{
				CheckDlgButton (hDlg, IDC_CHECK1, BST_CHECKED) ;
			}
			else
			{
				CheckDlgButton (hDlg, IDC_CHECK1, BST_UNCHECKED) ;
			}

			SetFocus (GetDlgItem (hDlg, IDC_EDIT1)) ;
			return FALSE ;
		}
		case WM_COMMAND:
		{
			if (LOWORD(wParam) == IDCANCEL)
			{
				EndDialog (hDlg, 0) ;
			}
			else if (LOWORD(wParam) == IDOK)
			{
				if (IsDlgButtonChecked (hDlg, IDC_CHECK1) == BST_CHECKED)
				{
					bUseIdentityData = TRUE ;
				}
				else
				{
					bUseIdentityData = FALSE ;
				}

				char in [256] ;

				GetDlgItemText (hDlg, IDC_USER, in, sizeof(in)) ;
				MultiByteToWideChar (CP_ACP, 0, in, -1, wUserName, 256) ;
				GetDlgItemText (hDlg, IDC_DOMAIN, in, sizeof(in)) ;
				MultiByteToWideChar (CP_ACP, 0, in, -1, wDomain, 256) ;
				GetDlgItemText (hDlg, IDC_PASSWORD, in, sizeof(in)) ;
				MultiByteToWideChar (CP_ACP, 0, in, -1, wPassword, 256) ;


				EndDialog (hDlg, 0) ;
			}

			return TRUE ;
		}

	}

	return FALSE ;
}
