Advertisement
5_2007-2008 Debugging and Error Handling #182510

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.

AI

KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Quellcode
original-source
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 ""
  Next
  
  'give the focus back to your program!
  SetForegroundWindow Me.hwnd
End Sub
Then just call clearDebug() anywhere in your code  and that it!
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine