当然可以使用
SHCreateShortcut 来创建快捷方式,但是我尝试着总是不成功,只好自己写一个了
/*******************************************************
smartphone 快捷方式介绍
快捷方式分3部分,形式如 XX#XXXXXXXXXXXXXXXXXXX
#号前面为#号后面的长度,即命令行的长度
程序名称必须用双引号括起来,参数写到双引号后面
例如:
54#"\Storage Card\PhoneSharp\PhoneSharp.exe" -callhistory
若中间没有空格也可以不用双引号,但为了保成通用还是有必要加上双引号
iHqq QQ:6966683
*****************************************************/
BOOL CMainDlg::CreateShortCut(LPCTSTR strFileName,TCHAR* path)
{
char szBuffer[255];
ZeroMemory(szBuffer, sizeof(szBuffer));
if(_tcslen(path))
{
int multicharlen = WideCharToMultiByte(CP_ACP,0,path,-1,NULL,0,NULL,NULL);
char* pMultiText;
pMultiText = new char[multicharlen];
WideCharToMultiByte(CP_ACP,0,path,-1,pMultiText,multicharlen,NULL,NULL);
sprintf(szBuffer,"%d#%s",multicharlen-1,pMultiText);
}
else
{
sprintf(szBuffer,"%s","10#\":MSINBOX\"");
}
HANDLE hFile = CreateFile(strFileName,GENERIC_WRITE,FILE_SHARE_READ,
NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwNumToWrite;
WriteFile(hFile,szBuffer,strlen(szBuffer),&dwNumToWrite,0);
CloseHandle(hFile);
return TRUE;
}
return FALSE;
}
LRESULT CMainDlg::SaveShortCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
TCHAR szBuffer[255]; // buffer for receives data
//DO key short press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_DOSHORT,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\DoKeySp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\DoKeySp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//DO key long press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_DOLONG,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\DoKeyLp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\DoKeyLp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//MO key short press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_MOSHORT,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\MoSp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\MoSp.lnk出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//MO key long press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_MOLONG,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\MoLp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\MoLp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//Camera key short press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_CAMERASHORT,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\CameraSp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\CameraSp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//Camera key long press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_CAMERALONG,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\CameraLp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\CameraLp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
MessageBox(_T("已经成功创建快捷方式!赶快试试吧!"),_T("提示!"),MB_OK);
return TRUE;
}
{
char szBuffer[255];
ZeroMemory(szBuffer, sizeof(szBuffer));
if(_tcslen(path))
{
int multicharlen = WideCharToMultiByte(CP_ACP,0,path,-1,NULL,0,NULL,NULL);
char* pMultiText;
pMultiText = new char[multicharlen];
WideCharToMultiByte(CP_ACP,0,path,-1,pMultiText,multicharlen,NULL,NULL);
sprintf(szBuffer,"%d#%s",multicharlen-1,pMultiText);
}
else
{
sprintf(szBuffer,"%s","10#\":MSINBOX\"");
}
HANDLE hFile = CreateFile(strFileName,GENERIC_WRITE,FILE_SHARE_READ,
NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwNumToWrite;
WriteFile(hFile,szBuffer,strlen(szBuffer),&dwNumToWrite,0);
CloseHandle(hFile);
return TRUE;
}
return FALSE;
}
LRESULT CMainDlg::SaveShortCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
TCHAR szBuffer[255]; // buffer for receives data
//DO key short press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_DOSHORT,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\DoKeySp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\DoKeySp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//DO key long press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_DOLONG,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\DoKeyLp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\DoKeyLp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//MO key short press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_MOSHORT,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\MoSp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\MoSp.lnk出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//MO key long press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_MOLONG,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\MoLp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\MoLp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//Camera key short press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_CAMERASHORT,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\CameraSp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\CameraSp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
//Camera key long press' shortcut
ZeroMemory(szBuffer, sizeof(szBuffer));
GetDlgItemText(IDC_CAMERALONG,szBuffer,255);
if(!CreateShortCut(_T("\\Storage\\Keys\\CameraLp.lnk"),szBuffer))
{
MessageBox(_T("创建快捷方式 \\Storage\\Keys\\CameraLp.lnk 出错"),_T("出错了!"),MB_OK);
return FALSE;
}
MessageBox(_T("已经成功创建快捷方式!赶快试试吧!"),_T("提示!"),MB_OK);
return TRUE;
}