全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:4093
推到 Plurk!
推到 Facebook!

如何创建.lnk文件?

答題得分者是:Cooky Kid
I_Love_You
一般會員


發表:18
回覆:87
積分:21
註冊:2002-07-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-10-29 18:45:58 IP:211.96.xxx.xxx 未訂閱
各位先进,我想问一下,在BCB中如何来创建快捷方式 (.lnk档案)?可否举个例子?谢谢!!!
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-10-30 09:13:01 IP:203.73.xxx.xxx 未訂閱
引言: 各位先进,我想问一下,在BCB中如何来创建快捷方式 (.lnk档案)?可否举个例子?谢谢!!!
以下資料「轉貼」自 MSDN 及 Platform SDK 關鍵字「Shell Links」希望對你有幫助~~ IsShortcut = "">SetPath(lpszPathObj); psl->SetDescription(lpszDesc); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface(&IID_IPersistFile, (LPVOID*)&ppf); if (SUCCEEDED(hres)) { WCHAR wsz[MAX_PATH]; // Ensure that the string is Unicode. MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); // Save the link by calling IPersistFile::Save. hres = ppf->Save(wsz, TRUE); ppf->Release(); } psl->Release(); } return hres; } Resolving a Shortcut An application may need to access and manipulate a shortcut that was previously created. This operation is referred to as resolving the shortcut. The application-defined ResolveIt function in the following example resolves a shortcut. Its parameters include a window handle, a pointer to the path of the shortcut, and the address of a buffer that receives the new path to the object. The window handle identifies the parent window for any message boxes that the Shell may need to display. For example, the Shell can display a message box if the link is on unshared media, if network problems occur, if the user needs to insert a floppy disk, and so on. The ResolveIt function calls the CoCreateInstance function and assumes that the CoInitialize function has already been called. Note that ResolveIt needs to use the IPersistFile interface to store the link information. IPersistFile is implemented by the IShellLink object. The link information must be loaded before the path information is retrieved, which is shown later in the example. Failing to load the link information causes the calls to the IShellLink::GetPath and IShellLink::GetDescription member functions to fail. HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath) { HRESULT hres; IShellLink* psl; char szGotPath[MAX_PATH]; char szDescription[MAX_PATH]; WIN32_FIND_DATA wfd; *lpszPath = 0; // assume failure // Get a pointer to the IShellLink interface. hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl); if (SUCCEEDED(hres)) { IPersistFile* ppf; // Get a pointer to the IPersistFile interface. hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); if (SUCCEEDED(hres)) { WCHAR wsz[MAX_PATH]; // Ensure that the string is Unicode. MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH); // Load the shortcut. hres = ppf->Load(wsz, STGM_READ); if (SUCCEEDED(hres)) { // Resolve the link. hres = psl->Resolve(hwnd, 0); if (SUCCEEDED(hres)) { // Get the path to the link target. hres = psl->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd, SLGP_SHORTPATH ); if (FAILED(hres)) HandleErr(hres); // application-defined function // Get the description of the target. hres = psl->GetDescription(szDescription, MAX_PATH); if (FAILED(hres)) HandleErr(hres); lstrcpy(lpszPath, szGotPath); } } // Release the pointer to the IPersistFile interface. ppf->Release(); } // Release the pointer to the IShellLink interface. psl->Release(); } return hres; } Creating a Shortcut to a Nonfile Object Creating a shortcut to a nonfile object, such as a printer, is similar to creating a shortcut to a file except that rather than setting the path to the file, you must set the identifier list to the printer. To set the identifier list, call the IShellLink::SetIDList method, specifying the address of an identifier list. Each object within the Shell's namespace has an item identifier. The Shell often concatenates item identifiers into null-terminated lists consisting of any number of item identifiers. For more information about item identifiers, see Item Identifiers and Identifier Lists. In general, if you need to set a shortcut to an item that does not have a file name, such as a printer, you will already have a pointer to the object's IShellFolder interface. IShellFolder is used to create namespace extensions. Once you have the class identifier for IShellFolder, you can call the CoCreateInstance function to retrieve the address of the interface. Then you can call the interface to enumerate the objects in the folder and retrieve the address of the item identifier for the object that you are searching for. Finally, you can use the address in a call to the IShellLink::SetIDList member function to create a shortcut to the object.
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
I_Love_You
一般會員


發表:18
回覆:87
積分:21
註冊:2002-07-24

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-10-30 14:13:02 IP:211.96.xxx.xxx 未訂閱
非常感谢RaynorPao,谢谢您。 我试着将上面的内容改成BCB,但在编译的时候总是过不去,不是这个没有定义, 就是那个无法识别的错误,如果您方便的话,可以用BCB作个简单的范例吗? 谢谢您,谢谢!!!
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-10-30 16:51:19 IP:203.73.xxx.xxx 未訂閱
引言: 非常感谢RaynorPao,谢谢您。 我试着将上面的内容改成BCB,但在编译的时候总是过不去,不是这个没有定义, 就是那个无法识别的错误,如果您方便的话,可以用BCB作个简单的范例吗? 谢谢您,谢谢!!!
目前我在 bcb 編譯也是有問題 不過~~我在 > 要記得~~ > 就是先用 >
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
Cooky Kid
初階會員


發表:5
回覆:68
積分:44
註冊:2002-07-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-10-31 01:42:55 IP:210.58.xxx.xxx 未訂閱
應該可以解你問題吧?! 也歡迎你將改寫的程式碼post出來,OK! enjoy it!!! //--------------------------------------------------------------------------- //此行定義,詳情請見 http://www.bcbdev.com/faqs/faq91.htm #define NO_WIN32_LEAN_AND_MEAN #include <vcl.h> #pragma hdrstop //--------------------------------------------------------------------------- #include <shellapi.h> //--------------------------------------------------------------------------- #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) { /* char sysDir[MAX_PATH]; //將系統路徑填入此字元陣列中 ::GetSystemDirectory(sysDir, sizeof(sysDir)); */ HRESULT hres; IShellLink* psl; //取得 IShellLink 介面的指標 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)(&psl)); //若成功取得,則進行 IShellLink 各項資料設定 if(SUCCEEDED(hres)) { //取得 IPersistFile 介面的指標 IPersistFile* ppf; hres = psl->QueryInterface(IID_IPersistFile, (void**)(&ppf)); //若成功取得,則進行 IShellLink 各項資料設定 if(SUCCEEDED(hres)) { //此範例連接檔的路徑,即是此執行檔路徑 hres = psl->SetPath(Application->ExeName.c_str()); //設定此連接檔的類型 hres = psl->SetDescription("my test"); //設定此連接檔放置何處,本範例的連接檔放置在桌面上 hres = ppf->Save(WideString("C:\\win98\\Desktop\\MyLinkFile.lnk"), TRUE); //完成後,將IPersistFile介面釋放 ppf->Release(); } //完成後,將IShellLink介面釋放 psl->Release(); } } //---------------------------------------------------------------------------
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-10-31 08:36:27 IP:203.73.xxx.xxx 未訂閱
引言: 應該可以解你問題吧?! 也歡迎你將改寫的程式碼post出來,OK! enjoy it!!!
哇~~好棒 原來只要這樣做就可以 解決在 >
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
I_Love_You
一般會員


發表:18
回覆:87
積分:21
註冊:2002-07-24

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-10-31 10:14:41 IP:211.96.xxx.xxx 未訂閱
非常感谢RaynorPao和Cooky Kid大大的指点,谢谢!!! 我在这边也测试成功了,真的要好好的谢谢您们。
Cooky Kid
初階會員


發表:5
回覆:68
積分:44
註冊:2002-07-11

發送簡訊給我
#8 引用回覆 回覆 發表時間:2002-11-01 13:25:57 IP:210.58.xxx.xxx 未訂閱
引言: 非常感谢RaynorPao和Cooky Kid大大的指点,谢谢!!! 我在这边也测试成功了,真的要好好的谢谢您们。
嗚~~~~~~~!_! 我不管啦.... I_Love_You大大,你要給我"糖"吃..ㄟ...給我"得分"啦~~~~
I_Love_You
一般會員


發表:18
回覆:87
積分:21
註冊:2002-07-24

發送簡訊給我
#9 引用回覆 回覆 發表時間:2002-11-01 13:38:05 IP:211.96.xxx.xxx 未訂閱
哈哈,只可惜每次只能给1分,要不然我给您120分,呵呵!!!^_^ 非常感谢您的帮忙。
lcsboy
版主


發表:87
回覆:622
積分:394
註冊:2002-06-18

發送簡訊給我
#10 引用回覆 回覆 發表時間:2002-11-07 01:18:44 IP:210.85.xxx.xxx 未訂閱
感謝Coody Kid所po的code, 真的可以用, 好感動 如果像偶用的> >會怎樣? > 那 > 如果我說的內容讓您不是很懂, 實在抱歉, 請參考: > (如有侵犯版權請記得告知) 發表人 -
davidchang
一般會員


發表:4
回覆:10
積分:2
註冊:2002-08-08

發送簡訊給我
#11 引用回覆 回覆 發表時間:2002-11-11 09:57:27 IP:61.220.xxx.xxx 未訂閱
版主大人....你放的那個demo檔只有.bpr 是只有這樣子嗎 還是沒放完整
lcsboy
版主


發表:87
回覆:622
積分:394
註冊:2002-06-18

發送簡訊給我
#12 引用回覆 回覆 發表時間:2002-11-11 10:16:13 IP:211.23.xxx.xxx 未訂閱
修正一下我之前的說法! 把VCL.h點掉是一個方法! 但是用了ShowMessage時找不到定義! 後來發現正解: 1. 就是shlobj擺最上方! 2. 加入#define NO_WIN32_LEAN_AND_MEAN在下一行 3. 接著就是vcl.h 這樣子Complier一定會過, 而且所有的function都可以正常work 原先放的Demo已經修正, 有興趣的人可以重新下載! http://delphi.ktop.com.tw/topic.php?TOPIC_ID=22716
系統時間:2024-04-25 0:40:15
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!