You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
/t used to do the trick until Acrobat Reader 8. The short answer is I don't know, but here's a fascinating link - look for the post by Skyter, who includes C source code. His (male gender imputing all others) approach is to send the application a WM_CLOSE message.
I should have added - the C code could no doubt be translated to PB.
Last edited by Chris Holbrook; 21 May 2008, 03:32 PM.
Reason: add link
Oh dear. I just followed the link from Skyter's post to his source code and it 404'd. Sorry! Looking on the bright side, a) it's a handy forum for PDF problems, and b) Skyter did at least identify an approach, which should be testable using PB.
source code for app which kills Adobe Reader included
OK. Here's some code by Ryan Mott which uses code by Eros Olmi which.. oh, never mind! The main thing is, it now compiles under PBWin 8.04 and kills one process whose title inlcudes "Adobe Reader". I'm sure you can adapt it.
Code:
#COMPILE EXE
#DIM ALL
#INCLUDE "win32api.inc"
' The following functions were adapted from a post by
' Eros Olmi on the PowerBasic Forum (11/08/02)
TYPE WinInfoType
WinTitle AS STRING * 256
WinHandle AS LONG
END TYPE
GLOBAL gWinList() AS WinInfoType
GLOBAL gWinListPos AS LONG
FUNCTION FindWindowByTitle(BYVAL lMethod AS STRING, BYVAL lTitle AS STRING) AS LONG
DIM Count AS LONG
gWinListPos = 0
EnumWindows CODEPTR(EnumWindowsProc), 0
lMethod = UCASE$(lMethod)
lTitle = UCASE$(lTitle)
FOR Count = 1 TO gWinListPos
IF IsWindowVisible(gWinList(Count).WinHandle) = 1 THEN
IF INSTR(lMethod, "START WITH") THEN
IF UCASE$(LEFT$(gWinList(Count).WinTitle, LEN(lTitle))) = lTitle THEN
FUNCTION = gWinList(Count).WinHandle
EXIT FOR
END IF
END IF
IF INSTR(lMethod, "CONTAIN") THEN
IF INSTR(UCASE$(gWinList(Count).WinTitle), lTitle) THEN
FUNCTION = gWinList(Count).WinHandle
EXIT FOR
END IF
END IF
IF INSTR(lMethod, "END WITH") THEN
IF UCASE$(RIGHT$(gWinList(Count).WinTitle, LEN(lTitle))) = lTitle THEN
FUNCTION = gWinList(Count).WinHandle
EXIT FOR
END IF
END IF
END IF
NEXT Count
END FUNCTION
FUNCTION EnumWindowsProc(BYVAL lHandle AS LONG, BYVAL lNotUsed AS LONG) AS LONG
DIM wTitle AS STRING
DIM lPos AS LONG
wTitle = STRING$(256,0)
GetWindowText lHandle, BYVAL STRPTR(wTitle), 256
wTitle = EXTRACT$(wTitle, CHR$(0))
IF LEN(wTitle) THEN
INCR gWinListPos
REDIM PRESERVE gWinList(gWinListPos)
gWinList(gWinListPos).WinTitle = wTitle
gWinList(gWinListPos).WinHandle = lHandle
END IF
FUNCTION = 1
END FUNCTION
FUNCTION PBMAIN () AS LONG
LOCAL winTitle AS LONG
winTitle = FindWindowByTitle("CONTAIN", "Adobe Reader")
IF winTitle = 0 THEN
? "Window not found."
ELSE
SendMessage winTitle, %WM_SYSCOMMAND, %SC_CLOSE, 0
? "Window closed."
END IF
? "Finished."
END FUNCTION
'-----------------
Thank you for the code. I will look at it and see what I can do with it. I am still learning, but I enjoy the challenges! I'll let you know what I come up with!
FindWindowByTitle() is the wrong approach for this, since the title can change based on metadata in the PDF. Here's the correct approach, though you'll need to check for class "AcrobatSDIWindow" in addition to "AdobeAcrobat" for version 8 of Reader/Acrobat. Who knows if they will change the classname again in the upcoming version 9.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment