Results 1 to 10 of 10

Thread: Tile Vertically

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    17

    Tile Vertically

    Hello,

    I am trying to:

    1) minimize all windows
    2) open two new explorer windows
    3) tile them vertically

    If I comment out code, I can do each one indivually and they all work, but when I put them all together I cannot get the new windows to tile vertically. Here is my code:

    Private Sub Form_Load()
    Me.Hide

    Dim oshell As Shell
    Set oshell = New Shell

    oshell.MinimizeAll

    Shell "explorer.exe", vbNormalNoFocus
    Shell "explorer.exe", vbNormalNoFocus

    oshell.TileVertically

    End

    End Sub


    Any suggestions? This is driving me crazy!?!?!?

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Tile Vertically

    Never used Shell in VB, but it would seem to me that you would want to use:
    oshell "explorer.exe", vbNormalNoFocus
    rather than:
    Shell "explorer.exe", vbNormalNoFocus

    You code isn't using your new instance of Shell.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    17

    Re: Tile Vertically

    Yeah, I tried using:

    oshell "explorer.exe", vbNormalFocus

    but I kept getting run-time error 438: Object doesn't support this property or method. That's why I tried just using

    shell "explorer.exe", vbNormalFocus

    which at least doesn't give me runtime errors.

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Tile Vertically

    After I submitted my post, I realized that there is probably some method in oshell that you have to use, just as you do in oshell.TileVertically.

    How are you referencing Shell? I dropped your code into the onload sub for a new form and get a "User-defined type not defined" compile error.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    17

    Re: Tile Vertically

    I added a reference to shell32.dll through the References window, so I think I have that part of it set up properly. The code I posted is the all the code I am using.

    If I comment everything out except for the oshell.tilevertically, it will properly tile the open windows on my desktop.

    If I comment out everything except for oshell.minimizeall and the two commands to open the 'explore.exe', it minimizes and opens the two windows properly.

    It just doesn't work when I put the two together. I'm relatively new to VB, but I really can't see why it isn't working.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Tile Vertically

    I would assume it isnt working because there is no delay between opening the windows.

    The " Shell ... " command runs asynchronously, so the statement is run but doesnt wait for Explorer to finish opening before executing the next statement.

    Unfortunately at the moment I cant think of a way to check that the Explorer windows have opened, so I would suggest that you add a "DoEvents" (or msgbox for now to see it happen) after each 'Shell "Explorer..' line, eg:

    Shell "explorer.exe", vbNormalNoFocus
    DoEvents
    Shell "explorer.exe", vbNormalNoFocus
    DoEvents

  7. #7
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Tile Vertically

    I'm not clear as to what you mean by "comment everything out except for ...".

    Anyway, I did some searching and found the following at MSDN:
    http://msdn.microsoft.com/library/de...hell_intro.asp

    Maybe you can find some help there.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    17

    Re: Tile Vertically

    Si,

    I think you are on the right track! I used a Msgbox after opening the windows and then it tiled correctly after clicking "OK". So I guess I need a way to pause before going to the tile command.

    I tried using a For-Next loop from 1 to 1000 but that didn't work. What should the count be to delay for about 1 second??

    Thanks

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Tile Vertically

    Unfortunately VB is clever and realises that an empty loop doesnt need to be run. There is also the problem that code runs at different speeds on different computers (and at different times). If you really want to pause, you should use the Sleep API (search this forum for examples).

    However, pausing isn't the way to do it, as you cannot predict accurately how long it will take to open those windows. I had a quick search on this site and found an idea that seems to work for me (from post 26 in this thread).

    What this basically does is keep track of which window is active, and waits until the active window changes (note that this method may fail if the user opens/activates a window while this code is running).

    Put this into the "general declarations":
    VB Code:
    1. Private Declare Function GetActiveWindow Lib "user32" () As Long
    and this in place of the two "Shell ..." lines:
    VB Code:
    1. Dim lActiveWindow As Long
    2. DoEvents
    3.  
    4. lActiveWindow = GetActiveWindow
    5. Shell "explorer.exe", vbNormalNoFocus
    6. Do
    7.   DoEvents
    8. Loop While lActiveWindow = GetActiveWindow
    9.  
    10. lActiveWindow = GetActiveWindow
    11. Shell "explorer.exe", vbNormalNoFocus
    12. Do
    13.   DoEvents
    14. Loop While lActiveWindow = GetActiveWindow

    It's not the ideal solution (which I don't know!), but it should hopefully do the job.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    17

    Re: Tile Vertically

    Si,

    After trying your suggestions I still couldn't get it to work. Eventually, this is what I added:

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Public Sub Wait(Seconds As Single)

    Dim lMilliSeconds As Long
    lMilliSeconds = Seconds * 1000
    Sleep lMilliSeconds

    End Sub

    Now it works!!

    Thanks for all your help.

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