Results 1 to 3 of 3

Thread: API Minimize through Code?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    API Minimize through Code?

    I have an altered Userform that can be minimized and maximized through the API similar to code used in this thread:

    http://www.vbforums.com/showthread.php?t=243829

    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2.     (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3.  
    4. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    5.     (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    6.  
    7. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    8.     (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    9.  
    10. Private Const WS_MINIMIZEBOX = &H20000
    11. Private Const GWL_STYLE = (-16)
    12.  
    13. Private Sub AddMinBox()
    14.  
    15.     ' Add minimize button to UserForm.
    16.  
    17.     Dim hWnd As Long
    18.  
    19.     Select Case Int(Val(Application.Version))
    20.         Case 8      ' Office 97.
    21.             hWnd = FindWindow("ThunderXFrame", vbNullString)
    22.         Case 9, 10  ' Office 2000, XP
    23.             hWnd = FindWindow("ThunderDFrame", vbNullString)
    24.     End Select
    25.    
    26.     SetWindowLong hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) Or WS_MINIMIZEBOX
    27.    
    28. End Sub
    29.  
    30. Private Sub UserForm_Initialize()
    31.     AddMinBox
    32. End Sub

    What I need to be able to do is flip back and forth between the open form and the spreadsheet. I can't close the form and save variable info to globals, because the form only has one control: an ActiveX Reflections Console control that needs to stay open.

    The form is modeless but is still "always on top" so that even though I can interact with the spreadsheet, the form is in the way. This is why I made the form minimizable so to speak.

    Problem is, I have no idea how to minimze the form with code. It will not be obvious enough to the user to minimize the window themselves when needed, and I want the program to do it. Please let there be some genius here that can help me. I'll even take alternate solutions.

    Thanks,
    Last edited by mikeyc1204; Jun 30th, 2005 at 10:16 AM.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: API Minimize through Code?

    Not too sure, but can you not just hide the form (me.visible=false) until the user selects an icon on the tray or something? Or if it is excel, perhaps a menu button or a button on the spreadsheet to hide/show the form??

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: API Minimize through Code?

    That was my first thought too. Who knew you can't change a userform's 'visible' property?

    Compile error:

    Function or interface marked as restricted, or the function uses and Automation type not supported in Visual Basic

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