Results 1 to 8 of 8

Thread: Question on setting top window and reseting all other windows

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    Miami, Fl.
    Posts
    5

    Question Question on setting top window and reseting all other windows

    I have a question. I'm new to VB so I hope to be able to describe my question correctly. I created a form and set its dimensions to automatically fill the width of the screen and set the height at just over my text size. The purpose of this is to have a scrolling text run across the screen. Everything works fine, but I want my form/window as the top most window, always visible. I have gotten this to work with SetWindowPos. But my question is.....
    How can I make all my other windows/programs resize automatically to begin just under my top form. I don’t want my top form to cut off the title bars of my other programs. Kind of like docking - how AOLIM does on the side of the screen. Any ideas anyone?? Please?!?!?!

    Could I have been anyone different?

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Use EnumWindows API to get the handler of all the top level windows, use isWindowVisible API Function to check for the window's visibility and then use SetWindowRect API to set the coordinates of all the windows except of yours.
    Tell me If you can't understand.. I'll paste the code.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    Miami, Fl.
    Posts
    5
    I will take a look and try to figure it out for myself. Thanks for the help.
    Could I have been anyone different?

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    Miami, Fl.
    Posts
    5
    ok.... I could use some help now. I'm getting a little confused. I don't fully understand this process. Can you please give me a little more help/code
    Thanks
    Could I have been anyone different?

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    Miami, Fl.
    Posts
    5
    Anyone??
    Please
    Could I have been anyone different?

  6. #6
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Following code is not the best one.. lil buggy rather..but I've written it just now and i hope it'll atleast give you the understanding

    Add this code to a Module
    VB Code:
    1. Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
    2. Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    3. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    4. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    5. Private Const HWND_DESKTOP = 0
    6. Private Const SWP_SHOWWINDOW = &H40
    7. Private Type RECT
    8.         Left As Long
    9.         Top As Long
    10.         Right As Long
    11.         Bottom As Long
    12. End Type
    13. Dim mainRect As RECT
    14. Public Function EnumWindowsProc(ByVal thWnd As Long, ByVal lParam As Long) As Long
    15. Dim FHwnd As Long
    16. Dim txtLen As Long
    17. Dim tRect As RECT
    18. If Form1.hwnd <> thWnd Then
    19.   If IsWindowVisible(thWnd) Then
    20.     GetWindowRect thWnd, tRect
    21.     If tRect.Top < mainRect.Bottom Then
    22.         SetWindowPos thWnd, HWND_DESKTOP, tRect.Left, mainRect.Bottom, tRect.Right - tRect.Left, tRect.Bottom - tRect.Top, SWP_SHOWWINDOW
    23.     End If
    24.   End If
    25. End If
    26. EnumWindowsProc = True
    27. End Function
    28. Public Sub SetWindows()
    29. GetWindowRect Form1.hwnd, mainRect
    30. EnumWindows AddressOf EnumWindowsProc, 0
    31. End Sub
    And this on the form with a command button
    VB Code:
    1. Private Sub Command1_Click()
    2. SetWindows
    3. End Sub
    4.  
    5. Private Sub Form_Load()
    6. Me.Left = 0
    7. Me.Top = 0
    8. Me.Width = Screen.Width * Screen.TwipsPerPixelX
    9. Me.Height = 1000  'I liked it to be like that
    10.  
    11. End Sub

    I hope it helps

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    Miami, Fl.
    Posts
    5
    Awsome!!!
    Thanks!!!
    but... how do i get everything to reset to normal when I close that window??

    And....

    why do i have to run the SetWindow funtion of a command button, why cant I run it off of Form_Load()???

    Thanks again for all your help.


    Could I have been anyone different?

  8. #8
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    To reset the windows to their previous dimensions.. you'll have to save their previous settings and on Form's QueryUnload Event or Unload Event reset them all by calling the Functions say ResetWindow(u'll make this)..
    I coded on CommandButton for testing... you can/must code it on Load Event.

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