 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
fincs
Joined: 05 May 2007 Posts: 82 Location: Seville, Spain
|
Posted: Wed Jul 04, 2007 3:40 pm Post subject: Help with Scintilla wrapper |
|
|
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? _________________ Sorry my poor English
Fincs
MsgBox % RegExReplace("Fernando Incs.", "^(\w).*\s+I(\w{3})\w*\.$", "$1i$2") |
|
| Back to top |
|
 |
foom
Joined: 19 Apr 2006 Posts: 386
|
Posted: Wed Jul 04, 2007 5:51 pm Post subject: |
|
|
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(). |
|
| Back to top |
|
 |
fincs
Joined: 05 May 2007 Posts: 82 Location: Seville, Spain
|
Posted: Wed Jul 04, 2007 10:28 pm Post subject: |
|
|
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
} |
_________________ Sorry my poor English
Fincs
MsgBox % RegExReplace("Fernando Incs.", "^(\w).*\s+I(\w{3})\w*\.$", "$1i$2") |
|
| Back to top |
|
 |
fincs
Joined: 05 May 2007 Posts: 82 Location: Seville, Spain
|
Posted: Tue Jul 10, 2007 3:00 pm Post subject: |
|
|
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 _________________ Sorry my poor English
Fincs
MsgBox % RegExReplace("Fernando Incs.", "^(\w).*\s+I(\w{3})\w*\.$", "$1i$2") |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Jul 10, 2007 4:18 pm Post subject: |
|
|
For our testing, we would need more than this file...
How do you know these calls don't work? _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
fincs
Joined: 05 May 2007 Posts: 82 Location: Seville, Spain
|
Posted: Tue Jul 10, 2007 5:40 pm Post subject: |
|
|
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)
} |
_________________ Sorry my poor English
Fincs
MsgBox % RegExReplace("Fernando Incs.", "^(\w).*\s+I(\w{3})\w*\.$", "$1i$2") |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Wed Jul 11, 2007 11:42 am Post subject: |
|
|
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)
|
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
fincs
Joined: 05 May 2007 Posts: 82 Location: Seville, Spain
|
Posted: Wed Jul 11, 2007 2:33 pm Post subject: |
|
|
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. _________________ Sorry my poor English
Fincs
MsgBox % RegExReplace("Fernando Incs.", "^(\w).*\s+I(\w{3})\w*\.$", "$1i$2") |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Wed Jul 11, 2007 3:54 pm Post subject: |
|
|
Once again, forgetting Global keyword in the function...
Took me a while to see that... _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
thibeaz
Joined: 22 Mar 2008 Posts: 4 Location: At my computer
|
Posted: Tue Mar 25, 2008 2:02 pm Post subject: You are awesome |
|
|
You just did what I was trying to do thanks  _________________ My Blogs | My Blogs Forums |
|
| 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
|