473,382 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 4827
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bohemia | last post by:
Hi all, I using visual c++ to creat a dll to wrapper a class that provided by another library.So I add the .lib to my win32 dll project under the link .and in my project I add some header files...
5
by: George Durzi | last post by:
I currently have an href inside of an asp:repeater <a href='<%# String.Concat("PDFReader.aspx?id=", DataBinder.Eval(Container.DataItem, "ProductUniqueId")) %>' target="_blank">View</a> ...
7
by: Brian Parker | last post by:
I'm reading PDF files in C#. I read them in using a TextReader then I parse out the pieces I want like the CreationDate, Author, etc. Sometimes, the PDF file is encrypted and I get binary junk...
5
by: Rainer Queck | last post by:
Hello NG, Is it possible to share the settings of an application with a class libreary? In my case I have a application and a set of different reports (home made) put into a class library. The...
2
by: Tim Reed | last post by:
Hello ... my Dad is dabbling in VB & has a question about invoking a PDF (to display a help file or manual). Myself, I don't know VB - but I *do* know how to post to a NG <g>. If anyone has a...
0
by: bartels | last post by:
hello everybody, i'm new with itextsharp and want to write things in an existing pdf. i've got a predesigned pdf. on that pdf i have to write some lines. string formFile =...
0
by: uxpalan | last post by:
Hi I am trying to parse the contents of the PDF with iTextSharp using : PdfReader reader = new PdfReader("Test.pdf"); reader.GetPageContent(pageNumber); byte pageContentByteArray; I am...
0
by: weicheong | last post by:
Hi guys, i hav successfully retrieve xmpmetadata from a pdf file and load it in a memeory stream. My current problem is to create another function such that i can directly use the xmpmetadata from...
3
by: anithaapr05 | last post by:
Hi All How to read existing pdf file content using asp.net Thanks Anitha
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.