Search Tools Links Login

First time ever! Clear the Debug/Immediate window with code!

For the first time ever, a code that can clear the debug window from code!
It's actually a cheat, since VB5-VB6 doesn't allow to clear the window without stopping the running project - the program sets the focus on the debug window, go to the last char and start printing a lot of empty lines - effectively getting rid of all clutter visible on the window.

Original Author: José Lucio Gama




Win32 API knowledge



Side Effects


API Declarations

FindWindow, SetForegroundWindow and SetFocus


Put this on the top of your form:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Then, paste this on your code:
Private Sub clearDebug()
  'this will try to get the handle to your
  'Immediate window. To make this work on
  'VB4, you can change the string "Immediate"
  'to "Debug"
  parent_hwnd = FindWindow(vbNullString, "Immediate")
  If parent_hwnd = 0 Then Exit Sub
  ' Set the focus on the debug window
  SetFocusAPI parent_hwnd
  'go to the last line / position on the window
  '(same as pressing CTRL + END on your keyboard
  SendKeys "^{END}", True
  'you can adjust the number of lines
  'printed according to your Immediate
  'window size
  For i = 1 To 100
    Debug.Print ""
  'give the focus back to your program!
  SetForegroundWindow Me.hwnd
End Sub
Then just call clearDebug() anywhere in your code  and that it!

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 140 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.