如何取得 Windows 的路徑 ? |
尚未結案
|
way888
初階會員 發表:32 回覆:76 積分:36 註冊:2005-05-31 發送簡訊給我 |
【文章】如何取得正在執行的程式位置
【作者】axsoft
【內文】原文:http://delphi.ktop.com.tw/topic.php?topic_id=35185
(1)取得執行檔自己的路徑
ShowMessage(ExtractFilePath(Application->ExeName));
或
ShowMessage(ExtractFilePath(ParamStr(0))); (2)取得 Windows 的路徑
char szWinPath[64];
GetWindowsDirectory(szWinPath, 64);
ShowMessage(szWinPath); (3)取得系統的路徑
char szSysPath[64];
GetSystemDirectory(szSysPath, 64);
ShowMessage(szSysPath); (4)取得目前路徑
GetCurrentDir();
LPSTR GetWindowsDir(LPSTR szBuf, INT cbBuf); 以上是前輩們的智慧
可真是造福人群
請問要如何改成Delphi的寫法?
|
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
搞不太懂,你都有找到那篇文章了,幾乎一模一樣怎麼不會轉?
Delphi陣列應該會用吧
C Builder的->改成.
就這樣而已
procedure TForm1.Button1Click(Sender: TObject);
var
Path:Array[0..64] of char;
begin
ShowMessage(ExtractFilePath(Application.ExeName));
GetWindowsDirectory(Path,64);
ShowMessage(Path);
GetSystemDirectory(Path, 64);
ShowMessage(Path);
ShowMessage(GetCurrentDir);
end;
|
way888
初階會員 發表:32 回覆:76 積分:36 註冊:2005-05-31 發送簡訊給我 |
Hi supman 您好
非常感謝您的指教,因我是業餘的程式設計,僅是興趣寫一些小程式來自己用用,對於C 或是其他語言則是一概不會,我只會Delphi,所以請多包涵。
真的非常感謝DelPhi前輩們的指教,讓我這小小的功力就能寫出實用的程式。
言歸正傳...
以上您的轉譯,我已經測試成功,一切OK,不過還是無法應用到我的程式裡面,
以下是我在其他網站找到的程式碼,我也測試OK了,但只能在檔案總管按複製時才能將檔案路徑送到MEMO,........
請問您有辦法把他改成雙擊時,讓其路徑送到MEMO...? ...retrieve the filenames in the clipboard?
Autor: P. Below
Homepage: http://www.teamb.com
[Write new comment]
[ Print tip ] Tip Rating (3):
{
"If I use the windows Explorer to copy a file,
how can I use a paste function in my app?
This code retrieves the filenames in the clipboard.
Now you may want to display a file in a memo or
do something else with it. "Wenn ich im Windows Explorer eine Datei kopiere,
wie kann ich dann eine Einfuge Funktion implementieren ?
Der folgende Code listet alle Dateinamen in der Zwischenablage auf.
Dann kann man eine Datei z.B in ein Memo laden oder
etwas anderes damit anstellen.
} uses
clipbrd, shellapi; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
f: THandle;
buffer: array [0..MAX_PATH] of Char;
i, numFiles: Integer;
begin
if not Clipboard.HasFormat(CF_HDROP) then Exit;
Clipboard.Open;
try
f := Clipboard.GetAsHandle(CF_HDROP);
if f <> 0 then
begin
numFiles := DragQueryFile(f, $FFFFFFFF, nil, 0);
memo1.Clear;
for i := 0 to numfiles - 1 do
begin
buffer[0] := #0;
DragQueryFile(f, i, buffer, SizeOf(buffer));
memo1.Lines.Add(buffer);
end;
end;
finally
Clipboard.Close;
end;
end;
|
way888
初階會員 發表:32 回覆:76 積分:36 註冊:2005-05-31 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |