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

透過WinExec開啟子目錄程式之後FileListBox 讀不到檔案

缺席
blacknight560
一般會員


發表:1
回覆:1
積分:0
註冊:2015-04-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2015-04-12 11:40:16 IP:122.118.xxx.xxx 訂閱
今天嘗試用一個小程式來使用WinExec("Program\\XXX\\XXX.exe",1);
開始各種嘗試,發現好像只能把數據檔直接丟到主目錄底下(就是小程式的位置),
謝謝。
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2015-04-13 10:32:39 IP:59.120.xxx.xxx 未訂閱
建議是另外建立一佪「捷徑檔」來執行,才能夠把「開始位置」設定給目標執行檔。

[code cpp]
//---------------------------------------------------------------------------
#define NO_WIN32_LEAN_AND_MEAN
#include "shlobj.h"
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void CreateLink(String PathObj,String WorkDir,WideString PathLink,
String Description,String Arguments,
int ShowCmd)
{
HRESULT hres;
IShellLink *NewLink;
CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&NewLink);
if(SUCCEEDED(hres))
{
NewLink->SetPath(PathObj.c_str());
NewLink->SetWorkingDirectory(WorkDir.c_str());
NewLink->SetDescription(Description.c_str());
NewLink->SetArguments(Arguments.c_str());
NewLink->SetShowCmd(ShowCmd);
IPersistFile *ppf;
NewLink->QueryInterface(IID_IPersistFile, (void**)&ppf);
ppf->Save(PathLink, True);
}
CoUninitialize();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String Dir;
char StartPath[MAX_PATH];
LPITEMIDLIST pidl;
SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl);
SHGetPathFromIDList(pidl, StartPath);
Dir= StartPath;
CreateLink(Application->ExeName,ExtractFileDir(Application->ExeName),Dir L"\BCB6 Created Link.lnk",L"Eden Design","",SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
[/code]


[code delphi]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShlObj, ActiveX, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
IObject : IUnknown;
ISLink : IShellLink;
IPFile : IPersistFile;
PIDL : PItemIDList;
InFolder : array[0..MAX_PATH] of Char;
TargetName : String;
LinkName : WideString;
begin
TargetName := 'c:windowscalc.exe';
{Use TargetName:=ParamStr(0) which
returns the path and file name of the
executing program to create a link to your
Application}
IObject := CreateComObject(CLSID_ShellLink) ;
ISLink := IObject as IShellLink;
IPFile := IObject as IPersistFile;
with ISLink do
begin
SetPath(pChar(TargetName)) ;
SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;
end;
// if we want to place a link on the Desktop
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL) ;
SHGetPathFromIDList(PIDL, InFolder) ;
{ or if we want a link to appear in
some other, not-so-special, folder:
InFolder := 'c:SomeFolder' }
LinkName := InFolder 'Delphi Created Link.lnk';
IPFile.Save(PWChar(LinkName), false) ;
end;
end.
[/code]

參考資料:
C Builder:
C Builder - Создать ярлык на рабочем столе
使用IShellLink创建快捷方式时的问题
Delphi:
How to Create a Windows Shortcut (.LNK) File
編輯記錄
GrandRURU 重新編輯於 2015-04-13 11:03:41, 註解 無‧
blacknight560
一般會員


發表:1
回覆:1
積分:0
註冊:2015-04-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2015-04-13 16:56:41 IP:122.118.xxx.xxx 訂閱
終於成功了,謝謝
系統時間:2024-11-21 17:44:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!