Results 1 to 9 of 9

Thread: Launch a program and set its size

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    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

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    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.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    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

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    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
  •  



Click Here to Expand Forum to Full Width