AutoHotkey Community

It is currently May 27th, 2012, 12:46 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: December 19th, 2009, 1:11 pm 
Offline

Joined: July 3rd, 2008, 2:05 pm
Posts: 10
I've been searching for this a while now, unfortunatly im unable to find a topic that answers my question. If there is a topic that does provide an answer please excuse me i've missed it.

anyway, I've got the following problem im creating a ahk gui script and would like to add auto incremental line numbers in some sort of edit box.
could some body help me create this?

it consists of allot of code but the part that im talking about is the following:
Code:
IniRead, UsrName, %A_AppData%\crt24x7\Config.ini, UserNames, %A_UserName%
Gui, Menu, MyMenuBar
Gui, Add, StatusBar,, (Empty Bar).
SB_SetText("Welcome " . UsrName . ".")
Gui, +Resize
Gui, Add, Edit, R20 W480 vMainEdit WantTab 
Gui, Show,, Content
openFileSet =
return


is there a way? mostly i would like to do it my self and just be pushed in the right direction ;)

thanks in advanced.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2009, 8:54 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
Well, here's my rather hacked attempt... You probably want to avoid the timer, just couldn't seem to be able to use OnMessage() with WM_VSROLL (think it get's sent to the control directly...).



Code:
#NoEnv
#SingleInstance force

loop 100
  text.="Line " a_index "`n"

Gui, +resize
Gui, Margin, 5, 5
Gui, Add, Edit, vlineNo +readOnly r10 -vscroll -hscroll -border w35 disabled
Gui, Add, Edit, vedit xp+35 yp hwndEdit ys r10 w200, % text
Gui, Show,, LineNumbers
GuiControlGet, edit, Pos, edit
LINE_HEIGHT:=editH/10           ; calc. line height
SetTimer, timer, 10
return

timer:
pos:=DllCall("GetScrollPos", "UInt", Edit, "Int", 1)
ifEqual, pos, % posPrev, return                       ; nothing new
posPrev:=pos
drawLineNumbers(pos)                                  ; draw line numbers
return

drawLineNumbers(firstLine="") {
local lines
static prevFirstLine
prevFirstLine:=firstLine!="" ? firstLine : prevFirstLine
firstLine:=prevFirstLine
loop % ceil(EDIT_HEIGHT/LINE_HEIGHT)+1
  lines.=++firstLine . "`n"
GuiControl,, lineNo, % lines
}

GuiSize:
GuiControlGet, lineNo, Pos, lineNo
GuiControl, Move, edit, % "w" a_guiwidth-15-lineNoW "h" a_guiheight-10
GuiControl, Move, lineNo, % "h" a_guiheight-10
EDIT_HEIGHT:=a_guiHeight-10
drawLineNumbers()
return

GuiClose:
exitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2009, 5:22 pm 
Offline

Joined: July 3rd, 2008, 2:05 pm
Posts: 10
Hey, thanks for you reply.
it works great thanks fot this. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2009, 2:17 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Here's an attempt with OnMessage.
Code:
rows = 10 ;Height of Edit control

Gui +LastFound
hGUI := WinExist()
Gui, Add, Edit, r%rows% w40 HWNDhNums Right -VScroll Disabled
Gui, Add, Edit, r%rows% w400 x+0
rowNums(hNums, 0)
OnMessage(0x111,"WM_COMMAND")

Gui, Show
return
GuiClose:
ExitApp

WM_COMMAND(wp,lp) {
 global hGUI
 If (wp>>16 != 0x602) ;EN_VScroll
  return
 hNums := DllCall("GetDlgItem", uint, hGUI, int, (wp & 0xFFFF)-1)
 SendMessage,0xCE,,,,ahk_id %lp% ;EM_GetFirstVisibleLine
 rowNums(hNums, ErrorLevel)
}

rowNums(hCtrl, startNum) {
 global rows
 Loop,% rows
  nums .= startNum+A_Index "`r`n"
 ControlSetText,,%nums%, ahk_id %hCtrl%
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2009, 3:21 am 
Offline

Joined: July 3rd, 2008, 2:05 pm
Posts: 10
thnx Jaco0646

I've took the liberty to edit your script so its resizeble.
it works great even a bit faster then the previous example :)

thanks again.



for those who are interested:

Code:
rows = 999 ;Height of Edit control

Gui +LastFound
Gui +resize
hGUI := WinExist()
Gui, Add, Edit, r10 w40 HWNDhNums Right -VScroll Disabled vLineNumbers
Gui, Add, Edit, r10 w400 h400 x+0 vMainEdit
rowNums(hNums, 0)
OnMessage(0x111,"WM_COMMAND")

Gui, Show
return
GuiClose:
ExitApp

WM_COMMAND(wp,lp) {
 global hGUI
 If (wp>>16 != 0x602) ;EN_VScroll
  return
 hNums := DllCall("GetDlgItem", uint, hGUI, int, (wp & 0xFFFF)-1)
 SendMessage,0xCE,,,,ahk_id %lp% ;EM_GetFirstVisibleLine
 rowNums(hNums, ErrorLevel)
}

rowNums(hCtrl, startNum) {
 global rows
 Loop,% rows
  nums .= startNum+A_Index "`r`n"
 ControlSetText,,%nums%, ahk_id %hCtrl%
}


GuiSize:
NewWidth := A_GuiWidth - 50
NewHeight := A_GuiHeight - 30
NewLineHeight := A_GuiHeight - 30
GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
GuiControl, Move, LineNumbers, H%NewLineHeight%
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2009, 7:58 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
I noticed that EN_VScroll isn't sent when the scroll bar is dragged manually. I suppose OnMessage() needs to monitor some additional message for that. I'll look into it when I get a chance.

For a resizable control, 100 lines is probably sufficent (unless you have a very large screen) and will be faster than 999.
Code:
Gui, +LastFound +Resize
hGUI := WinExist()
Gui, Add, Edit, r10 w40 HWNDhNums Right -VScroll Disabled vLineNumbers
Gui, Add, Edit, r10 w400 h400 x+0 vMainEdit
rowNums(hNums, 0)
OnMessage(0x111,"WM_COMMAND")

Gui, Show
return
GuiClose:
ExitApp

WM_COMMAND(wp,lp) {
 global hGUI
 If (wp>>16 != 0x602) ;EN_VScroll
  return
 hNums := DllCall("GetDlgItem", uint, hGUI, int, (wp & 0xFFFF)-1)
 SendMessage,0xCE,,,,ahk_id %lp% ;EM_GetFirstVisibleLine
 rowNums(hNums, ErrorLevel)
}

rowNums(hCtrl, startNum) {
 Loop,100
  nums .= startNum+A_Index "`r`n"
 ControlSetText,,%nums%, ahk_id %hCtrl%
}

GuiSize:
 NewWidth := A_GuiWidth - 50
 NewHeight := A_GuiHeight - 30
 GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
 GuiControl, Move, LineNumbers, H%NewHeight%
return


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Leef_me, Ohnitiel, XstatyK, Yahoo [Bot] and 20 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