Здравствуйте!
У меня стоит Дельфи7 и Виндоус 10.
Хочу отправить на печать файл типа HTML с помощью API-функции ShellExecute, но выходит ошибка
SE_ERR_NOASSOC: S := 'There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.';
Вручную связываю такие файлы через Проводник и ставлю опцию открывать с помощью имеющегося браузера Google.
Но проблема не уходит, файл не печатается.
Предполагаю, что что то изменилось в Виндоус и API функция устарела. Есть ли альтернативные способы вывода HTML на печать ?
Код:
function PrintHTML(Handle: THandle; FileName: String): integer;
var
ErrorCode: Integer;
S: string;
begin
ErrorCode := Integer(ShellAPI.ShellExecute(Handle, 'Print', PChar(FileName), nil, nil, SW_SHOWMAXIMIZED));
S := '';
if ErrorCode <= HINSTANCE_ERROR { = 32 } then
begin
case ErrorCode of
0: S := 'The operating system is out of memory or resources.';
ERROR_FILE_NOT_FOUND: S := 'The specified file was not found.';
ERROR_PATH_NOT_FOUND: S := 'The specified path was not found.';
ERROR_BAD_FORMAT: S := 'The .exe file is invalid (non-Win32 .exe or error in .exe image).';
SE_ERR_ACCESSDENIED: S := 'The operating system denied access to the specified file.';
SE_ERR_ASSOCINCOMPLETE: S := 'The file name association is incomplete or invalid.';
SE_ERR_DDEBUSY: S := 'The DDE transaction could not be completed because other DDE transactions were being processed.';
SE_ERR_DDEFAIL: S := 'The DDE transaction failed.';
SE_ERR_DDETIMEOUT: S := 'The DDE transaction could not be completed because the request timed out.';
SE_ERR_DLLNOTFOUND: S := 'The specified DLL was not found.';
// SE_ERR_FNF: Application.MessageBox(PChar('The specified file was not found.';
SE_ERR_NOASSOC: S := 'There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.';
SE_ERR_OOM: S := 'There was not enough memory to complete the operation.';
// SE_ERR_PNF: Application.MessageBox(PChar('The specified path was not found.';
SE_ERR_SHARE: S := 'A sharing violation occurred.';
else
S := 'Unknown Error %d';
end;
if S = '' then exit;
S := 'PrintHTML func. ' + S;
Application.MessageBox(PChar(Format(S, [ErrorCode])), 'Error', MB_OK or MB_ICONERROR);
Exit;
end;
end;
Админ: Пользуемся тегами при оформлении кода!