Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PDF's in a form 2

Status
Not open for further replies.

budman48

MIS
Dec 20, 2002
23
0
0
US
I open up a pdf in a form using OLE Controls.
Once my PDF is opened I cannot type in any of my fields on the form. Acrobat is in control. How do I keep the PDF open in the form but still have access to the fields on the form.
 
Try using the shellexecute to open the file and see if that helps. Modify the code below to point to your pdf file and execute all the code below and it should work for you.

appLaunch("myfile.pdf") && change to your file path/name

***********************************************************************
FUNCTION appLaunch
PARAMETER tcOutFile,tcCmd

IF PCOUNT() < 1
MESSAGEBOX(&quot;You did not provide a filename.&quot;,&quot;AppLauch Method&quot;)
RETURN
ENDIF

IF PCOUNT() < 2
tcCmd = &quot;Open&quot;
ENDIF

tcCmd = PROPER(m.tcCmd)

* This code was originally located in Ken Levy's DBF2XML program so blame
* Ken for the bugs :)

* API Call to communicate with an application based on the registered
* file-type.
* For example:
* On my computer txt is notepad; DOC is word

DECLARE INTEGER ShellExecute ;
IN SHELL32.DLL ;
INTEGER nWinHandle,;
STRING cOperation,;
STRING cFileName,;
STRING cParameters,;
STRING cDirectory,;
INTEGER nShowWindow

* tip: to determine commands available for each filetype
* Launch explorer
* go to View / Folder Options
* Select the File Type Tag
* go to the item you wish to look up (example Acrobat)
* Press Edit
* You will see acrobat has Open, Print, and Printto option types.

IF !FILE(tcOutFile)
MESSAGEBOX(tcOutFile + &quot; does not exist!&quot;,&quot;AppLauch Method -- AppLauch Method&quot;)
ELSE

* play with this.
* by adding the ,0 instead of ,1 I was able to get it to
* print directly without opening the document on my sceen.


* this is handy if you wish to print a pdf, word document,
* spreadsheet, text file, etc. from within your applicaiton.
IF m.tcCmd = &quot;Print&quot;
lnFileStatus = ShellExecute(0,&quot;&tcCmd&quot;,tcOutFile,&quot;&quot;,&quot;&quot;,0)
ELSE
lnFileStatus = ShellExecute(0,&quot;&tcCmd&quot;,tcOutFile,&quot;&quot;,&quot;&quot;,1)
ENDIF
DO CASE
CASE m.lnFileStatus > 32
* successful open
CASE m.lnFileStatus = 2
MESSAGEBOX(&quot;Bad Association (for example, invalid URL)&quot;,;
&quot;AppLauch Method -- AppLauch Method&quot;)
CASE m.lnFileStatus = 29
MESSAGEBOX(&quot;Failure to load application&quot;,&quot;AppLauch Method -- AppLauch Method&quot;)
CASE m.lnFileStatus = 30
MESSAGEBOX(&quot;Application is busy&quot;,&quot;AppLauch Method -- AppLauch Method&quot;)
CASE m.lnFileStatus = 31
MESSAGEBOX(&quot;No application association with specified &quot;+;
&quot;command: &quot; + m.tcCmd,&quot;AppLauch Method -- AppLauch Method&quot;)
OTHERWISE
MESSAGEBOX(&quot;Unknown Error&quot;,&quot;AppLauch Method -- AppLauch Method&quot;)
RETURN .F.
ENDCASE
ENDIF



Jim Osieczonek
Delta Business Group, LLC
 
jim00

This opens acrobat outside of the form. I have olecontrol inside my form so acrobat open as part of my form. But I cannot type in any of the fields on my form. The buttons work but my text fields that I am trying to type into do not.
 
budman48,

What version of VFP are you using? Also, what is the control (name and version) you are using to display the PDF in the form? Are textboxes the only effected controls, I mean does everything else you throw on the form work properly? Are the textboxes able to get focus or when you say that you can't type in them are you saying that you can't even get the controls to receive the focus?

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
[/sup]
 
slighthaze

I am using VFP 7.0
the control name is olecontrol1
oleclass is PDF.PDFCTRL.5
oletypeallowed is -2 ActiveX Control
I have 7 text boxes that can receive focus but you cannot type in them.
I have 3 buttons on the screen that work.
I have discovered that if I minimize the screen to the toolbar at the bottom of the desktop then open the screen again I can type in the text boxes.
 
budman48,

Hmmmmmmmm...sounds like a really weird bug. Ok well if you have found a workaround that works then you could try some stuff in code to see if you can get it to work there...

such as calling the form.activate(), or changing the form.windowstate to 1 and then back to 0, or try calling the form.show()...I mean what I would do at this point is just start playing a little battleship with this thing and find a workaround that mimics what you see when you minimize the form and then restore it...it's not pretty but my thought is that you will find something within the things you try that is actually workable and that doesn't cause the form to flash in front of the user, and will still allow them to type in those textboxes. Sorry, I just haven't run into this before...if i get some time here I will try and recreate it and then get back to you.

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
[/sup]
 
Another thing that I found out is after you minimize and come back. If you happen to click on the pdf the text fields are locked out again.

If anyone has a solution please let me know.

Thank You
 
Here's a hack that will work:

1) Launch Acrobat Reader as an external Application
2) Create your form in VFP you want the PDF to be inside
3) &quot;take&quot; the Acrobat Reader into your VFP form
4) Modify the Acrobat Reader window so it looks integral to your app.

It may sound &quot;dirty&quot; but it's not hard to do:

Code:
ShellExec('MyPdfForm.pdf')
pdfCap = 'Adobe Reader - [LL_Affidavit_2002.pdf]'
pdfWin = FindWindow(pdfCap)
IF pdfWin<=0
  MessageBox('Error Finding PDF window')
  SUSP
ENDIF
vfpForm = create('form')
vfpForm.visible = .t.

TakeWindow(pdfWin, vfpForm.Caption)

* Resize, remove titlebar
SetWinPos(pdfWin,30,30,200,200,.t.)


* Utility routines:
************************************************************************
* WinApi :: ShellExecute*********************************
***    Author: Rick Strahl, West Wind Technologies
***            [URL unfurl="true"]http://www.west-wind.com/[/URL]
***  Function: Opens a file in the application that it's
***            associated with.
***      Pass: lcFileName  -  Name of the file to open
***            lcWorkDir   -  Working directory
***            lcOperation -  &quot;Open&quot; &quot;Run&quot; &quot;Play&quot; &quot;Edit&quot; etc...
***    Return: 2  - Bad Association (invalid URL)
***            31 - No application association
***            29 - Failure to load application
***            30 - Application is busy***
***            Values over 32 indicate success
***            and return an instance handle for
***            the application started (the browser)
************************************************************************
FUNCTION ShellExec
LPARAMETERS lcFileName, lcWorkDir, lcOperation, pcParameters
LOCAL pp, lcParam
pp = pCount()          && LAS v9b1w  wgcs
if pp>3                    && LAS v9b1w  wgcs
  lcParam = pcParameters   && LAS v9b1w  wgcs
else                       && LAS v9b1w  wgcs
  lcParam = ''
endif
lcWorkDir=IIF(type(&quot;lcWorkDir&quot;)=&quot;C&quot;,lcWorkDir,&quot;&quot;)
lcOperation=IIF(type(&quot;lcOperation&quot;)=&quot;C&quot;,lcOperation,&quot;Open&quot;)
DECLARE INTEGER ShellExecute ;    
    IN SHELL32.DLL ;    
    INTEGER nWinHandle,;
    STRING cOperation,;    
    STRING cFileName,;    
    STRING cParameters,;
    STRING cDirectory,;    
    INTEGER nShowWindow
RETURN ShellExecute(0,lcOperation,lcFilename,lcParam,lcWorkDir,1)
*ENDFUNC  ShellExecute

*********************************************************
*  FindWindow( cWindowName )
*  Auth: William GC Steinford
*  Date: 7/16/98
*  Purp: Ask windows if a particular window name exists
*        (Case Insensitive)
FUNCTION FindWindow
LPARAMETERS cWinName
DECLARE INTEGER FindWindow in win32api as apiFindWindow INTEGER nClass, STRING cName
Return apiFindWindow( 0, cWinName )

PROCEDURE TakeWindow
* Author : William GC Steinford
* Date   : Nov 2002          
LPARAMETERS pncWindowTitle, pncParentWindow
LOCAL lnWHND, lnVFP, lnRes, lnCNT, lnWinCnt

DECLARE INTEGER FindWindow in win32api as apiFindWindow ;
  INTEGER nClass, STRING cName
DECLARE INTEGER FindWindowEx in win32api as apiFindWindowEx ;
  INTEGER nParent, INTEGER nChildAfter, ;
  INTEGER nClass, STRING cName

* First get the VFP window handle
lnVFP = apiFindWindow( 0, _Screen.Caption )
if lnVFP<=0
  RETURN -1
ENDIF
lnWinCnt = lnVFP

lnWHND = iif(VarType(pncWindowTitle)='N', pncWindowTitle, apiFindWindow(0,pncWindowTitle) )

* Not outside of VFP... if we have a parent window, check inside VFP
if lnWHND<=0 and vartype(pncParentWindow)='C' and not empty(pncParentWindow)
  lnWHND=apiFindWindowEx( lnVFP, 0, 0, pncWindowTitle ) && Look in VFP window
  if lnWHND=0 && Not in Main VFP window... This is the case if this window
              && was created by VFP
    && Container windows in VFP have no title
    lnCNT  = apiFindWindowEx( lnVFP, 0, 0, '' ) && Find in container window
    do while lnWHND=0 and lnCNT<>0
      lnWHND = apiFindWindowEx( lnCNT, 0, 0, pncWindowTitle ) && Look in container
      lnCNT  = apiFindWindowEx( lnVFP, lnCNT, 0, '' ) && Find next container window
    enddo
  endif
endif

if lnWHND<0
  RETURN -1
endif

* Find the Parent Window
if vartype(pncParentWindow)='C' and not empty(pncParentWindow)
  lnWinCNT=apiFindWindowEx( lnVFP, 0, 0, pncParentWindow ) && Look in container
  
  if lnWinCnt=0 && Not in Main VFP window... This is the case if this window
              && was created by VFP
    && Container windows in VFP have no title
    lnCNT  = apiFindWindowEx( lnVFP, 0, 0, '' ) && Find in container window
    do while lnWinCnt=0 and lnCNT<>0
      lnWinCnt = apiFindWindowEx( lnCNT, 0, 0, pncParentWindow ) && Look in container
      lnCNT  = apiFindWindowEx( lnVFP, lnCNT, 0, '' ) && Find next container window
    enddo
    if lnWinCNT<=0
      RETURN -1  && Couldnt find new parent window
    endif
  endif
else
  if vartype(pncParentWindow)='N'
    if pncParentWindow<0
      lnWinCnt = 0               && Use VFP Main Window
    else
      lnWinCnt = pncParentWindow && Use passed HWND
    endif
  else
    DEFINE WINDOW TakeWindowXoXoX TITLE &quot;TakeWindowXoXoX&quot; AT 0,0 Size 1,1
    SHOW WINDOW TakeWindowXoXoX
    * Find the empty-caption window inside VFP that contains &quot;TakeWindowXoXoX&quot;
    lnWinCNT =0
    lnCNT  = apiFindWindowEx( lnVFP, 0, 0, '' ) && Find first container window
    DO WHILE lnCnt<>0 and lnWinCnt=0
      lnWinCNT = apiFindWindowEx( lnCNT, 0, 0, 'TakeWindowXoXoX' ) && Find Marker Window
      if lnWinCnt=0
        lnCNT  = apiFindWindowEx( lnVFP, lnCNT, 0, '' ) && Find next container window
      endif
    ENDDO
    if lnWinCnt<>0
      lnWinCnt = lnCnt
    endif
    RELEASE WINDOW TakeWindowXoXoX
  endif
endif


DECLARE INTEGER SetParent in Win32API as apiSetParent ;
  INTEGER hWndChild, INTEGER hWndNewParent
     
if lnWinCnt<>0 && Use proper container window
  lnRes = apiSetParent( lnWHND, lnWinCnt )
else
  lnRes = apiSetParent( lnWHND, lnVFP )
endif
RETURN lnRes

PROCEDURE SetWinPos
LPARAM wHnd, X, Y, cWid, cHig, lRemBord

#define GWL_STYLE           (-16)
#define WS_BORDER           0x00800000
#define NOT_WS_BORDER       0xFF7FFFFF && 4286578687
#define SWP_ASYNCWINDOWPOS  0x4000
* The frame changed: send WM_NCCALCSIZE */
#define SWP_FRAMECHANGED    0x0020  

if lRemBord
  DECLARE INTEGER SetWindowLong IN user32; 
      LONG hWnd,; 
      INTEGER nIndex,; 
      LONG dwNewLong 
  *SetWindowLong( wHnd, GWL_STYLE, WS_BORDER )
  DECLARE LONG GetWindowLong IN user32; 
      LONG hWnd,; 
      INTEGER nIndex

  lnRet = SetWindowLong(wHND,GWL_STYLE, BITAND( NOT_WS_BORDER, GetWindowLong(wHND,GWL_STYLE)))
endif

DECLARE INTEGER SetWindowPos IN user32; 
    INTEGER hwnd,; 
    INTEGER hWndInsertAfter,; 
    INTEGER x,; 
    INTEGER y,; 
    INTEGER cx,; 
    INTEGER cy,; 
    INTEGER wFlags 
    
LOCAL lnFlags, lnInsideWHND

lnFlags = SWP_ASYNCWINDOWPOS
if lRemBord
 lnFlags = BITOR(lnFlags , SWP_FRAMECHANGED)
endif

lnInsideWHND = 0
* FindWindow(_Screen.caption)

SetWindowPos( wHnd, lnInsideWhnd, X, Y, cWid, cHig, lnFlags )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top