PDFreader?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Lauwers

    PDFreader?

    Hello,

    With the API Shellexecute function I open a PDF document with the PDFreader,
    How can I set the position of the PDF Reader?
    Also With an API ???

    ShellExecute Me.hwnd, "Open", "Helpbestan d Q-Cycle.pdf", 0, 0, vbNormalFocus

    Now I have to set the position .

    Hope You can help me.

    Greets John.


  • J French

    #2
    Re: PDFreader?

    On Tue, 25 Nov 2003 09:20:59 +0100, "John Lauwers"
    <nobody@fictief .com> wrote:
    [color=blue]
    >Hello,
    >
    >With the API Shellexecute function I open a PDF document with the PDFreader,
    >How can I set the position of the PDF Reader?
    >Also With an API ???
    >
    >ShellExecute Me.hwnd, "Open", "Helpbestan d Q-Cycle.pdf", 0, 0, vbNormalFocus
    >
    >Now I have to set the position .[/color]

    You'll need to get the Windows Handle of the PDF Reader and then use
    the MoveWindow API

    SetWindowPos is an alternative

    Alternatively you could use the SetParent API to force the PDFReader
    into one of your Forms

    Comment

    • John Lauwers

      #3
      Re: PDFreader?

      Thanks J.French
      But can I now programatticaly use the print command of the PDF reader
      without pushing the print button?

      Greets John


      "J French" <erewhon@nowher e.com> schreef in bericht
      news:3fc32887.3 970869@news.btc lick.com...[color=blue]
      > On Tue, 25 Nov 2003 09:20:59 +0100, "John Lauwers"
      > <nobody@fictief .com> wrote:
      >[color=green]
      > >Hello,
      > >
      > >With the API Shellexecute function I open a PDF document with the[/color][/color]
      PDFreader,[color=blue][color=green]
      > >How can I set the position of the PDF Reader?
      > >Also With an API ???
      > >
      > >ShellExecute Me.hwnd, "Open", "Helpbestan d Q-Cycle.pdf", 0, 0,[/color][/color]
      vbNormalFocus[color=blue][color=green]
      > >
      > >Now I have to set the position .[/color]
      >
      > You'll need to get the Windows Handle of the PDF Reader and then use
      > the MoveWindow API
      >
      > SetWindowPos is an alternative
      >
      > Alternatively you could use the SetParent API to force the PDFReader
      > into one of your Forms[/color]


      Comment

      • J French

        #4
        Re: PDFreader?

        On Tue, 25 Nov 2003 11:23:06 +0100, "John Lauwers"
        <nobody@fictief .com> wrote:
        [color=blue]
        >Thanks J.French
        >But can I now programatticaly use the print command of the PDF reader
        >without pushing the print button?[/color]

        I assume that button responds to Ctl P

        - force the target App into focus, then ...

        // --- Force in Ctl O
        call keybd_event(VK_ CONTROL, 0, 0, 0)
        call keybd_event(VK_ P, 0, 0, 0)
        call keybd_event(VK_ P, 0, KEYEVENTF_KEYUP , 0)
        call keybd_event(VK_ CONTROL, 0, KEYEVENTF_KEYUP , 0)

        You could probably also use SendKeys


        Comment

        • Raoul Watson

          #5
          Re: PDFreader?


          "John Lauwers" <nobody@fictief .com> wrote in message
          news:3fc32d51$0 $22016$ba620e4c @reader3.news.s kynet.be...
          [color=blue]
          > But can I now programatticaly use the print command of the PDF reader
          > without pushing the print button?
          >
          > Greets John
          >[/color]

          John..

          There is an OCX that pdf users would have installed (comes with the reader).
          The name is pdf.ocx. If you use that in your component, you will be
          surprised what you can do with it.. this to include:

          pdfcontrol.prin t
          pdfcontrol.prin tpages
          pdfcontrol.left
          etc..

          I have no idea where these are documented but experimentation within VB (by
          just typing controlname <period> and watch the pop-up of procs and
          properties usually will be sufficient.


          Comment

          • John Lauwers

            #6
            Re: PDFreader?

            J.French,

            I will use SetParent API but how can a obtain the Hwnd from the PDFreader
            that I opened ?

            Greets John


            "J French" <erewhon@nowher e.com> schreef in bericht
            news:3fc32887.3 970869@news.btc lick.com...[color=blue]
            > On Tue, 25 Nov 2003 09:20:59 +0100, "John Lauwers"
            > <nobody@fictief .com> wrote:
            >[color=green]
            > >Hello,
            > >
            > >With the API Shellexecute function I open a PDF document with the[/color][/color]
            PDFreader,[color=blue][color=green]
            > >How can I set the position of the PDF Reader?
            > >Also With an API ???
            > >
            > >ShellExecute Me.hwnd, "Open", "Helpbestan d Q-Cycle.pdf", 0, 0,[/color][/color]
            vbNormalFocus[color=blue][color=green]
            > >
            > >Now I have to set the position .[/color]
            >
            > You'll need to get the Windows Handle of the PDF Reader and then use
            > the MoveWindow API
            >
            > SetWindowPos is an alternative
            >
            > Alternatively you could use the SetParent API to force the PDFReader
            > into one of your Forms[/color]


            Comment

            • J French

              #7
              Re: PDFreader?

              On Tue, 25 Nov 2003 12:28:47 +0100, "John Lauwers"
              <nobody@fictief .com> wrote:
              [color=blue]
              >J.French,
              >
              >I will use SetParent API but how can a obtain the Hwnd from the PDFreader
              >that I opened ?[/color]

              Not tonight - this is a bookmark

              Comment

              • J French

                #8
                Re: PDFreader?

                On Tue, 25 Nov 2003 22:46:57 +0000 (UTC), erewhon@nowhere .com (J
                French) wrote:
                [color=blue]
                >On Tue, 25 Nov 2003 12:28:47 +0100, "John Lauwers"
                ><nobody@fictie f.com> wrote:
                >[color=green]
                >>J.French,
                >>
                >>I will use SetParent API but how can a obtain the Hwnd from the PDFreader
                >>that I opened ?[/color]
                >
                >Not tonight - this is a bookmark[/color]

                Ok, goto www.AllAPI.net

                Download their API Guide and look at the example for Terminate Process

                The bit you want is: InstanceToWnd

                It would be wise *not* to use Shell, better use CreateProcess
                Although Shell returns a PID - it is reportedly not totally reliable
                Start with Shell and then replace it later

                I could cut and paste the bits you need, but you would be much better
                off spending a few minutes sniffing through the API Guide
                - besides you'll need the rest of it

                BTW don't use TerminateProces s - it is poison

                Try sending a WM_QUIT or WM_CLOSE message, well behaved Apps will
                close

                HTH

                Comment

                • Randy Birch

                  #9
                  Re: PDFreader?

                  If found them in the \adobe\acrobat\ reader\activex folder. In the VB
                  component's dialog it appears as "acrobat control for activex". I used the
                  component dialog to browse to that control (pdf.ocx) and select it, thus
                  causing it to become registered (it wasn't listed in my dialog), and two
                  lines of code did the trick.

                  --

                  Randy Birch
                  MVP Visual Basic

                  Please respond only to the newsgroups so all can benefit.


                  "Raoul Watson" <WatsonR@Intell igenCIA.com> wrote in message
                  news:9uGwb.1915 $nP3.892@nwrdny 03.gnilink.net. ..
                  :
                  : "John Lauwers" <nobody@fictief .com> wrote in message
                  : news:3fc32d51$0 $22016$ba620e4c @reader3.news.s kynet.be...
                  :
                  : > But can I now programatticaly use the print command of the PDF reader
                  : > without pushing the print button?
                  : >
                  : > Greets John
                  : >
                  :
                  : John..
                  :
                  : There is an OCX that pdf users would have installed (comes with the
                  reader).
                  : The name is pdf.ocx. If you use that in your component, you will be
                  : surprised what you can do with it.. this to include:
                  :
                  : pdfcontrol.prin t
                  : pdfcontrol.prin tpages
                  : pdfcontrol.left
                  : etc..
                  :
                  : I have no idea where these are documented but experimentation within VB
                  (by
                  : just typing controlname <period> and watch the pop-up of procs and
                  : properties usually will be sufficient.
                  :
                  :


                  Comment

                  • John Lauwers

                    #10
                    Re: PDFreader?

                    J.Frech,

                    The Shellexecute API doesn't return a handle it returns a long which
                    represents the error code when the function fails.

                    Greets John



                    "J French" <erewhon@nowher e.com> schreef in bericht
                    news:3fc49234.9 6573393@news.bt click.com...[color=blue]
                    > On Tue, 25 Nov 2003 22:46:57 +0000 (UTC), erewhon@nowhere .com (J
                    > French) wrote:
                    >[color=green]
                    > >On Tue, 25 Nov 2003 12:28:47 +0100, "John Lauwers"
                    > ><nobody@fictie f.com> wrote:
                    > >[color=darkred]
                    > >>J.French,
                    > >>
                    > >>I will use SetParent API but how can a obtain the Hwnd from the[/color][/color][/color]
                    PDFreader[color=blue][color=green][color=darkred]
                    > >>that I opened ?[/color]
                    > >
                    > >Not tonight - this is a bookmark[/color]
                    >
                    > Ok, goto www.AllAPI.net
                    >
                    > Download their API Guide and look at the example for Terminate Process
                    >
                    > The bit you want is: InstanceToWnd
                    >
                    > It would be wise *not* to use Shell, better use CreateProcess
                    > Although Shell returns a PID - it is reportedly not totally reliable
                    > Start with Shell and then replace it later
                    >
                    > I could cut and paste the bits you need, but you would be much better
                    > off spending a few minutes sniffing through the API Guide
                    > - besides you'll need the rest of it
                    >
                    > BTW don't use TerminateProces s - it is poison
                    >
                    > Try sending a WM_QUIT or WM_CLOSE message, well behaved Apps will
                    > close
                    >
                    > HTH[/color]


                    Comment

                    • John Lauwers

                      #11
                      Re: PDFreader?

                      Raoul,

                      I don't won't to use this ocx because when you do the mail button and other
                      buttons seems to be gone, and this button I need to mail my PDF document.

                      Greets John


                      "Raoul Watson" <WatsonR@Intell igenCIA.com> schreef in bericht
                      news:9uGwb.1915 $nP3.892@nwrdny 03.gnilink.net. ..[color=blue]
                      >
                      > "John Lauwers" <nobody@fictief .com> wrote in message
                      > news:3fc32d51$0 $22016$ba620e4c @reader3.news.s kynet.be...
                      >[color=green]
                      > > But can I now programatticaly use the print command of the PDF reader
                      > > without pushing the print button?
                      > >
                      > > Greets John
                      > >[/color]
                      >
                      > John..
                      >
                      > There is an OCX that pdf users would have installed (comes with the[/color]
                      reader).[color=blue]
                      > The name is pdf.ocx. If you use that in your component, you will be
                      > surprised what you can do with it.. this to include:
                      >
                      > pdfcontrol.prin t
                      > pdfcontrol.prin tpages
                      > pdfcontrol.left
                      > etc..
                      >
                      > I have no idea where these are documented but experimentation within VB[/color]
                      (by[color=blue]
                      > just typing controlname <period> and watch the pop-up of procs and
                      > properties usually will be sufficient.
                      >
                      >[/color]


                      Comment

                      • J French

                        #12
                        Re: PDFreader?

                        On Thu, 27 Nov 2003 10:33:37 +0100, "John Lauwers"
                        <nobody@fictief .com> wrote:
                        [color=blue]
                        >J.Frech,
                        >
                        >The Shellexecute API doesn't return a handle it returns a long which
                        >represents the error code when the function fails.[/color]

                        No you get an InstanceHandle
                        - which may contain Error Codes

                        ShellExecuteEx (optionally) returns a hProcess

                        CreateProcess strikes me as the best solution

                        Here is something I have hacked together

                        Option Explicit

                        ' J French - 27th Nov 2003
                        ' Shell and Re-Parent
                        ' hacked from MS and KPD

                        Private Declare Function ShellExecute _
                        Lib "shell32.dl l" _
                        Alias "ShellExecu teA" _
                        (ByVal hwnd As Long, _
                        ByVal lpOperation As String, _
                        ByVal lpFile As String, _
                        ByVal lpParameters As String, _
                        ByVal lpDirectory As String, _
                        ByVal nShowCmd As Long) As Long
                        Const SW_SHOWNORMAL = 1

                        Private Declare Function MoveWindow _
                        Lib "user32" _
                        (ByVal hwnd As Long, _
                        ByVal x As Long, _
                        ByVal y As Long, _
                        ByVal nWidth As Long, _
                        ByVal nHeight As Long, _
                        ByVal bRepaint As Long) As Long

                        Private Declare Function FindWindow _
                        Lib "user32" _
                        Alias "FindWindow A" _
                        (ByVal lpClassName As Long, _
                        ByVal lpWindowName As Long) As Long
                        Private Declare Function GetParent _
                        Lib "user32" (ByVal hwnd As Long) As Long
                        Private Declare Function SetParent _
                        Lib "user32" _
                        (ByVal hWndChild As Long, _
                        ByVal hWndNewParent As Long) As Long
                        Private Declare Function GetWindowThread ProcessId _
                        Lib "user32" _
                        (ByVal hwnd As Long, _
                        lpdwProcessId As Long) As Long
                        Private Declare Function GetWindow _
                        Lib "user32" _
                        (ByVal hwnd As Long, _
                        ByVal wCmd As Long) As Long
                        Private Declare Function LockWindowUpdat e _
                        Lib "user32" _
                        (ByVal hwndLock As Long) As Long
                        Private Declare Function GetDesktopWindo w _
                        Lib "user32" () As Long
                        Private Declare Function DestroyWindow _
                        Lib "user32" (ByVal hwnd As Long) As Long
                        Private Declare Function TerminateProces s _
                        Lib "kernel32" _
                        (ByVal hProcess As Long, _
                        ByVal uExitCode As Long) As Long
                        Private Declare Function GetCurrentProce ss _
                        Lib "kernel32" () As Long
                        Private Declare Function Putfocus _
                        Lib "user32" _
                        Alias "SetFocus" _
                        (ByVal hwnd As Long) As Long
                        Const GW_HWNDNEXT = 2


                        Private Type STARTUPINFO
                        cb As Long
                        lpReserved As String
                        lpDesktop As String
                        lpTitle As String
                        dwX As Long
                        dwY As Long
                        dwXSize As Long
                        dwYSize As Long
                        dwXCountChars As Long
                        dwYCountChars As Long
                        dwFillAttribute As Long
                        dwFlags As Long
                        wShowWindow As Integer
                        cbReserved2 As Integer
                        lpReserved2 As Long
                        hStdInput As Long
                        hStdOutput As Long
                        hStdError As Long
                        End Type

                        Private Type PROCESS_INFORMA TION
                        hProcess As Long
                        hThread As Long
                        dwProcessID As Long
                        dwThreadID As Long
                        End Type


                        Private Declare Function CreateProcessA _
                        Lib "kernel32" _
                        (ByVal lpApplicationNa me As String, _
                        ByVal lpCommandLine As String, _
                        ByVal lpProcessAttrib utes As Long, _
                        ByVal lpThreadAttribu tes As Long, _
                        ByVal bInheritHandles As Long, _
                        ByVal dwCreationFlags As Long, _
                        ByVal lpEnvironment As Long, _
                        ByVal lpCurrentDirect ory As String, _
                        lpStartupInfo As STARTUPINFO, _
                        lpProcessInform ation As PROCESS_INFORMA TION) As Long

                        Private Declare Function WaitForSingleOb ject _
                        Lib "kernel32" _
                        (ByVal hHandle As Long, _
                        ByVal dwMilliseconds As Long) As Long

                        Private Declare Function CloseHandle Lib "kernel32" _
                        (ByVal hObject As Long) As Long

                        Private Const NORMAL_PRIORITY _CLASS = &H20&


                        Dim mWnd As Long

                        Function InstanceToWnd(B yVal target_pid As Long) As Long
                        Dim test_hwnd As Long, _
                        test_pid As Long, _
                        test_thread_id As Long
                        'Find the first window
                        test_hwnd = FindWindow(ByVa l 0&, ByVal 0&)
                        Do While test_hwnd <> 0
                        'Check if the window isn't a child
                        If GetParent(test_ hwnd) = 0 Then
                        'Get the window's thread
                        test_thread_id = GetWindowThread ProcessId(test_ hwnd, _
                        test_pid)
                        If test_pid = target_pid Then
                        InstanceToWnd = test_hwnd
                        Exit Do
                        End If
                        End If
                        'retrieve the next window
                        test_hwnd = GetWindow(test_ hwnd, GW_HWNDNEXT)
                        Loop
                        End Function

                        Public Function ExecCmd(cmdline $) As Long
                        Dim proc As PROCESS_INFORMA TION
                        Dim start As STARTUPINFO
                        Dim Ret&

                        ' Initialize the STARTUPINFO structure:
                        start.cb = Len(start)

                        ' Start the shelled application:
                        Ret& = CreateProcessA( vbNullString, cmdline$, _
                        0&, 0&, 1&, _
                        NORMAL_PRIORITY _CLASS, _
                        0&, vbNullString, _
                        start, proc)
                        ' --- let it start - this seems important
                        Call WaitForSingleOb ject(proc.hProc ess, 500)
                        If Ret Then
                        ExecCmd = InstanceToWnd(p roc.dwProcessID )
                        Me.Print Ret, ExecCmd
                        Call CloseHandle(pro c.hThread)
                        Call CloseHandle(pro c.hProcess)
                        End If

                        End Function


                        Private Sub Command1_Click( )
                        'KPD-Team 1999
                        'URL: http://www.allapi.net/
                        'E-Mail: KPDTeam@Allapi. net
                        ' ---
                        Me.AutoRedraw = True

                        'Lock the window update
                        LockWindowUpdat e GetDesktopWindo w

                        'Execute notepad.Exe
                        mWnd = ExecCmd("notepa d.exe")
                        'If mWnd = 0 Then MsgBox "Error starting the app"

                        Me.Print Str$(mWnd)
                        ' Set the notepad's parent
                        If mWnd Then
                        SetParent mWnd, Me.hwnd
                        ' -
                        Me.ScaleMode = vbPixels
                        Call MoveWindow(mWnd , 0, 0, _
                        Me.ScaleWidth, _
                        Me.ScaleHeight, 1)
                        ' Put the focus on notepad
                        Putfocus mWnd
                        End If

                        ' Unlock windowupdate
                        LockWindowUpdat e False
                        End Sub
                        Private Sub Form_Unload(Can cel As Integer)
                        'Unload notepad
                        'DestroyWindow mWnd
                        'End this program
                        End Sub


                        Comment

                        • Raoul Watson

                          #13
                          Re: PDFreader?


                          "John Lauwers" <nobody@fictief .com> wrote in message
                          news:3fc5c52f$0 $1809$ba620e4c@ reader2.news.sk ynet.be...
                          [color=blue]
                          >
                          > I don't won't to use this ocx because when you do the mail button and[/color]
                          other[color=blue]
                          > buttons seems to be gone, and this button I need to mail my PDF document.
                          >[/color]

                          "Mail button?" .. I've used reader for ages and don't remember seeing that.

                          But [erhaps it is an Adobe Reader PLUG-IN that is installed on your PC. The
                          OCX will not load plug-ins If that's the case, relying on it for your
                          product would be silly since your customer may not have it. And if your
                          argument is that you need to use it for yourself, why on earth write a VB
                          app. Just not just use the Reader.


                          Comment

                          • John Lauwers

                            #14
                            Re: PDFreader?

                            Raoul,

                            It is a sort of organizer I wrote in vb that scans documents and convert it
                            automatically in PDF documents. The user can store in a database what sort
                            of pdf document it is( ex. document of an elektronic component), an when he
                            scaned for instance 2 documents of that component you just do a search of
                            that component and there are the 2 pdf's with the information of that
                            component.
                            No more paper, but al in PDF's on the computer.
                            The mail button I want to use to mail a specific document to a client.

                            Hope this clears out your remark.

                            Greets John


                            "Raoul Watson" <WatsonR@Intell igenCIA.com> schreef in bericht
                            news:RVdyb.1713 0$lF6.1031@nwrd ny01.gnilink.ne t...[color=blue]
                            >
                            > "John Lauwers" <nobody@fictief .com> wrote in message
                            > news:3fc5c52f$0 $1809$ba620e4c@ reader2.news.sk ynet.be...
                            >[color=green]
                            > >
                            > > I don't won't to use this ocx because when you do the mail button and[/color]
                            > other[color=green]
                            > > buttons seems to be gone, and this button I need to mail my PDF[/color][/color]
                            document.[color=blue][color=green]
                            > >[/color]
                            >
                            > "Mail button?" .. I've used reader for ages and don't remember seeing[/color]
                            that.[color=blue]
                            >
                            > But [erhaps it is an Adobe Reader PLUG-IN that is installed on your PC.[/color]
                            The[color=blue]
                            > OCX will not load plug-ins If that's the case, relying on it for your
                            > product would be silly since your customer may not have it. And if your
                            > argument is that you need to use it for yourself, why on earth write a VB
                            > app. Just not just use the Reader.
                            >
                            >[/color]


                            Comment

                            Working...