//---------------------------------------------------------------------------
#define NO_WIN32_LEAN_AND_MEAN
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(OpenDialog->Execute())
{
Edit1->Text=OpenDialog->FileName;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(Edit1->Text.IsEmpty()||!FileExists(Edit1->Text))
{
MessageBox(Handle,"你要创建的文件不存在!\n请重新选择要创建的文件!","YYB警告你:",MB_ICONWARNING);
return;
}
if(Edit2->Text.IsEmpty())
{
MessageBox(Handle,"请输入快捷方式名称!","YYB警告你:",MB_ICONWARNING);
return;
}
String desktop=GetDeskTopPath(CSIDL_DESKTOP);
if(desktop.IsEmpty())
{
desktop=GetCurrentDir();
}
CreateShortCut(Edit1->Text,"中国石油大学(华东)",desktop);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CreateShortCut(String File,String Description,String Path)
{
IShellLink*Link;
IPersistFile *PersistFile;
if(SUCCEEDED(CoInitialize(NULL)))
{
if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(void**)&Link)))
{
Link->SetPath(File.c_str());
Link->SetDescription(Description.c_str());
Link->SetShowCmd(SW_SHOW);
//Link->SetIconLocation()
if(SUCCEEDED(Link->QueryInterface(IID_IPersistFile,(void**)&PersistFile)))
{
WideString ShortCutLocation(Path+"\\"+Edit2->Text+".lnk");
PersistFile->Save(ShortCutLocation.c_bstr(),true);
PersistFile->Release();
}
Link->Release();
}
CoUninitialize();
MessageBox(Handle,"快捷方式创建成功!","YYB恭喜你:",MB_OK);
}
else MessageBox(Handle,"快捷方式创建失败!","YYB提醒你:",MB_ICONERROR);
}
//========================================================================
String __fastcall TForm1::GetDeskTopPath(int Folder)
{
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
char Dir[MAX_PATH];
String path="";
if(SUCCEEDED(SHGetMalloc(&pShellMalloc)))
{
if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,Folder,&pidl)))
{
if(SHGetPathFromIDList(pidl,Dir))
{
path=Dir;
}
pShellMalloc->Free(pidl);
}
pShellMalloc->Release();
}
return path;
}
void __fastcall TForm1::Button3Click(TObject *Sender)
{
String str=GetDeskTopPath(CSIDL_APPDATA);
ShowMessage(str);
}
//---------------------------------------------------------------------------
没有合适的资源?快使用搜索试试~ 我知道了~
编程快速实现快捷方式的创建和特殊文件家的获取
共8个文件
cpp:2个
bdsproj:1个
exe:1个
需积分: 0 7 下载量 115 浏览量
2008-12-22
23:35:49
上传
评论
收藏 16KB RAR 举报
温馨提示
编程快速实现快捷方式的创建和特殊文件家的获取,你可以在你所需要的位置创建快捷方式!
资源推荐
资源详情
资源评论
收起资源包目录
.rar (8个子文件)
创建快捷方式
__history
Debug_Build
Project1.exe 37KB
Project1.bdsproj 16KB
Project1.bdsproj.local 900B
Unit1.dfm 2KB
Project1.cpp 805B
Project1.res 4KB
Unit1.h 1KB
Unit1.cpp 3KB
共 8 条
- 1
资源评论
YeBinYe
- 粉丝: 207
- 资源: 265
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功