// GobiImgMgrDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GobiImgMgr.h"
#include "GobiImgMgrDlg.h"
#include <GobiAPI.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// global pointer to self
CGobiImgMgrDlg* g_This = NULL;

#define TIMER_DeviceSearch				WM_APP + 0x1000
#define WM_USER_NOTIFY_DEVICE_REMOVAL	WM_APP + 0x1001
#define WM_USER_NOTIFY_NEW_SMS          WM_APP + 0x1002

// Session state callback handler
static void GOBICALLBACK DeviceRemovalCallback(ULONG nStatus)
{
	g_This->PostMessage(WM_USER_NOTIFY_DEVICE_REMOVAL, (WPARAM)nStatus, NULL);
}


LRESULT CGobiImgMgrDlg::OnNotifDeviceRemoval(WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);

	// Shutdown API
	QCWWANDisconnect();
	
	LST_AMSS.ResetContent();
	LST_UQCN.ResetContent();
	btnSetPreference.EnableWindow(FALSE);

	// start timer to search for available device
	SetTimer(TIMER_DeviceSearch, 1000, NULL);
	UpdateData(FALSE);	// update screen

	return 0;
}



// CGobiImgMgrDlg dialog

CGobiImgMgrDlg::CGobiImgMgrDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGobiImgMgrDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGobiImgMgrDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_MODEMSEARCH, LBL_MODEMSEARCH);
	DDX_Control(pDX, IDC_AMSS, LST_AMSS);
	DDX_Control(pDX, IDC_UQCN, LST_UQCN);
	DDX_Control(pDX, IDC_SET_IMAGE_PREFERENCE, btnSetPreference);
	DDX_Control(pDX, IDC_EDIT1, edEdit1);
}

BEGIN_MESSAGE_MAP(CGobiImgMgrDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
	ON_WM_SIZE()
#endif
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_USER_NOTIFY_DEVICE_REMOVAL, OnNotifDeviceRemoval)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_SET_IMAGE_PREFERENCE, &CGobiImgMgrDlg::OnBnClickedSET_IMAGE_PREFERENCE)
	ON_BN_CLICKED(IDC_BUTTON1, &CGobiImgMgrDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CGobiImgMgrDlg::OnBnClickedButton2)
END_MESSAGE_MAP()


// CGobiImgMgr message handlers

BOOL CGobiImgMgrDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	g_This = this;	
    SetTimer(TIMER_DeviceSearch, 1000, NULL);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGobiImgMgrDlg::OnTimer(UINT_PTR nIDEvent)
{
	switch (nIDEvent)
	{
		// search for available device
		case TIMER_DeviceSearch:
			KillTimer(nIDEvent);
			if (DeviceSearch())
			{
				// device found

				// Assign device removal callback handler
				SwiSetDeviceRemovalCallback(DeviceRemovalCallback);

				FillImagesList();
				
    	        LBL_MODEMSEARCH.SetWindowText(_T("Connected to Device"));


			}
			else
			{
				// Device not found
    	        LBL_MODEMSEARCH.SetWindowText(_T("Unable find device"));
				SetTimer(TIMER_DeviceSearch, 1000, NULL);
            }
			break;
		default:
			break;
	}

	CDialog::OnTimer(nIDEvent);
}

BOOL CGobiImgMgrDlg::DeviceSearch()
{
	// Attempt to connect to first available device
	if (!QCWWANConnect())
	{
        //m_editStatus.SetWindowText(_T("Connected to Device"));
        //UpdateData(TRUE);
		return TRUE;
	}
	
	return FALSE;
}


#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CGobiImgMgrDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
	if (AfxIsDRAEnabled())
	{
		DRA::RelayoutDialog(
			AfxGetResourceHandle(), 
			this->m_hWnd, 
			DRA::GetDisplayMode() != DRA::Portrait ? 
			MAKEINTRESOURCE(IDD_GOBIIMGMGR_DIALOG_WIDE) : 
			MAKEINTRESOURCE(IDD_GOBIIMGMGR_DIALOG));
	}
}
#endif

// Maximum length for an AMCC/UQCN Image file build info string (including NULL)
const ULONG MBN_BUILD_ID_LEN = 32;
// Maximum length for  an AMCC/UQCN Image fileunique image ID
const ULONG MBN_UNIQUE_ID_LEN = 16;
struct SWI_STRUCT_CarrierInfor
{
	ULONG FirmwareId;
	WCHAR BuildIdG5k[MBN_BUILD_ID_LEN]; //UQCN BID Used by Gobi5k
	WCHAR BuildIdG3k[MBN_BUILD_ID_LEN]; //UQCN BID Used by 9090/G3K
	ULONG CarrierId;
	ULONG Region;
};

static const SWI_STRUCT_CarrierInfor Carrier_info_table[] =
{
    {0x00000000,	L"FACTORY",			L"",						CARRIER_FACTORY,		REGION_NORTH_AMERICA },
    {0x00010000,	L"VZW",				L"D3600-UQSUVH",			CARRIER_VERIZON,		REGION_NORTH_AMERICA },
    {0x00020000,	L"SPRINT",			L"D3600-UQSUSH",			CARRIER_SPRINT,			REGION_NORTH_AMERICA },
    {0x00030000,	L"ATT",				L"D3200-UQSUAN",			CARRIER_ATT,			REGION_NORTH_AMERICA },
    {0x00040000,	L"VODAFONE",		L"D3200-UQSUVN",			CARRIER_VODAFONE,		REGION_EUROPE },
    {0x00040000,	L"VODA",			L"",						CARRIER_VODAFONE,		REGION_EUROPE },
    {0x00050000,	L"TMOBILE",			L"D3200-UQSULN",			CARRIER_TMOBILE,		REGION_EUROPE },
    {0x00060000,	L"TELUS",			L"D3200-UQSUTN",			CARRIER_TELUS,			REGION_NORTH_AMERICA },
    {0x00070000,	L"ALLTEL",			L"",						CARRIER_ALLTEL,			REGION_NORTH_AMERICA },
    {0x00090000,	L"GENERIC",			L"",						CARRIER_GENERIC,		REGION_GLOBAL },
    {0x000A0000,	L"GENERIC",			L"",						CARRIER_GENERIC,		REGION_NORTH_AMERICA },
    {0x000B0000,	L"ORANGE",			L"D3200-UQSUON",			CARRIER_ORANGE,			REGION_EUROPE },
    {0x000C0000,	L"TELEFONICA",		L"D3200-UQSUHN",			CARRIER_TELEFONICA,		REGION_EUROPE },
    {0x000D0000,	L"NTTDOCOMO",		L"",						CARRIER_NTT_DOCOMO,		REGION_ASIA },
    {0x000E0000,	L"TELECOMITALIA",	L"D3200-UQSUIN",			CARRIER_TELECOM_ITALIA,	REGION_EUROPE },
    {0x000F0000,	L"TELESTRA2",		L"",						CARRIER_TELSTRA2,		REGION_AUSTRILIA },
    {0x00100000,	L"GRUPOIUSACALL",	L"",						CARRIER_GRUPO_IUSACALL,	REGION_NORTH_AMERICA },
    {0x00110000,	L"BELL",			L"D3200-UQSUCN",			CARRIER_BELL,			REGION_NORTH_AMERICA },
    {0x00120000,	L"TELECOMNZ",		L"",						CARRIER_TELECOM_NZ,		REGION_AUSTRILIA },
    {0x00130000,	L"CHINAMOBILE",		L"",						CARRIER_CHINA_MOBILE,	REGION_ASIA },
    {0x00140000,	L"OMH",				L"",						CARRIER_OMH,			REGION_GLOBAL },
    {0x00160000,	L"AMXTELCEL",		L"",						CARRIER_AMX_TELCEL,		REGION_LATIN_AMERICA },
    {0x00170000,	L"NORF",			L"",						CARRIER_NORF,			REGION_GLOBAL },
    {0x00180000,	L"FACTORY",			L"",						CARRIER_FACTORY,		REGION_GLOBAL },
    {0x00190000,	L"BRASILVIVO",		L"",						CARRIER_BRASIL_VIVO,	REGION_LATIN_AMERICA },
    {0x001A0000,	L"SWISSCOM",		L"",						CARRIER_SWISSCOM,		REGION_EUROPE },
    {0x0,			L"SOFTBANK",		L"",						CARRIER_SOFTBANK,		REGION_ASIA },
    {0x0,			L"TELSTRA",			L"",						CARRIER_TELSTRA,		REGION_AUSTRILIA },
    {0x0,			L"BIGPOND",			L"",						CARRIER_GENERIC,		REGION_AUSTRILIA },
    {0x0,			L"NETINDEX",		L"",						CARRIER_NETINDEX,		REGION_ASIA },
    {0x0,			L"DNA",				L"",						CARRIER_DNA,			REGION_EUROPE },
    {0x0,			L"ROGERS",			L"D3200-UQSURN",			CARRIER_ROGERS,			REGION_NORTH_AMERICA },
    {0x0,			L"VERIZON",			L"",						CARRIER_VERIZON,		REGION_NORTH_AMERICA },
    {0x0,			L"GENEU",			L"",						CARRIER_GENERIC,		REGION_EUROPE },
    {0x0,			L"GENNA",			L"",						CARRIER_GENERIC,		REGION_NORTH_AMERICA },
    {0x0,			L"DOCOMO",			L"",						CARRIER_NTT_DOCOMO,		REGION_ASIA },
    {0x0,			L"0",				L"",						CARRIER_GENERIC,		REGION_GLOBAL },
    {0x0,			L"1",				L"",						CARRIER_SOFTBANK,		REGION_ASIA },
    {0x0,			L"2",				L"",						CARRIER_TELSTRA,		REGION_AUSTRILIA },
    {0x0,			L"3",				L"",						CARRIER_GENERIC,		REGION_AUSTRILIA }, // BigPond
    {0x0,			L"4",				L"",						CARRIER_ATT,			REGION_NORTH_AMERICA },
    {0x0,			L"5",				L"",						CARRIER_VERIZON,		REGION_NORTH_AMERICA },
    {0x0,			L"6",				L"",						CARRIER_NETINDEX,		REGION_ASIA }, // NetIndex
    {0x0,			L"7",				L"",						CARRIER_DNA,			REGION_EUROPE }, // DNA
    {0x0,			L"8",				L"",						CARRIER_BELL,			REGION_NORTH_AMERICA },
    {0x0,			L"9",				L"",						CARRIER_TELUS,			REGION_NORTH_AMERICA },
    {0x0,			L"10",				L"",						CARRIER_ROGERS,			REGION_NORTH_AMERICA }, // Rogers
    {0x0,			L"11",				L"",						CARRIER_SPRINT,			REGION_NORTH_AMERICA },
    {0x0,			L"12",				L"",						CARRIER_TELEFONICA,		REGION_EUROPE },
    {0x0,			L"216",				L"",						CARRIER_NTT_DOCOMO,		REGION_ASIA },
    {0x0,			L"",				L"D3200-UQSUGN",			CARRIER_GENERIC,		REGION_GLOBAL }, //Generic UMTS
    {0x0,			L"",				L"D3600-UQSUGH",			CARRIER_GENERIC,		REGION_GLOBAL }, //Generic CDMA
    {0x0,			L"",				L"D3600-UQSUAH",			CARRIER_AERIS,			REGION_NORTH_AMERICA }
    //{0x0,			L"", 				L"D3600-UQSUCH",			CARRIER_CHINA_TELECOM,	REGION_ASIA }, //CARRIER_CHINA_TELECOM not defined in QMI spec
    //{0x0,			L"", 				L"D3600-UQSUNH",			CARRIER_ANATEL, 		REGION_LATIN_AMERICA } //CARRIER_ANATEL not defined in QMI spec
};

ULONG GetCarrierFromUqcnBuildIdG3k(const WCHAR * BuildId)
{
	ULONG carrier = UNKNOWN;
	//TBD_FUNCTION(GetCarrierFromUqcnBuildIdG3k);
	int iTableSize = sizeof(Carrier_info_table)/sizeof(SWI_STRUCT_CarrierInfor);
	for(int i = 0; i < iTableSize; i++)
	{
		if(wcscmp(Carrier_info_table[i].BuildIdG3k, L"") &&
			wcsstr(BuildId, Carrier_info_table[i].BuildIdG3k)
			)

		{
			carrier = Carrier_info_table[i].CarrierId;
			return carrier;
		}
	}
	return carrier;
}

ULONG GetRegionFromUqcnBuildIdG3k(const WCHAR * BuildId)
{
	//TBD_FUNCTION(GetRegionFromUqcnBuildIdG3k);
	ULONG region = UNKNOWN;
	int iTableSize = sizeof(Carrier_info_table)/sizeof(SWI_STRUCT_CarrierInfor);
	for(int i = 0; i < iTableSize; i++)
	{
		if(wcscmp(Carrier_info_table[i].BuildIdG3k, L"") &&
			wcsstr(BuildId, Carrier_info_table[i].BuildIdG3k)
			)
		{
			region = Carrier_info_table[i].Region;
			return region;
		}
	}
	return region;
}


void ParseStoredImageList(ULONG * pImageListSize, BYTE *pImageList, storedImageList* pStoredImageList)
{
	BYTE* pWorker = pImageList;
	pStoredImageList->pNumImageType = pWorker;
	BYTE numImageType = *pWorker;
	pWorker++;

	for (int i = 0; i < numImageType; i++)
	{
		storedImageSubList* pImgList = &(pStoredImageList->ArrImageList[i]);
		
		pImgList->pImageType = pWorker;
		pWorker++;

		pImgList->pMaxImage = pWorker;
		pWorker++;

		pImgList->pIndexRunning = pWorker;
		pWorker++;

		pImgList->pNumOfImageElement = pWorker;
		BYTE numImageElement = *pWorker;
		pWorker++;

		for (int j = 0; j < numImageElement; j++)
		{
			pImgList->pImageElements[j] = (imageElement*)pWorker;
			BYTE buildIdLen = pImgList->pImageElements[j]->buildIdLen;
			pWorker += (19 + buildIdLen); //storageIndex + failureCount + arrUniqueId[16] + BuildIdLen = 19
		}
	}
}

void CGobiImgMgrDlg::OnBnClickedSET_IMAGE_PREFERENCE()
{
    ULONG nImgListSize;
	BYTE imageList[255];
	ULONG nImageTypesSize = 2;
    BYTE nModemIndex = 0xFF;
    
	ULONG result;
	BYTE* pImageList;

	pImageList = (BYTE*) malloc(3072);
	ULONG imageListSize = 3072;
	memset(pImageList,0, 3072);
	memset(imageList, 0, sizeof(imageList));


	GetStoredImages(&imageListSize, pImageList);
	storedImageList storedImgList;
	ParseStoredImageList(&imageListSize, pImageList,&storedImgList);
	
	BYTE AMSSChoice, UQCNChoice;
	AMSSChoice=LST_AMSS.GetCurSel();
	UQCNChoice=LST_UQCN.GetCurSel();
	
	BYTE* AMSS_unique_id;
	CHAR* AMSS_build_id;
	BYTE AMSS_build_id_len;

	BYTE* UQCN_unique_id;
	CHAR* UQCN_build_id;
	BYTE UQCN_build_id_len;

	for (int i = 0; i < *(storedImgList.pNumImageType); i++)
	{
		BYTE imgType = *(storedImgList.ArrImageList[i].pImageType);

		if (imgType==0)//AMSS
		{
			AMSS_build_id_len=storedImgList.ArrImageList[i].pImageElements[AMSSChoice]->buildIdLen;
			AMSS_build_id=storedImgList.ArrImageList[i].pImageElements[AMSSChoice]->szBuildId;
			AMSS_unique_id=storedImgList.ArrImageList[i].pImageElements[AMSSChoice]->arrUniqueId;
		}
		else if (imgType==1)//UQCN
		{
			UQCN_build_id_len=storedImgList.ArrImageList[i].pImageElements[UQCNChoice]->buildIdLen;
			UQCN_build_id=storedImgList.ArrImageList[i].pImageElements[UQCNChoice]->szBuildId;
			UQCN_unique_id=storedImgList.ArrImageList[i].pImageElements[UQCNChoice]->arrUniqueId;
		}
	}
	
	
	
	BYTE* pWork=imageList;
	*pWork=2;//num_entries
	pWork++;

	*pWork=0;//image_type, 0 modem image AMSS
	pWork++;
	memcpy(pWork, AMSS_unique_id, 16);//AMSS unique_id
	pWork+=16;
	*pWork=AMSS_build_id_len;//AMSS build_id_len
	pWork++;
	memcpy(pWork, AMSS_build_id, AMSS_build_id_len);//AMSS build id
	pWork+=AMSS_build_id_len;

	*pWork=1;//image_type, 1 PRL UQCN
	pWork++;
	memcpy(pWork, UQCN_unique_id, 16);//UQCN unique_id
	pWork+=16;
	*pWork=UQCN_build_id_len;//UQCN build_id_len
	pWork++;
	memcpy(pWork, UQCN_build_id, UQCN_build_id_len);//UQCN build id
	pWork+=UQCN_build_id_len;


	nImgListSize=pWork-imageList;
	nImageTypesSize=2;
	BYTE imageTypes[255] = {0};
    result = SetImagesPreference(
                                nImgListSize, 
                                &imageList[0], 
                                0,// 1 to force a re-download, 0 to skip download if the firmware is already there
                                255,//let the firmware to decide where to storage the image
                                &nImageTypesSize,
                                &imageTypes[0]);
								
	if (result==0)
		ResetDevice();
	else
	{
		if (result==0x42F)
		{
			CString errmsg;
			errmsg.Format(L"SetImagesPreference returned error %d", result-1000);
			MessageBox(errmsg, L"Error", MB_ICONERROR);
		}
	}
	if (pImageList) free(pImageList);
}

void CGobiImgMgrDlg::FillImagesList()
{
	//FirmwareID is actually string of PRIID... 
	//Try to get the UQCN Build ID string
	BYTE* pImageList;
	pImageList = (BYTE*) malloc(3072);
	ULONG imageListSize = 3072;
	memset(pImageList,0, 3072);
	
	LST_AMSS.ResetContent();
	LST_UQCN.ResetContent();

	ULONG rCode = GetStoredImages(&imageListSize, pImageList);
	if(rCode)
	{
		if (rCode==0x42F)
			MessageBox(L"This module is not supported\r\n", L"Error", MB_ICONINFORMATION);
		else
		{
			CString errmsg;
			errmsg.Format(L"GetStoredImages returned error %d", rCode-1000);
			MessageBox(errmsg, L"Error", MB_ICONERROR);
		}
	}
	else
	{
		storedImageList storedImgList;
		ParseStoredImageList(&imageListSize, pImageList,&storedImgList);
		for (int i = 0; i < *(storedImgList.pNumImageType); i++)
		{
			BYTE imgType = *(storedImgList.ArrImageList[i].pImageType);

			for (int j=0;j<*(storedImgList.ArrImageList[i].pNumOfImageElement);j++)
			{
				WCHAR wcsBuildId[50];
				memset(wcsBuildId, 0, sizeof(wcsBuildId));
				MultiByteToWideChar(CP_ACP , 0, (CHAR*) storedImgList.ArrImageList[i].pImageElements[j]->szBuildId, storedImgList.ArrImageList[i].pImageElements[j]->buildIdLen, wcsBuildId, 50);

				WCHAR wcsUniqueId[16*2+1];
				memset(wcsUniqueId, 0, sizeof(wcsUniqueId));
				wsprintf(wcsUniqueId, L"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[0],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[1],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[2],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[3],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[4],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[5],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[6],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[7],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[8],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[9],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[10],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[11],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[12],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[13],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[14],
					storedImgList.ArrImageList[i].pImageElements[j]->arrUniqueId[15]					
				
				);
				if (imgType==0)
				{	
					CString temp;
					temp=wcsBuildId;
					temp+=L" ";
					temp+=wcsUniqueId;
					LST_AMSS.AddString(temp);
				}
				else if (imgType==1)
				{
					CString temp;
					temp=wcsBuildId;
					temp+=L" ";
					temp+=wcsUniqueId;
					LST_UQCN.AddString(temp);

					//wprintf (L"UQCN %s\r\n", wcsBuildId);	
				}
			}

			if (imgType==0)
			{
				LST_AMSS.SetCurSel(*(storedImgList.ArrImageList[i].pIndexRunning));
	
			}
			else if (imgType==1)
			{
				LST_UQCN.SetCurSel(*(storedImgList.ArrImageList[i].pIndexRunning));

			}
		}

		btnSetPreference.EnableWindow(TRUE);
	}
	if (pImageList) free(pImageList);
}

void CGobiImgMgrDlg::OnCancel() 
{
	// clear callback handlers
	SwiSetDeviceRemovalCallback(NULL);

	// disconnect from device
	QCWWANDisconnect();
    g_This = NULL;
	
	CDialog::OnCancel();
}

/////////////////////////////////////////////////////////////////////////////
//
//	Function	:	OnOK
//
//	Description	:	Handler for IDOK
//
//	Arguments	:	None
//
//	Returns		:	None
//
//	Comments	:	
//
/////////////////////////////////////////////////////////////////////////////
void CGobiImgMgrDlg::OnOK() 
{
	OnCancel();
}
void CGobiImgMgrDlg::OnBnClickedButton1()
{
	// TODO: Add your control notification handler code here
	ULONG SarState;
	ULONG ret;
	ret=GetRfSarState(&SarState);
	if (ret!=0)
	{
		CString temp;
		temp.Format(L"GetRfSarState error %d", ret);
		edEdit1.SetWindowTextW(temp);
	}
	else
	{
		CString temp;
		temp.Format(L"GetRfSarState return %d", SarState);
		edEdit1.SetWindowTextW(temp);
	}
}

void CGobiImgMgrDlg::OnBnClickedButton2()
{
	// TODO: Add your control notification handler code here
	ULONG SarState;
	ULONG ret;
	CString temp;
	edEdit1.GetWindowText(temp);
	swscanf(temp, L"%d", &SarState);

	ret=SetRfSarState(SarState);
	if (ret!=0)
	{
		
		temp.Format(L"SetRfSarState error %d", ret);
		edEdit1.SetWindowTextW(temp);
	}
}
