AutoHotkey Community

It is currently May 24th, 2012, 2:14 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Simple loger function
PostPosted: January 5th, 2007, 1:54 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
This is simple Log function that uses simple Edit control. Bellow is an example of usage. I use it all the time, so I thought someone might need it for quick text loging too....

SYNTAX: Log( <text> [, addnewline = true ] )

- If text is single letter that letter will be used to draw a line, like, "-", "=" ...
- To continue line next time specify false as second argument
- Use `n as new line
- The function operates on edit with handle hLog witch should be globaly available


Code:
Gui, Font, s8, Courier New
Gui, Add, Edit, w400 r14 HwndhLog -Wrap ReadOnly Disabled

Gui, Add, Button, gOnClick, Clck to log something
Gui, Show

return

OnClick:
   Log("`nStart of loging"), Log("_"), Log("")
   Sleep 2000
   Log("Something really cool happened now")
   SLeep 2000
   Log("Kewl calculation is going on now ...", false)
   Sleep 2000
   Log(" OK")
   Log("`n`nAnd finally, its over !"), Log("-")

   Control, Enable,,, ahk_id %hLog%
return


Log(s, newline = true){   
   local c

   StringReplace s, s, `n, % chr(13)chr(10), A
   if StrLen(s) = 1
   {
      c := chr(*(&s))
      loop, 119
         s .= c
   }

   if (newline)
      s .= chr(13)chr(10)

   SendMessage, 0xC2, false, &s,, ahk_id %hLog%
}


:D

_________________
Image


Last edited by majkinetor on January 5th, 2007, 2:54 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2007, 2:09 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
Why do you use chr(13)chr(10) when `r`n works?
You probably already know that Control commands work with control handles so SendMessage isn't the only way to append text.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2007, 2:49 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Well, I tried just `n and it didn't work and this was the first thing...

Quote:
You probably already know that Control commands work with control handles so SendMessage isn't the only way to append text.

Is it really important witch way is it ? I just know API much better then AHK... The problem is that some of those things I need can't be done in AHK so at one point I did stop searching the AHK docs if I know the way to do it via API. Now I see that you probably ment on doc part:

EditPaste, String: Pastes String at the caret/insert position in an Edit control.

The problem with edit control and loging is, if it is enabled, user can change the carret position in witch case new text will be appended from that point. I tried various things before appnding, like sending CTRL END to edit to go all the way down, using API to select end of the input etc... but for some reason I could still be able to change curret position. So in my scripts, I usualy disable log edit while working and then enable it again when things are done.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], maraskan_user, RaptorX 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