Windows Programming/Delphi 6/7

Delphi6/7 ShellAPI unit의 ShellExecute

denisOh 2010. 9. 13. 02:51

ShellExecute()는 윈도우쉘 명령을 실행시킬 때 쓰는 함수이다.
내가 사용하는 용도는 두가지이다.
한가지는 탐색기를 열 때(지정한 폴더로 이동시키는 것 까지),
나머지 한가지는 파일(윈도우즈 확장자 연결 프로그램으로 등록된 확장자를 가진 파일)을 열 때 이다.

먼저 탐색기를 여는 방법이다.
ShellExecute(0, 'explore', PChar(descDir), nil, nil, SW_SHOWNORMAL);

다음으로 파일을 열 때 이다.
var
  fileFullPath : String;
  errCode : Cardinal;

begin
    errCode := ShellExecute(handle, 'open', Pchar(fileFullPath) , nil, nil, SW_SHOW);
    if errCode = 31 then ShowMessage('HWP가 설치되어 있지 않습니다'); //실행화일 없을때
    if errCode = 2 then ShowMessage('파일이 존재하지 않습니다');      //파일 없을때
end;