c 语言快捷方式生成代码,c语言创建快捷方式

匿名用户

1级

2013-04-15 回答

1、将C语言编辑器装在哪个文件夹下,找到那儿,应该有个比较鲜艳的图标,选中它后点右键,创建快捷方式,应该就可以了,如果找不到,那就到控制面板里面去将它卸载后重新安装的时候将它的安装路径记下来,就可以找到那儿创建快捷方式了

2、例程:

#define STRICT

#include 

/* C run time library headers */

#include 

#include 

#include 

/* COM headers (requires shell32.lib, ole32.lib, uuid.lib) */

#include 

#include 

static HRESULT CreateShortCut(LPSTR pszTargetfile, LPSTR pszTargetargs,

LPSTR pszLinkfile, LPSTR pszDescription,

int iShowmode, LPSTR pszCurdir,

LPSTR pszIconfile, int iIconindex)

{

HRESULT       hRes;                  /* Returned COM result code */

IShellLink*   pShellLink;            /* IShellLink object pointer */

IPersistFile* pPersistFile;          /* IPersistFile object pointer */

WORD          wszLinkfile[MAX_PATH]; /* pszLinkfile as Unicode string */

int           iWideCharsWritten;     /* Number of wide characters written */

hRes = E_INVALIDARG;

if (

(pszTargetfile != NULL) && (strlen(pszTargetfile) > 0) &&

(pszTargetargs != NULL) &&

(pszLinkfile != NULL) && (strlen(pszLinkfile) > 0) &&

(pszDescription != NULL) &&

(iShowmode >= 0) &&

(pszCurdir != NULL) &&

(pszIconfile != NULL) &&

(iIconindex >= 0)

)

{

hRes = CoCreateInstance(&CLSID_ShellLink,     /* pre-defined CLSID of the IShellLink object */

NULL,                 /* pointer to parent interface if part of aggregate */

CLSCTX_INPROC_SERVER, /* caller and called code are in same process */

&IID_IShellLink,      /* pre-defined interface of the IShellLink object */

&pShellLink);         /* Returns a pointer to the IShellLink object */

if (SUCCEEDED(hRes))

{

/* Set the fields in the IShellLink object */

hRes = pShellLink->lpVtbl->SetPath(pShellLink, pszTargetfile);

hRes = pShellLink->lpVtbl->SetArguments(pShellLink, pszTargetargs);

if (strlen(pszDescription) > 0)

{

hRes = pShellLink->lpVtbl->SetDescription(pShellLink, pszDescription);

}

if (iShowmode > 0)

{

hRes = pShellLink->lpVtbl->SetShowCmd(pShellLink, iShowmode);

}

if (strlen(pszCurdir) > 0)

{

hRes = pShellLink->lpVtbl->SetWorkingDirectory(pShellLink, pszCurdir);

}

if (strlen(pszIconfile) > 0 && iIconindex >= 0)

{

hRes = pShellLink->lpVtbl->SetIconLocation(pShellLink, pszIconfile, iIconindex);

}

/* Use the IPersistFile object to save the shell link */

hRes = pShellLink->lpVtbl->QueryInterface(pShellLink,        /* existing IShellLink object */

&IID_IPersistFile, /* pre-defined interface of the IPersistFile object */

&pPersistFile);    /* returns a pointer to the IPersistFile object */

if (SUCCEEDED(hRes))

{

iWideCharsWritten = MultiByteToWideChar(CP_ACP, 0, pszLinkfile, -1, wszLinkfile, MAX_PATH);

hRes = pPersistFile->lpVtbl->Save(pPersistFile, wszLinkfile, TRUE);

pPersistFile->lpVtbl->Release(pPersistFile);

}

pShellLink->lpVtbl->Release(pShellLink);

}

}

return (hRes);

}

int main(int n, char **argv)

{

HRESULT   hRes;                      /* result of calling COM functions */

hRes = CoInitialize(NULL);

if (SUCCEEDED(hRes))

{

hRes = CreateShortCut(argv[0],

"",  /* Target arguments */

"E:\\sam.lnk",    /* Short-cut filename */

"Samurai 2", /* Short-cut description */

SW_SHOW,     /* Showmode constant */

"",      /* Working directory for linked file */

"",    /* Icon file shown for the link */

0);   /* Index of icon in the file */

}

/* call CoUninitialize() and exit the program. */

CoUninitialize();

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值