Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - ShellExec and a bit more (delphi)
  FAQ FAQ  Forum Search   Register Register  Login Login

ShellExec and a bit more (delphi)

 Post Reply Post Reply
Author
Message
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Topic: ShellExec and a bit more (delphi)
    Posted: 01 Nov 05 at 12:13AM
Often i've read questions about how to show/open a pdf-file with QuickPDF. Why you want to do this with QuickPDF? Everybody who's working with pdf-files have installed a pdf-reader... so why not use it? For this you can use ShellExecute or (better) ShellExec ('cause it supports long file names and offers you more features).

If you don't want to work with the real name "acrord32" you can use my second example as well. All in Delphi but i think other languages offers the same.

Some more special code is "Keybd_Event...". You know pressing the shift-key while opening a pdf-file supress the loading of many dlls (from the acrobat reader) which you often don't need. So in my code first i simulate a pressed shift key and after ShellExec i simulate a released shift key.

Best regards,
Ingo

. . .
   uses ShellAPI
. . .
function ShellExec( op, fn, par, dir: PChar;
show: Word; wait: Boolean): LongInt;
var
ih: Word;
OK: Boolean;
Info: TShellExecuteInfo;
begin
FillChar(Info, SizeOf(Info), Chr(0));
Info.cbSize := SizeOf(Info);
Info.fMask := SEE_MASK_NOCLOSEPROCESS;
Info.lpVerb := op;
Info.lpFile := fn;
Info.lpParameters := par;
Info.lpDirectory := dir;
Info.nShow := show;
OK := Boolean(ShellExecuteEx(@Info));
if OK then
begin
if wait then
begin
while
WaitForSingleObject(Info.hProcess,100)
= WAIT_TIMEOUT do
Application.ProcessMessages;
OK := GetExitCodeProcess(
Info.hProcess, DWord(Result));
end
else
Result := 0;
end;
if not OK then Result := -1;
end;
. . .
// Anywhere in your program ... perhaps at an onclick-event:
. . .
   Keybd_Event(vk_Shift,0,0,0);
   ShellExec('open',PChar('acrord32.exe'),PChar('/s ' + ExtractFilePath(Application.ExeName) + 'example.pdf'),nil,SW_SHOWNORMAL,True);
   Keybd_Event(vk_Shift,0,KEYEVENTF_KEYUP,0);

// and a second solution...

. . .
ShellExec('open',PChar(GetProgramAssociation('pdf')),PChar('/s ' + ExtractFilePath(Application.ExeName) + 'example.pdf'),nil,SW_SHOWNORMAL,True);
. . .


Edited by Ingo
Cheers,
Ingo

Back to Top
DafCorpX View Drop Down
Beginner
Beginner
Avatar

Joined: 06 Dec 05
Location: Sweden
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote DafCorpX Quote  Post ReplyReply Direct Link To This Post Posted: 06 Dec 05 at 10:49AM

Nice code just wanted to show abnother way to open or print the pdf file.

uses ShellAPI

ShellExecute( Form1.Handle, 'OPEN', PChar(TheFullPDFFilenameWithPath), nil, nil, sw_shownormal);


ShellExecute( Form1.Handle, 'PRINT', PChar(TheFullPDFFilenameWithPath), nil, nil, sw_shownormal);

This will either OPEN the file with it's associated progranm or PRINT it with the same program

Saves the tedious way to find AcroRead or whatever program that's associated with PDF files.

Goodluck

//Dan
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store