 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
nicklorion
Joined: 03 Jul 2008 Posts: 10
|
Posted: Sat Dec 19, 2009 12:11 pm Post subject: How to create autoincrement line numbers in gui edit box. |
|
|
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. |
|
| Back to top |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 307
|
Posted: Sat Dec 19, 2009 7:54 pm Post subject: |
|
|
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 |
|
|
| Back to top |
|
 |
nicklorion
Joined: 03 Jul 2008 Posts: 10
|
Posted: Mon Dec 21, 2009 4:22 pm Post subject: |
|
|
Hey, thanks for you reply.
it works great thanks fot this.  |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Wed Dec 23, 2009 1:17 am Post subject: |
|
|
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%
} |
|
|
| Back to top |
|
 |
nicklorion
Joined: 03 Jul 2008 Posts: 10
|
Posted: Wed Dec 23, 2009 2:21 am Post subject: |
|
|
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 |
|
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Thu Dec 24, 2009 6:58 pm Post subject: |
|
|
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 |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|