Skip to content

Instantly share code, notes, and snippets.

@maestrith
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maestrith/3c315f5f8a132e2c4d00 to your computer and use it in GitHub Desktop.
Save maestrith/3c315f5f8a132e2c4d00 to your computer and use it in GitHub Desktop.
Posted using AHK Studio
#SingleInstance,Force
if !FileExist("scilexer.dll")
URLDownloadToFile,http://files.maestrith.com/AHK-Studio/SciLexer.dll,SciLexer.dll
Version=0.001.0
sc:=new s(1,{pos:"w200 h200"})
Gui,+hwndhwnd
Gui,Add,Text,x+5 w200 h200 hwndtext,Type things in the left box
Gui,Show,,Scintilla Testing
return
GuiEscape:
GuiClose:
ExitApp
return
class s{
static ctrl:=[],main:=[],temp:=[]
__New(window,info){
static int,count:=1
if !init
DllCall("LoadLibrary","str","scilexer.dll"),init:=1
win:=window?window:1,pos:=info.pos?info.pos:"x0 y0"
if info.hide
pos.=" Hide"
notify:=info.label?info.label:"notify"
Gui,%win%:Add,custom,classScintilla hwndsc w500 h400 %pos% +1387331584 g%notify%
this.sc:=sc,t:=[],s.ctrl[sc]:=this
for a,b in {fn:2184,ptr:2185}
this[a]:=DllCall("SendMessageA","UInt",sc,"int",b,int,0,int,0)
v.focus:=sc,this.2660(1)
if info.main
s.main.Insert(this)
if info.temp
s.temp.Insert(this)
return this
}
clear(){
for a,b in s.temp
DllCall("DestroyWindow",uptr,b.sc)
s.temp:=[]
}
delete(x*){
if(s.main.MaxIndex()=1){
MsgBox,Can not delete the last control
return
}
this:=x.1
for a,b in s.main
if (b.sc=this.sc)
s.main.remove(a)
DllCall("DestroyWindow",uptr,this.sc)
}
__Get(x*){
return DllCall(this.fn,"Ptr",this.ptr,"UInt",x.1,int,0,int,0,"Cdecl")
}
__Call(code,lparam=0,wparam=0,extra=""){
if(code="getword"){
cpos:=lparam?lparam:sc.2008
return sc.textrange(sc.2266(cpos,1),sc.2267(cpos,1))
}
if(code="getseltext"){
VarSetCapacity(text,this.2161),length:=this.2161(0,&text)
return StrGet(&text,length,"UTF-8")
}
if(code="textrange"){
cap:=VarSetCapacity(text,abs(lparam-wparam)),VarSetCapacity(textrange,12,0),NumPut(lparam,textrange,0),NumPut(wparam,textrange,4),NumPut(&text,textrange,8)
this.2162(0,&textrange)
return strget(&text,cap,"UTF-8")
}
if(code="getline"){
length:=this.2350(lparam),cap:=VarSetCapacity(text,length,0),this.2153(lparam,&text)
return StrGet(&text,length,"UTF-8")
}
if(code="gettext"){
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=strget(&text,vv,"UTF-8")
return t
}
if(code="getuni"){
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=StrGet(&text,vv,"UTF-8")
return t
}
wp:=(wparam+0)!=""?"Int":"AStr"
if wparam.1
wp:="AStr"
if wparam=0
wp:="int"
if IsObject(wparam)
wp:="AStr",wparam:=wparam.1
lp:=(lparam+0)!=""?"Int":"AStr"
info:=DllCall(this.fn,"Ptr",this.ptr,"UInt",code,lp,lparam,wp,wparam,"Cdecl")
return info
}
show(){
GuiControl,+Show,% this.sc
}
}
notify:
fn:=[],info:=A_EventInfo
for a,b in {0:"Obj",2:"Code",3:"position",4:"ch",5:"mod",6:"modType",7:"text",8:"length",9:"linesadded",10:"msg",11:"wparam",12:"lparam",13:"line",14:"fold",17:"listType",22:"updated"}
fn[b]:=NumGet(Info+(A_PtrSize*a))
if(fn.code=2001){
ControlSetText,Static1,% sc.gettext(),ahk_id%hwnd%
}
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment