📄 simtestdlg.cpp
字号:
wsprintf(tchStorage, TEXT("General SIM Storage:\r\n%d Used\r\n%d Free\r\n%d Total"),
dwUsed, dwTotal-dwUsed, dwTotal);
MessageBoxW(tchStorage, TEXT("SIM Usage"), MB_OK|MB_ICONINFORMATION);
}
}
void CSIMTestDlg::OnBnClickedButtonBookstatus()
{
// TODO: 在此添加控件通知处理程序代码
HRESULT hr = S_OK;
// Get phonebook status
DWORD dwUsed = 0, dwTotal = 0;
TCHAR tchPhonebook[1024] = TEXT("\0");
hr = SimGetPhonebookStatus( m_hSim,
SIM_PBSTORAGE_SIM,
&dwUsed,
&dwTotal);
if(FAILED(hr))
{
ErrorHandle(hr);
}
else
{
wsprintf(tchPhonebook, TEXT("Phonebook Usage:\r\n%d Used\r\n%d Free\r\n%d Total"),
dwUsed, dwTotal-dwUsed, dwTotal);
MessageBoxW( tchPhonebook, TEXT("SIM Phonebook"), MB_OK|MB_ICONINFORMATION);
}
}
//reads the first phonebook entry from the general SIM phonebook.
void CSIMTestDlg::OnBnClickedButtonReadphone()
{
// TODO: 在此添加控件通知处理程序代码
HRESULT hr = S_OK;
SIMPHONEBOOKENTRY simPhoneEntry;
memset(&simPhoneEntry, 0, sizeof(SIMPHONEBOOKENTRY));
simPhoneEntry.cbSize = sizeof(SIMPHONEBOOKENTRY);
hr = SimReadPhonebookEntry( m_hSim,
SIM_PBSTORAGE_SIM,
2,
&simPhoneEntry);
CString str = _T("");
str.Format(_T("%s: %s"), simPhoneEntry.lpszText , simPhoneEntry.lpszAddress);
if(FAILED(hr))
{
ErrorHandle(hr);
// return FALSE;
}
else
{
MessageBoxW(str, TEXT("phonebook entry"), MB_OK|MB_ICONINFORMATION);
}
}
void CSIMTestDlg::OnBnClickedButtonWritephone()
{
// TODO: 在此添加控件通知处理程序代码
HRESULT hr = S_OK;
CString strPhone=_T("");
// Write a phonebook entry to the SIM
SIMPHONEBOOKENTRY simPhoneEntryRead, simPhoneEntryWrite;
memset(&simPhoneEntryRead, 0, sizeof(SIMPHONEBOOKENTRY));
simPhoneEntryRead.cbSize = sizeof(SIMPHONEBOOKENTRY);
memset(&simPhoneEntryWrite, 0, sizeof(SIMPHONEBOOKENTRY));
simPhoneEntryWrite.cbSize = sizeof(SIMPHONEBOOKENTRY); //填充结构体,待写入
simPhoneEntryWrite.dwParams = SIM_PARAM_PBE_ALL;
simPhoneEntryWrite.dwAddressType = SIM_ADDRTYPE_INTERNATIONAL;
simPhoneEntryWrite.dwNumPlan = SIM_NUMPLAN_TELEPHONE;
wsprintf(simPhoneEntryWrite.lpszAddress, _T("13590526770"));
wsprintf(simPhoneEntryWrite.lpszText, _T("Jeremy"));
for(DWORD dwIndex = m_simcaps.dwMinPBIndex ; dwIndex <= m_simcaps.dwMaxPBIndex; dwIndex++)
{
hr = SimReadPhonebookEntry( m_hSim, SIM_PBSTORAGE_SIM, dwIndex,&simPhoneEntryRead);
if(FAILED(hr)) //如果条目无效,交给SimWritePhonebookEntry()写入。
{
hr = SimWritePhonebookEntry(m_hSim,
SIM_PBSTORAGE_SIM,
dwIndex,
&simPhoneEntryWrite);
if(FAILED(hr))
{
ErrorHandle(hr);
}
else
{
MessageBox(TEXT("New entry added successfully"), TEXT("SIM Write"), MB_OK);
}
}
}
}
void CSIMTestDlg::OnBnClickedButtonClearlist()
{
// TODO: 在此添加控件通知处理程序代码
UINT n = m_pNumList->GetCount();
for (UINT i=0;i <= n; i++)
{
m_pNumList->DeleteString(0);
}
m_pNumList->DeleteString(0);
m_pNumList->UpdateData(TRUE);
m_pNumList->UpdateWindow();
}
void CSIMTestDlg::OnBnClickedButtonListnum()
{
// TODO: 在此添加控件通知处理程序代码
HRESULT hr = S_OK;
DWORD dwUsed = 0, dwTotal = 0;
hr = SimGetSmsStorageStatus(m_hSim,
SIM_SMSSTORAGE_SIM,
&dwUsed,
&dwTotal);
CString strPhone=_T("");;
SIMPHONEBOOKENTRY simPhoneEntry;
memset(&simPhoneEntry, 0, sizeof(SIMPHONEBOOKENTRY));
simPhoneEntry.cbSize = sizeof(SIMPHONEBOOKENTRY);
for(DWORD dwIndex=m_simcaps.dwMinPBIndex; dwIndex <= m_simcaps.dwMaxPBIndex; dwIndex++)
{
hr = SimReadPhonebookEntry( m_hSim, SIM_PBSTORAGE_SIM, dwIndex,&simPhoneEntry);
if(SUCCEEDED(hr))
{
strPhone.Format(_T("%s: %s"),simPhoneEntry.lpszText, simPhoneEntry.lpszAddress);
m_pNumList->AddString(strPhone);
m_pNumList->UpdateData(TRUE);
m_pNumList->UpdateWindow();
}
else
{
// ErrorHandle(hr);
}
}
}
void CSIMTestDlg::OnBnClickedButtonReadsms()
{
// TODO: 在此添加控件通知处理程序代码
HRESULT hr = S_OK;
SIMMESSAGE simMessage;
memset(&simMessage, 0, sizeof(SIMMESSAGE));
simMessage.cbSize = sizeof(SIMMESSAGE);
hr = SimReadMessage( m_hSim,
SIM_SMSSTORAGE_SIM,
1,
&simMessage);
if(FAILED(hr))
{
ErrorHandle(hr);
// return FALSE;
}
else
{
MessageBoxW(simMessage.lpszMessage, TEXT("SIM Message"), MB_OK|MB_ICONINFORMATION);
}
}
void CSIMTestDlg::ErrorHandle(HRESULT hr)
{
switch(hr)
{
case SIM_E_SIMFAILURE:
MessageBoxW(_T("SIM_E_SIMFAILURE: SIM failure was detected"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMBUSY:
MessageBoxW(_T("SIM_E_SIMBUSY: SIM is busy"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMWRONG:
MessageBoxW(_T("SIM_E_SIMWRONG: Inorrect SIM was inserted"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_NOSIMMSGSTORAGE:
MessageBoxW(_T("SIM_E_NOSIMMSGSTORAGE: SIM isn't capable of storing messages"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMTOOLKITBUSY:
MessageBoxW(_T("SIM_E_SIMTOOLKITBUSY: SIM Application Toolkit is busy"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMDOWNLOADERROR:
MessageBoxW(_T("SIM_E_SIMDOWNLOADERROR: SIM data download error"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMNOTINSERTED:
MessageBoxW(_T("SIM_E_SIMNOTINSERTED: SIM isn't inserted into the phone"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_PHSIMPINREQUIRED :
MessageBoxW(_T("SIM_E_PHSIMPINREQUIRED : PH-SIM PIN is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_PHFSIMPINREQUIRED:
MessageBoxW(_T("SIM_E_PHFSIMPINREQUIRED: PH-FSIM PIN is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_PHFSIMPUKREQUIRED:
MessageBoxW(_T("SIM_E_PHFSIMPUKREQUIRED: PH-FSIM PUK is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMPINREQUIRED:
MessageBoxW(_T("SIM_E_SIMPINREQUIRED: SIM PIN is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMPUKREQUIRED:
MessageBoxW(_T("SIM_E_SIMPUKREQUIRED: SIM PUK is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_INCORRECTPASSWORD:
MessageBoxW(_T("SIM_E_INCORRECTPASSWORD: Incorrect password was supplied"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMPIN2REQUIRED :
MessageBoxW(_T("SIM_E_SIMPIN2REQUIRED : SIM PIN2 is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMPUK2REQUIRED:
MessageBoxW(_T("SIM_E_SIMPUK2REQUIRED: SIM PUK2 is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_NETWKPINREQUIRED:
MessageBoxW(_T("SIM_E_NETWKPINREQUIRED: Network Personalization PIN is required to perform this operation"), _T ("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_NETWKPUKREQUIRED:
MessageBoxW(_T("SIM_E_NETWKPUKREQUIRED: Network Personalization PUK is required to perform this operation"), _T ("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SUBSETPINREQUIRED:
MessageBoxW(_T("SIM_E_SUBSETPINREQUIRED: Network Subset Personalization PIN is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SUBSETPUKREQUIRED:
MessageBoxW(_T("SIM_E_SUBSETPUKREQUIRED: Network Subset Personalization PUK is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SVCPINREQUIRED:
MessageBoxW(_T("SIM_E_SVCPINREQUIRED: Service Provider Personalization PIN is required to perform this operation"), _T ("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SVCPUKREQUIRED :
MessageBoxW(_T("SIM_E_SVCPUKREQUIRED : Service Provider Personalization PUK is required to perform this operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_CORPPINREQUIRED:
MessageBoxW(_T("SIM_E_CORPPINREQUIRED: Corporate Personalization PIN is required to perform this operation"), _T ("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_CORPPUKREQUIRED :
MessageBoxW(_T("SIM_E_CORPPUKREQUIRED : Corporate Personalization PUK is required to perform this operation"), _T ("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_MEMORYFULL:
MessageBoxW(_T("SIM_E_MEMORYFULL: Storage memory is full"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_INVALIDINDEX:
MessageBoxW(_T("SIM_E_INVALIDINDEX: Invalid storage index was supplied"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_NOTFOUND:
MessageBoxW(_T("SIM_E_NOTFOUND: A requested storage entry was not found"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_MEMORYFAILURE:
MessageBoxW(_T("SIM_E_MEMORYFAILURE: Storage memory failure"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SIMMSGSTORAGEFULL:
MessageBoxW(_T("SIM_E_SIMMSGSTORAGEFULL: Message sto age on the SIM is full"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_EMPTYINDEX:
MessageBoxW(_T("SIM_E_EMPTYINDEX: Storage location is empty"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_TEXTSTRINGTOOLONG:
MessageBoxW(_T("SIM_E_TEXTSTRINGTOOLONG: Supplied text string is too long"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_DIALSTRINGTOOLONG:
MessageBoxW(_T("SIM_E_DIALSTRINGTOOLONG: Supplied dial string contains invalid characters"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_NOTREADY:
MessageBoxW(_T("SIM_E_NOTREADY: SIM isn't yet ready to perform the requested operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_SECURITYFAILURE:
MessageBoxW(_T("SIM_E_SECURITYFAILURE: SIM isn't yet ready to perform the requested operation"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_BUFFERTOOSMALL:
MessageBoxW(_T("SIM_E_BUFFERTOOSMALL: Buffer too small"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_NOTTEXTMESSAGE:
MessageBoxW(_T("SIM_E_NOTTEXTMESSAGE: Requested SMS message is not a text message"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_NOSIM:
MessageBoxW(_T("SIM_E_NOSIM: Device doesn't have a SIM"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_NETWORKERROR:
MessageBoxW(_T("SIM_E_NETWORKERROR: There was a network error"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_MOBILEERROR:
MessageBoxW(_T("SIM_E_MOBILEERROR: Mobile error"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_UNSUPPORTED:
MessageBoxW(_T("SIM_E_UNSUPPORTED: The command is unsupported"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_BADPARAM :
MessageBoxW(_T("SIM_E_BADPARAM : Bad parameter"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_UNDETERMINED :
MessageBoxW(_T("SIM_E_UNDETERMINED: Undetermined error"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_RADIONOTPRESENT :
MessageBoxW(_T("SIM_E_RADIONOTPRESENT: The Radio is not present"), _T("Error"), MB_OK|MB_ICONERROR);
break;
case SIM_E_RADIOOFF :
MessageBoxW(_T("SIM_E_RADIOOFF : The Radio is off"), _T("Error"), MB_OK|MB_ICONERROR);
break;
default:
MessageBoxW(_T("Unknown Error!"), _T("Error"), MB_OK|MB_ICONERROR);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -