|
-
Mar 15th, 2009, 04:55 PM
#1
Thread Starter
Hyperactive Member
Launch a program and set its size
I am using ShellExecute to open a PDF file. Can I set the size of this window ? I need to be sure there is enough room for some buttons my app needs to make visible at the same time, rather than hidden behind the Adobe window. I'm tried using SetWindowPos to bring them to the front, but that approach doesn't allow the user to access my buttons and the Adobe window.
-
Mar 15th, 2009, 06:44 PM
#2
Re: Launch a program and set its size
If you have the hWnd of the window, you can use SetWindowPos, MoveWindow. Maybe you were not using SetWindowPos correctly? More information regarding the problem might help us help you. Also, if the adobe window opens full screen, it should be restored before it is resized.
Last edited by LaVolpe; Mar 15th, 2009 at 06:54 PM.
-
Mar 15th, 2009, 07:38 PM
#3
Thread Starter
Hyperactive Member
Re: Launch a program and set its size
I have the hWnd of my app, but not that of the Adobe window. I'm using SetWindowPos to ensure my buttons are visible, and that works. The user can move and resize the Adobe window, but if my app's form with buttons is touched, the Adobe window is sent to the back of the stack. To complete the picture, I have a full screen parent form. It shows a modal form with a few buttons, and launches Adobe as an external program - it was being shown using pdf.ocx, but this restricts to a certain version of Adobe, which is about to change. By showing the PDF via it's extension, it doesn't matter what version of Adobe the user has. So the user has to move or click a button, and move or re-size the Adobe window without one making the other disapprear
-
Mar 15th, 2009, 07:49 PM
#4
Re: Launch a program and set its size
Adobe windows probably have a set class name for their windows. If this is true, after you shell the .pdf file, you can use FindWindow to locate the Adobe window (taking into consideration for a second or two or three) for it to open. There are other ways too: Using shellexecute, you can create a process for the .pdf to run in, and since you know its PID (process ID), you can locate the specific file you launched by using the GetWindowThreadProcessID api. This will come in handy if there are more than one Adobe windows opened at the same time. There are many posted examples on how to get the hWnd from a PID.
Anyway, once you get the hWnd, you can now have far more control. Here are some options
1. Easiest, but not really recommended: Use SetParent API and place the Adobe window directly onto your form. That way it cannot be hidden behind your fullscreen form.
2. Set the Adobe window to be top most, that way if someone clicks on your form by mistake, it won't go behind your form. Of course, now you need to move and or size it to exactly where you want: SetWndowPos or MoveWindow
Here is one possible gotcha. I don't use Adobe too often, but I do notice that sometimes it pops up with another window that asks if I want to upgrade or not, or download a patch or not. This window may or may not cause you some problems if and when it does pop up.
-
Mar 15th, 2009, 08:42 PM
#5
Thread Starter
Hyperactive Member
Re: Launch a program and set its size
Thanks for your help. I like your approach to use ShellExecute to create a process. But how ? This gives me a PID which I use to view the PDF with Adobe in that process. But how ? I am about to search as to how to get the hWnd from the PID. You would make my search easier if you tell me how. I understand that from there it should be plain sailing.
-
Mar 15th, 2009, 09:06 PM
#6
Re: Launch a program and set its size
To ensure we are all on the same page, would you mind posting the bit of code (the routine) that shellexecutes and describe the parameters that routine receives, if any?
-
Mar 15th, 2009, 09:21 PM
#7
Thread Starter
Hyperactive Member
Re: Launch a program and set its size
The form containing the buttons has
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
Then where the PDF document is to be shown,
If ShellExecute(Me.hWnd, "Open", strPath, _
vbNullString, "C:\", 1) = 0 Then Resume Next
-
Mar 15th, 2009, 09:29 PM
#8
Re: Launch a program and set its size
Take a look at this version of using shell APIs. You will get a PID
http://www.vbforums.com/showthread.php?t=512887
To retrieve the hWnd of a window in that process... Look at this thread. A few ways of finding the PID are discussed. The one in reply #9 is an easy one, but in order to find the hWnd to test for the PID, you'll have to enumerate the windows. There are a few ways of doing this, but EnumWindows API is probably as easy as some of the others
-
Mar 15th, 2009, 11:12 PM
#9
Addicted Member
Re: Launch a program and set its size
Have you considered embedding the AcroPDF.dll component to allow viewing PDF files within your program?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|