[RESOLVED] [VB6] - can i hide a control without using the ShowWindow() api function?-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] [VB6] - can i hide a control without using the ShowWindow() api function?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,923

    Resolved [RESOLVED] [VB6] - can i hide a control without using the ShowWindow() api function?

    can i hide a control without using the ShowWindow() api function?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    296

    Re: [VB6] - can i hide a control without using the ShowWindow() api function?

    I assume you're already aware of the "Visible" property for Visual Basic controls. Here is some code that hides windows without using the ShowWindow API function:

    Code:
    Option Explicit
    
    Private Const GWL_STYLE As Long = -16&
    Private Const WS_VISIBLE As Long = &H10000000
    
    Private Declare Function GetParent Lib "User32.dll" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowLongA Lib "User32.dll" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLongA Lib "User32.dll" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function UpdateWindow Lib "User32.dll" (ByVal lhwnd As Long) As Long
    
    Private Sub HideWindow(WindowH As Long)
    Dim Styles As Long
    
    Styles = GetWindowLongA(WindowH, GWL_STYLE)
    SetWindowLongA WindowH, GWL_STYLE, (Styles Xor WS_VISIBLE)
    
    RefreshWindow WindowH
    End Sub
    
    Public Sub Main()
    Dim WindowH As Long
    
    WindowH = CLng(Val(InputBox$("Window handle:", , "0")))
    If WindowH = 0 Then Exit Sub
    
    HideWindow WindowH
    End Sub
    
    Public Sub RefreshWindow(ByVal WindowH As Long)
    Do
       UpdateWindow WindowH
       WindowH = GetParent(WindowH)
       DoEvents
    Loop Until WindowH = 0
    End Sub
    People could help you better if you explained why you don't want to use the ShowWindow API function.
    Last edited by Peter Swinkels; Nov 21st, 2012 at 08:33 AM.

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,923

    Re: [VB6] - can i hide a control without using the ShowWindow() api function?

    Quote Originally Posted by Peter Swinkels View Post
    I assume you're already aware of the "Visible" property for Visual Basic controls. Here some code that hides windows without using the ShowWindow API function:

    Code:
    Option Explicit
    
    Private Const GWL_STYLE As Long = -16&
    Private Const WS_VISIBLE As Long = &H10000000
    
    Private Declare Function GetParent Lib "User32.dll" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowLongA Lib "User32.dll" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLongA Lib "User32.dll" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function UpdateWindow Lib "User32.dll" (ByVal lhwnd As Long) As Long
    
    Private Sub HideWindow(WindowH As Long)
    Dim Styles As Long
    
    Styles = GetWindowLongA(WindowH, GWL_STYLE)
    SetWindowLongA WindowH, GWL_STYLE, (Styles Xor WS_VISIBLE)
    
    RefreshWindow WindowH
    End Sub
    
    Public Sub Main()
    Dim WindowH As Long
    
    WindowH = CLng(Val(InputBox$("Window handle:", , "0")))
    If WindowH = 0 Then Exit Sub
    
    HideWindow WindowH
    End Sub
    
    Public Sub RefreshWindow(ByVal WindowH As Long)
    Do
       UpdateWindow WindowH
       WindowH = GetParent(WindowH)
       DoEvents
    Loop Until WindowH = 0
    End Sub
    People could help you better if you explained why you don't want to use the ShowWindow API function.
    because isn't working in these case
    i have another question that can go out of the topic, but i have another thread for that
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    3,187

    Re: [RESOLVED] [VB6] - can i hide a control without using the ShowWindow() api functi

    SetWindowPos can also hide/show a control:

    Code:
    Private Const SWP_NOSIZE     As Long = &H1  'Retains the current size (ignores the cx and cy parameters)
    Private Const SWP_NOMOVE     As Long = &H2  'Retains the current position (ignores X and Y parameters)
    Private Const SWP_NOZORDER   As Long = &H4  'Retains the current Z order (ignores the hWndInsertAfter parameter)
    Private Const SWP_SHOWWINDOW As Long = &H40 'Displays the window
    Private Const SWP_HIDEWINDOW As Long = &H80 'Hides the window
    
    Private Declare Function SetWindowPos Lib "user32.dll" ( _
                 ByVal hWnd As Long, _
        Optional ByVal hWndInsertAfter As Long, _
        Optional ByVal X As Long, Optional ByVal Y As Long, _
        Optional ByVal cx As Long, Optional ByVal cy As Long, _
        Optional ByVal uFlags As Long _
    ) As Long
    
    Public Sub HideOrShowControl(ByRef Ctrl As Control, Optional ByVal Show As Boolean)
        Const SWP_FLAGS = SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOZORDER
    
        On Error Resume Next
        If Show Then
            SetWindowPos Ctrl.hWnd, uFlags:=SWP_FLAGS Or SWP_SHOWWINDOW
        Else
            SetWindowPos Ctrl.hWnd, uFlags:=SWP_FLAGS Or SWP_HIDEWINDOW
        End If
    End Sub
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,923

    Re: [RESOLVED] [VB6] - can i hide a control without using the ShowWindow() api functi

    Quote Originally Posted by Bonnie West View Post
    SetWindowPos can also hide/show a control:

    Code:
    Private Const SWP_NOSIZE     As Long = &H1  'Retains the current size (ignores the cx and cy parameters)
    Private Const SWP_NOMOVE     As Long = &H2  'Retains the current position (ignores X and Y parameters)
    Private Const SWP_NOZORDER   As Long = &H4  'Retains the current Z order (ignores the hWndInsertAfter parameter)
    Private Const SWP_SHOWWINDOW As Long = &H40 'Displays the window
    Private Const SWP_HIDEWINDOW As Long = &H80 'Hides the window
    
    Private Declare Function SetWindowPos Lib "user32.dll" ( _
                 ByVal hWnd As Long, _
        Optional ByVal hWndInsertAfter As Long, _
        Optional ByVal X As Long, Optional ByVal Y As Long, _
        Optional ByVal cx As Long, Optional ByVal cy As Long, _
        Optional ByVal uFlags As Long _
    ) As Long
    
    Public Sub HideOrShowControl(ByRef Ctrl As Control, Optional ByVal Show As Boolean)
        Const SWP_FLAGS = SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOZORDER
    
        On Error Resume Next
        If Show Then
            SetWindowPos Ctrl.hWnd, uFlags:=SWP_FLAGS Or SWP_SHOWWINDOW
        Else
            SetWindowPos Ctrl.hWnd, uFlags:=SWP_FLAGS Or SWP_HIDEWINDOW
        End If
    End Sub
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.