AutoHotkey Community

It is currently May 25th, 2012, 4:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Debugging
PostPosted: September 28th, 2007, 7:09 pm 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
Not sure how OutputDebug is suppose to work. My first guess is there would be a debug screen like the variable and their content screen and the last script lines executed screen etc. (Maybe I am missing something).

Anyway I wrote a very simple script that shows an Edit box at the top right of the screen which debug messages can be sent to through either Print(str) or PrintLn(str) which attaches a line feed character.

Code:
Print(str) {
   static create = true, output
   if create {
      create =
      Gui, 99: -Caption
      Gui, 99:Margin, 0, 0
      Gui, 99:Add, Edit, w500 r5 voutput
      x := A_ScreenWidth - 500
      Gui, 99:Show, NoActivate x%x% y0
   } else
      GuiControlGet, output, 99:
   GuiControl, 99: , output, %output%%str%
   Gui, 99:Show, NoActivate
}
PrintLn(str) {
   Print(str . "`n")
}


Edit: Now shouldn't conflict with other Gui Windows.
Edit2: Added NoActivate.


Last edited by Xander on October 1st, 2007, 6:42 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging
PostPosted: September 28th, 2007, 7:50 pm 
Offline

Joined: June 4th, 2005, 1:30 am
Posts: 113
Location: Stuttgart, Germany
Xander wrote:
Not sure how OutputDebug is suppose to work. My first guess is there would be a debug screen like the variable and their content screen and the last script lines executed screen etc. (Maybe I am missing something)
You are missing an utility like DebugView.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging
PostPosted: September 29th, 2007, 4:40 pm 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
olfen wrote:
You are missing an utility like DebugView.

Yes, indeed I am missing that. I will continue to miss that as all I really want is a simple box where I can print messages, not some full blown application :shock:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 2:47 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
I like to use StdOut, since PSPad, SciTE and other editors capture it (and display it in a tool window.) FileAppend,text,* seems to buffer output (making real-time debugging difficult), so I use DllCall.
Code:
#Persistent
#NoTrayIcon  ; closing the console leaves the tray icon stranded
DllCall("AllocConsole")
SetTimer, tick, 1000
return

tick:
StdOut(A_Now)
return

StdOut( text, term="`n" )
{
    static hStdOut=-1

    if (hStdOut = -1) {
        hStdOut := DllCall("GetStdHandle", "UInt", -11) ; -11=STD_OUTPUT_HANDLE
        if ErrorLevel
            return 0
    }

    ; for convenience:
    text .= term

    ret := DllCall("WriteFile"
        , "UInt", hStdOut       ; hFile
        , "UInt", &text         ; lpBuffer
        , "UInt", StrLen(text)  ; nNumberOfCharsToWrite
        , "UIntP", bytesWritten ; lpNumberOfCharsWritten
        , "UInt", 0)            ; lpOverlapped

    return bytesWritten
}
If run from PSPad, AllocConsole() does nothing, otherwise it shows a standard Windows console (as in command prompt.)

I've never used OutputDebug either...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 3:14 am 
Offline

Joined: August 4th, 2007, 10:58 pm
Posts: 21
lexikos wrote:
I like to use StdOut, since PSPad, SciTE and other editors capture it (and display it in a tool window.) FileAppend,text,* seems to buffer output (making real-time debugging difficult), so I use DllCall.
Code:
#Persistent
#NoTrayIcon  ; closing the console leaves the tray icon stranded
DllCall("AllocConsole")
SetTimer, tick, 1000
return

tick:
StdOut(A_Now)
return

StdOut( text, term="`n" )
{
    static hStdOut=-1

    if (hStdOut = -1) {
        hStdOut := DllCall("GetStdHandle", "UInt", -11) ; -11=STD_OUTPUT_HANDLE
        if ErrorLevel
            return 0
    }

    ; for convenience:
    text .= term

    ret := DllCall("WriteFile"
        , "UInt", hStdOut       ; hFile
        , "UInt", &text         ; lpBuffer
        , "UInt", StrLen(text)  ; nNumberOfCharsToWrite
        , "UIntP", bytesWritten ; lpNumberOfCharsWritten
        , "UInt", 0)            ; lpOverlapped

    return bytesWritten
}
If run from PSPad, AllocConsole() does nothing, otherwise it shows a standard Windows console (as in command prompt.)

I've never used OutputDebug either...


I like your approach to debug output better, it doesn't take up a gui instance and there's not much to do as far as keeping it from stealing focus. My only question, how do I make closing the cmd prompt NOT kill my script?

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 4:39 am 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
lexikos wrote:
I like to use StdOut, since PSPad, SciTE and other editors capture it (and display it in a tool window.) FileAppend,text,* seems to buffer output (making real-time debugging difficult), so I use DllCall.
Looks interesting, I'll have to look into the next time I am writing something in AHK. Preferably I would like to setup eclipse to recieve the output. (free at eclipse.org - don't take as endorsement, this is not your average code writing software!! It is almost exclusively geared towards Java for instance.. and is a resource hog ... real-time compile error checking etc.).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 4:44 am 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
thefunnyman wrote:
there's not much to do as far as keeping it from stealing focus.
It steals focus? I was not aware of that. However I think I've only used it to test the TableLayout script while resizing another GUI so it obviously wouldn't have been able to steal focus there.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 5:47 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Actually, Gui,Show has two no-activate options.
Quote:
NoActivate: Unminimizes or unmaximizes the window, if necessary. The window is also shown without activating it.

NA: Shows the window without activating it.


thefunnyman wrote:
My only question, how do I make closing the cmd prompt NOT kill my script?
The close event can be intercepted by using SetConsoleCtrlHandler(), but it seems while that allows the script to clean up properly, the process is always terminated after some system-defined timeout.

The following script demonstrates two things:
  • Using a mouse hotkey and WM_NCHITTEST to prevent the script from exiting when the user presses the close button.
  • Using SetConsoleCtrlHandler() to clean up properly (i.e. remove the tray icon) when the console is closed some other way (i.e. sysmenu->Close.)

Code:
#NoEnv

DllCall("AllocConsole")

if (hwnd := DllCall("GetConsoleWindow"))
    GroupAdd, MyConsole, ahk_id %hwnd%

DllCall("SetConsoleCtrlHandler", "uint", RegisterCallback("HandlerRoutine"), "int", 1)

return


HandlerRoutine(dwCtrlType)
{
    if dwCtrlType = 2  ; CTRL_CLOSE_EVENT
        ExitApp  ; clean up properly
    return false
}


#IfWinActive ahk_group MyConsole

LButton::Click Down
LButton Up::
    CoordMode, Mouse, Screen
    MouseGetPos, x, y
    SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16  ; WM_NCHITTEST

    if (ErrorLevel = 20) ; close button
        DllCall("FreeConsole")

    Click Up
return

Unfortunately (for me), WM_NCHITTEST doesn't work accurately with Windows Vista's Aero interface: It returns HTMAXBUTTON, HTTOPRIGHT, HTTOP or HTCLOSEBUTTON depending on where in the close button the mouse cursor is.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 6:43 am 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
lexikos wrote:
Actually, Gui,Show has two no-activate
Thanks for posting this.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 10:06 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
You can't really compare DbgView with this - it has filters, history, time, doesn't influence your app anyway (contrary to that, gui num 99 is often used), colors, IS online when your script crashes, can monitor multiple scritps, etc..

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 12:50 pm 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
majkinetor wrote:
You can't really compare DbgView with this - it has filters, history, time, doesn't influence your app anyway
This was not meant to be a robust solution. It's purpose is purely simplicity. If you are experiencing so many problems with code you write, you may want to adopt better practices! I haven't had any need for complex debugging in ages :o


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 1:22 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
This was not meant to be a robust solution. It's purpose is purely simplicity. If you are experiencing so many problems with code you write, you may want to adopt better practices! I haven't had any need for complex debugging in ages

Dude, chillout, smoke something....

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 1:37 pm 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
majkinetor wrote:
Dude, chillout, smoke something....
Sorry if it read as defensive, just wanted to point out that it is not meant to be a replacement for DebugView, just a simple alternative.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2007, 4:08 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
I made me this little function which can be put in the library:

Code:
RunDebugView()
var := "hallo"
outputdebug, Line%A_LineNumber% var=%var%


return

RunDebugView(){
debuggerpath .= "c:\programme\autohotkey\DebugView\Dbgview.exe"
debuggerTitel := "DebugView on \\" . A_ComputerName . " (local)"
IfExist, %debuggerpath%
 ifwinNotexist, %debuggerTitel%
    Run, %debuggerpath%
sleep, 1000
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2007, 10:43 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
maybe its just for simple minded folks like me, but I like the idea...

small suggests like:

why not call it DEBUG() ?

maybe include an optional Debug(text = "", pause = 0) {

option so that if pause // msgbox or pause ??

and... maybe
a global DEBUGon? var...

to if !DebugON // Return... ?



and... anyone know...

is there an alternate to actual `n to designate end of line ???

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, Jaaaaaaaaay, Rajat, XX0 and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group