AutoHotkey Community

It is currently May 25th, 2012, 10:52 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: July 4th, 2007, 3:40 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Hi,
I'm making a wrapper for Scintilla:

Code:
Scintilla_Add(hwnd, x, y, w, h){
   Global
   Local Static ScintillaNum = 0
   ScintillaNum++
   Local GWL_HINSTANCE := -6
;   MsgBox % WS_CHILD WS_VISIBLE WS_HSCROLL WS_VSCROLL WS_TABSTOP WS_CLIPCHILDREN " - "WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_TABSTOP | WS_CLIPCHILDREN
   Local hLib := DllCall("LoadLibrary", "str", "SciLexer.dll", "Cdecl Int")
   Local Sci := DllCall("CreateWindowEx", "int", WS_EX_CLIENTEDGE, "str", "Scintilla" , "str", "WindowWithScintilla" ScintillaNum
                  , "int", WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|WS_TABSTOP|WS_CLIPCHILDREN, "int", x, "int", y
               , "int", w, "int", h, "UInt", hwnd, "UInt", 0, "int", 0, "int" 0, "Cdecl UInt")
;   MsgBox %Sci%
   Return %Sci%
}

Scintilla_SetLexer(Scintilla, Lexer){
   SendMessageUser32(Scintilla, SCI_SETLEXER, Lexer)
}

Scintilla_SetStyle(Scintilla, Style, Fore, Back, Size=0, Bold=0, Italic=0, Underline=0, Font=""){
   SendMessageUser32(Scintilla, SCI_STYLESETFORE, Style, Fore)
   SendMessageUser32(Scintilla, SCI_STYLESETBACK, Style, Back)
   If Size > 1
      SendMessageUser32(Scintilla, SCI_STYLESETSIZE, Style, Size)
   If Font <>
      SendMessageUser32(Scintilla, SCI_STYLESETFONT, Style, Font, "int", "str")
;   pause
   SendMessageUser32(Scintilla, SCI_STYLESETBOLD, Style, Bold)
   SendMessageUser32(Scintilla, SCI_STYLESETITALIC, Style, Italic)
   SendMessageUser32(Scintilla, SCI_STYLESETUNDERLINE, Style, Underline)
}

SendMessageUser32(hwnd, msg, wParam, lParam=0, type1="int", type2="int"){
   Return DllCall("SendMessage", "UInt", hwnd, "int", msg, type1, wParam, type2, lParam)
}

SwitchColor(color){
   Return color ^ (((color & 0xFF) ^ (color / 0x10000)) * 0x10001)
}

There are a problem with function "SendMessageUser32". It seems that the function does not pass the lParam parameter (I tested the function, and when I call the function without the lParam parameter it works, but when I specify a value for lParam, it doesn't works).
Can you help me?

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2007, 5:51 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
I am not sure what the problem is but in Scintilla_SetStyle() you pass messages like SCI_STYLESETFORE or SCI_STYLESETBACK to SendMessageUser32() that are not defined in Scintilla_SetStyle().
So the short story is "Global" is missing in Scintilla_SetStyle().


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2007, 10:28 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Thanks,
I forget to put "Global" (because the variables that "does not exist" are in a include file that I #include) after "Scintilla_SetStyle".
Code:
Scintilla_SetStyle(Scintilla, Style, Fore, Back, Size=0, Font="", Bold=0, Italic=0, Underline=0){ ; I forget to put Font parameter in its place
    Global
    ; code
}

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2007, 3:00 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Now I have a trouble with Bold/Italic/Underline.
This code seems to not work (the variables Bold, Italic and Underline are parameters that are passed to Scintilla_SetStyle function):

Code:
SendMessageUser32(Scintilla, SCI_STYLESETBOLD, Style, Bold)
SendMessageUser32(Scintilla, SCI_STYLESETITALIC, Style, Italic)
SendMessageUser32(Scintilla, SCI_STYLESETUNDERLINE, Style, Underline)


Body of the SendMessageUser32 function:

Code:
SendMessageUser32(hwnd, msg, wParam=0, lParam=0, type1="int", type2="int"){
   Return DllCall("SendMessageA", "UInt", hwnd, "int", msg, type1, wParam, type2, lParam)
}


For your testing, there is the Scintilla.h.ahk file that I #Include (because is too big I've uploaded the file to autohotkey.net):

Scintilla.h.ahk

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2007, 4:18 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
For our testing, we would need more than this file...
How do you know these calls don't work?

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2007, 5:40 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Test this code:
(wrapper code must be in file "Scintilla.ahk")
Code:
#Include Scintilla.ahk
Gui +LastFound
hwnd := WinExist()
sci := Scintilla_Add(hwnd, 0, 0, 640, 480)
Scintilla_SetLexer(sci, SCLEX_AU3)
bits := SendMessageUser32(sci, SCI_GETSTYLEBITSNEEDED)
SendMessageUser32(sci, SCI_SETSTYLEBITS, bits)
SendMessageUser32(sci, SCI_SETZOOM, -1)
SendMessageUser32(sci, SCI_SETENDATLASTLINE, False)
Scintilla_SetStyle(sci, STYLE_DEFAULT, 0x000000, 0xFFFFFF, 10, "Courier New", 0, 0, 0)
Scintilla_SetStyle(sci, SCE_AU3_STRING, 0xCC9999, 0xFFFFFF, 0, "", 1, 0, 0)
SendMessageUser32(sci, SCI_SETCARETLINEBACK, RGB2BGR(0xFFFED8))
SendMessageUser32(sci, SCI_SETCARETLINEVISIBLE, 1)
Gui, Show, w640 h480, Scintilla Demo
Return

GuiClose:
ExitApp
Return


Note: I forget to mention file "WindowConstants.au3.ahk" that is included in file "Scintilla.ahk", and "Scintilla.h.ahk" is included in file "Scintilla.ahk" too.

WindowConstants.au3.ahk

Scintilla.ahk
Code:
#Include Scintilla.h.ahk
#Include WindowConstants.au3.ahk
Scintilla_Add(hwnd, x, y, w, h){
   Global
   Local Static ScintillaNum = 0
   ScintillaNum++
   Local GWL_HINSTANCE := -6
;   MsgBox % WS_CHILD WS_VISIBLE WS_HSCROLL WS_VSCROLL WS_TABSTOP WS_CLIPCHILDREN " - "WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_TABSTOP | WS_CLIPCHILDREN
   Local hLib := DllCall("LoadLibrary", "str", "SciLexer.dll", "Cdecl Int")
   Local Sci := DllCall("CreateWindowEx", "int", WS_EX_CLIENTEDGE, "str", "Scintilla" , "str", "WindowWithScintilla" ScintillaNum
                  , "int", WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL, "int", x, "int", y
               , "int", w, "int", h, "UInt", hwnd, "UInt", 0, "int", 0, "int" 0, "Cdecl UInt")
;   MsgBox %Sci%
   Return %Sci%
}

Scintilla_SetLexer(Scintilla, Lexer){
   Global
   SendMessageUser32(Scintilla, SCI_SETLEXER, Lexer)
}

Scintilla_SetStyle(Scintilla, Style, Fore, Back, Size=0, Font="", Bold=0, Italic=0, Underline=0){
   Global
   SendMessageUser32(Scintilla, SCI_STYLESETFORE, Style, Fore)
   SendMessageUser32(Scintilla, SCI_STYLESETBACK, Style, Back)
   If Size > 1
      SendMessageUser32(Scintilla, SCI_STYLESETSIZE, Style, Size)
   If Font <>
      SendMessageUser32(Scintilla, SCI_STYLESETFONT, Style, Font, "int", "str")
   SendMessageUser32(Scintilla, SCI_STYLESETBOLD, Style, Bold)
   SendMessageUser32(Scintilla, SCI_STYLESETITALIC, Style, Italic)
   SendMessageUser32(Scintilla, SCI_STYLESETUNDERLINE, Style, Underline)
}

SendMessageUser32(hwnd, msg, wParam=0, lParam=0, type1="int", type2="int"){
;   Global SCI_STYLESETBOLD
;   If msg = %SCI_STYLESETBOLD%
;      Pause
   Return DllCall("SendMessageA", "UInt", hwnd, "int", msg, type1, wParam, type2, lParam)
}

RGB2BGR(color){
   Return color ^ (((color & 0xFF) ^ (color / 0x10000)) * 0x10001)
}

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 11th, 2007, 11:42 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Thanks for the sample. It is a very interesting project, much more advanced than what I started to make (and left inactive for quite some time now).

You need to apply the default style to all others styles, or to specify all parameters to each style. The first option makes sense anyway:
Code:
Scintilla_SetStyle(sci, STYLE_DEFAULT, 0x000000, 0xFFFFFF, 18, "Times New Roman")
SendMessageUser32(sci, SCI_STYLECLEARALL) ; Added line!
Scintilla_SetStyle(sci, SCE_AU3_STRING, 0xCC9999, 0xFFFFFF, 0, "", 0, 1)

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 11th, 2007, 2:33 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Thanks! Problem with styles are solved. Now I get a problem with keywords:

Code:
Scintilla_SetKeywords(Scintilla, KeywordNumber, Keywords)  ; added function
{
   SendMessageUser32(Scintilla, SCI_SETKEYWORDS, KeywordNumber, Keywords, "int", "str")
}


Try to put this code on the example:
Code:
Scintilla_SetStyle(sci, SCE_AU3_FUNCTION, 0x0000AA, 0xFFFFFF, Default, Default, 1, 0, 0)
Scintilla_SetKeywords(sci, 1, "msgbox inputbox test")


When I type "msgbox" (or "MsgBox", "InputBox" or "Test") I don't get any syntax highlighting for this keywords. Now there is a problem with Scintilla_SetKeywords function.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 11th, 2007, 3:54 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Once again, forgetting Global keyword in the function... :D
Took me a while to see that...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject: You are awesome
PostPosted: March 25th, 2008, 2:02 pm 
Offline

Joined: March 22nd, 2008, 4:03 am
Posts: 57
Location: At my computer
You just did what I was trying to do thanks :-D

_________________
My Blogs | PChat the free XChat fork for Windows and *nix
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2011, 9:59 am 
Offline

Joined: April 22nd, 2009, 6:04 am
Posts: 29
flincs, i tried to open the files below but they don't exist anymore
please help me out if you still have these files :?:

#Include Scintilla.h.ahk
#Include WindowConstants.au3.ahk


Last edited by wiseley on January 13th, 2011, 1:40 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2011, 10:18 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
If you're trying to use a Scintilla control from AutoHotkey, you might be interested in my Scintilla.iface parser and the script which it generates.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2011, 1:50 pm 
Offline

Joined: April 22nd, 2009, 6:04 am
Posts: 29
Thanks Lexikos
your script does exactly what i wanted to do. :D


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: mrhobbeys, toddintr and 74 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