469,353 Members | 2,066 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

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", "Helpbestand Q-Cycle.pdf", 0, 0, vbNormalFocus

Now I have to set the position .

Hope You can help me.

Greets John.
Jul 17 '05 #1
13 4743
On Tue, 25 Nov 2003 09:20:59 +0100, "John Lauwers"
<no****@fictief.com> wrote:
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", "Helpbestand Q-Cycle.pdf", 0, 0, vbNormalFocus

Now I have to set the position .


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
Jul 17 '05 #2
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" <er*****@nowhere.com> schreef in bericht
news:3f**************@news.btclick.com...
On Tue, 25 Nov 2003 09:20:59 +0100, "John Lauwers"
<no****@fictief.com> wrote:
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", "Helpbestand Q-Cycle.pdf", 0, 0, vbNormalFocus
Now I have to set the position .


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

Jul 17 '05 #3
On Tue, 25 Nov 2003 11:23:06 +0100, "John Lauwers"
<no****@fictief.com> wrote:
Thanks J.French
But can I now programatticaly use the print command of the PDF reader
without pushing the print button?


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
Jul 17 '05 #4

"John Lauwers" <no****@fictief.com> wrote in message
news:3f***********************@reader3.news.skynet .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.print
pdfcontrol.printpages
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.
Jul 17 '05 #5
J.French,

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

Greets John
"J French" <er*****@nowhere.com> schreef in bericht
news:3f**************@news.btclick.com...
On Tue, 25 Nov 2003 09:20:59 +0100, "John Lauwers"
<no****@fictief.com> wrote:
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", "Helpbestand Q-Cycle.pdf", 0, 0, vbNormalFocus
Now I have to set the position .


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

Jul 17 '05 #6
On Tue, 25 Nov 2003 12:28:47 +0100, "John Lauwers"
<no****@fictief.com> wrote:
J.French,

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


Not tonight - this is a bookmark
Jul 17 '05 #7
On Tue, 25 Nov 2003 22:46:57 +0000 (UTC), er*****@nowhere.com (J
French) wrote:
On Tue, 25 Nov 2003 12:28:47 +0100, "John Lauwers"
<no****@fictief.com> wrote:
J.French,

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


Not tonight - this is a bookmark


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 TerminateProcess - it is poison

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

HTH
Jul 17 '05 #8
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
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Raoul Watson" <Wa*****@IntelligenCIA.com> wrote in message
news:9u****************@nwrdny03.gnilink.net...
:
: "John Lauwers" <no****@fictief.com> wrote in message
: news:3f***********************@reader3.news.skynet .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.print
: pdfcontrol.printpages
: 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.
:
:
Jul 17 '05 #9
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" <er*****@nowhere.com> schreef in bericht
news:3f***************@news.btclick.com...
On Tue, 25 Nov 2003 22:46:57 +0000 (UTC), er*****@nowhere.com (J
French) wrote:
On Tue, 25 Nov 2003 12:28:47 +0100, "John Lauwers"
<no****@fictief.com> wrote:
J.French,

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


Not tonight - this is a bookmark


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 TerminateProcess - it is poison

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

HTH

Jul 17 '05 #10
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" <Wa*****@IntelligenCIA.com> schreef in bericht
news:9u****************@nwrdny03.gnilink.net...

"John Lauwers" <no****@fictief.com> wrote in message
news:3f***********************@reader3.news.skynet .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.print
pdfcontrol.printpages
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.

Jul 17 '05 #11
On Thu, 27 Nov 2003 10:33:37 +0100, "John Lauwers"
<no****@fictief.com> wrote:
J.Frech,

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


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.dll" _
Alias "ShellExecuteA" _
(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 "FindWindowA" _
(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 GetWindowThreadProcessId _
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 LockWindowUpdate _
Lib "user32" _
(ByVal hwndLock As Long) As Long
Private Declare Function GetDesktopWindow _
Lib "user32" () As Long
Private Declare Function DestroyWindow _
Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function TerminateProcess _
Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
Private Declare Function GetCurrentProcess _
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_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function CreateProcessA _
Lib "kernel32" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function WaitForSingleObject _
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(ByVal 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(ByVal 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 = GetWindowThreadProcessId(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_INFORMATION
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 WaitForSingleObject(proc.hProcess, 500)
If Ret Then
ExecCmd = InstanceToWnd(proc.dwProcessID)
Me.Print Ret, ExecCmd
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
End If

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

'Lock the window update
LockWindowUpdate GetDesktopWindow

'Execute notepad.Exe
mWnd = ExecCmd("notepad.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
LockWindowUpdate False
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Unload notepad
'DestroyWindow mWnd
'End this program
End Sub
Jul 17 '05 #12

"John Lauwers" <no****@fictief.com> wrote in message
news:3f**********************@reader2.news.skynet. be...

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.


"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.
Jul 17 '05 #13
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" <Wa*****@IntelligenCIA.com> schreef in bericht
news:RV******************@nwrdny01.gnilink.net...

"John Lauwers" <no****@fictief.com> wrote in message
news:3f**********************@reader2.news.skynet. be...

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.


"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.

Jul 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by bohemia | last post: by
5 posts views Thread by George Durzi | last post: by
5 posts views Thread by Rainer Queck | last post: by
2 posts views Thread by Tim Reed | last post: by
reply views Thread by weicheong | last post: by
3 posts views Thread by anithaapr05 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.