-
Nov 18th, 2012, 12:39 PM
#1
Thread Starter
PowerPoster
[RESOLVED] [VB6] - can i hide a control without using the ShowWindow() api function?
can i hide a control without using the ShowWindow() api function?
-
Nov 21st, 2012, 08:06 AM
#2
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.
-
Nov 21st, 2012, 08:26 AM
#3
Thread Starter
PowerPoster
Re: [VB6] - can i hide a control without using the ShowWindow() api function?
Originally Posted by Peter Swinkels
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
-
Mar 2nd, 2013, 11:32 AM
#4
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)
-
Mar 5th, 2013, 04:19 PM
#5
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6] - can i hide a control without using the ShowWindow() api functi
Originally Posted by Bonnie West
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|