 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sat May 26, 2007 3:25 pm Post subject: |
|
|
It was something simple I was missing with loading a RichEdit 2.0 control . |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sat May 26, 2007 5:39 pm Post subject: |
|
|
Updated to version 0.02 Beta.
- fixed hInstance usage [thanks PhiLho]
- fixed RICHEDIT was hard coded [thanks PhiLho]
- added FreeDlls option (_action param) to cGUI() to free all dlls loaded by the cGUI() function
- updated demo to load RichEdit v2.0
- modifed global variables used
- added win95_98.ahk demo to the zip file available for download
**Note to Win95/98 users: If the control does not display when running the demo script then change RichEdit20A to RICHEDIT in the cGUI function in the demo script or download and install riched20.dll |
|
| Back to top |
|
 |
Daniel2 Guest
|
Posted: Sat May 26, 2007 8:51 pm Post subject: |
|
|
| Quote: | | As there are a few structs that are commonly used when modifying RichEdit controls, I'll likely add a function to make using a few of the common ones a bit easier | Yeah-- the two that I mentioned alone would immiediately unlock a number of them. I look forward to seeing your examples (i'll learn quite a bit off of them!! ) |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sun May 27, 2007 10:42 am Post subject: |
|
|
Updated to version 0.03 Beta. Added: | Quote: | *****************************************
EXGETSEL - retrieves the starting and ending character positions of the selection
_action = EXGETSEL
*****************************************
EXSETSEL - set the current selection
_action = EXSETSEL
opt1 = start position
opt2 = end position
*****************************************
GETSELTEXT - get the current text that is selected in the control
_action = GETSELTEXT
*****************************************
GETTEXTLENGTH - get the number of characters in the control
_action = GETTEXTLENGTH
opt1 = (1 - unicode, 0 - ANSI) Default ANSI
*****************************************
GETTEXT - get the text in the control
_action = GETTEXT
opt1 = (1 - unicode, 0 - ANSI) Default ANSI
*****************************************
BackColor - change the background colour of the RichEdit control
_action = BackColor
opt1 = RRGGBB colour
*****************************************
SETSCROLLPOS - scroll to a specific position in the control
_action = SETSCROLLPOS
opt1 = x position
opt2 = y position
*****************************************
GETSCROLLPOS - get the current scroll position in the control
_action = SETSCROLLPOS
*****************************************
AutoURLDetect - automatic detection of URLs
_action = AutoURLDetect
opt1 = (1 = on, 0 = off)
*****************************************
|
... plus a few other updates. Please see the first post for details, screenshots, downloads, etc... . |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Sun May 27, 2007 11:45 am Post subject: |
|
|
This is the function you might want to use for font change. I created it for the HiEdit. Only the last line is related to HiEdit, so you can use it for richedit, perhaps even unchanged.
| Code: | HE_SetFont(hEdit, pFont="") {
local height, weight, italic, underline, strikeout , nCharSet
local hFont
static WM_SETFONT := 0x30
;parse font
italic := InStr(pFont, "italic") ? 1 : 0
underline := InStr(pFont, "underline") ? 1 : 0
strikeout := InStr(pFont, "strikeout") ? 1 : 0
weight := InStr(pFont, "bold") ? 700 : 400
;height
RegExMatch(pFont, "(?<=[S|s])(\d{1,2})(?=[ ,])", height)
if (height = "")
height := 10
RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels
height := -DllCall("MulDiv", "int", Height, "int", LogPixels, "int", 72)
;face
RegExMatch(pFont, "(?<=,).+", fontFace)
if (fontFace != "")
fontFace := RegExReplace( fontFace, "(^\s*)|(\s*$)") ;trim
else fontFace := "MS Sans Serif"
;create font
hFont := DllCall("CreateFont", "int", height, "int", 0, "int", 0, "int", 0
,"int", weight, "Uint", italic, "Uint", underline
,"uint", strikeOut, "Uint", nCharSet, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "str", fontFace)
SendMessage,WM_SETFONT,hFont,TRUE,,ahk_id %hEdit%
return ErrorLevel
}
|
THe usage:
| Code: | fStyle := "s12 bold" , fFace := "Courier New"
HE_SetFont( hEdit, fStyle "," fFace) |
_________________
 |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sun May 27, 2007 6:10 pm Post subject: |
|
|
| majkinetor wrote: | | This is the function you might want to use for font change. I created it for the HiEdit. Only the last line is related to HiEdit, so you can use it for richedit, perhaps even unchanged. | Thanks for the code contribution . Out of curiousity, have you tried this instead? | Code: | | SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, &CHARFORMATstruct) |
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sun May 27, 2007 8:21 pm Post subject: |
|
|
Well, I came up with a few functions for working with a few specific structs but I decided against adding them due to the overhead involved in trying to avoid creating global variables. I may have a closer look sometime later (or possibly sooner if anyone has any code suggestions/submissions).
After wrestling with EM_GETCHARFORMAT and the CHARRANGE struct for a little while, I managed to get a Bold command working though so I'll try and post an update that includes a few basic text formatting features a bit later. Here's the current code for the Bold _action in case anyone wants to experiment, play, provide feedback, etc... | Code: | /*
*****************************************************************************************
Bold - make the current selection Bold or add Bold text from the current location
- this will act as a toggle if appplied to the same selection again
_action = Bold
*****************************************************************************************
*/
Else If _action = Bold
{
VarSetCapacity(_tmp1, 60, 0) ; CHARFORMAT struct
InsertInteger_cGUI(60, _tmp1, 0) ; cbSize
InsertInteger_cGUI(1, _tmp1, 4) ; dwMask
InsertInteger_cGUI(1, _tmp1, 8) ; dwEffects
; ** SendMessage(hwnd, EM_GETCHARFORMAT, SCF_SELECTION, &CHARFORMATstruct)
DllCall("SendMessage", "UInt", _ctrlID, "UInt", 0x43A, "UInt", "1", "UInt", &_tmp1)
; ** Check if Bold is applied to the current selection
VarSetCapacity(_tmp1, -1)
_tmp2 := !((ExtractInteger_cGUI(_tmp1, 4) & 1) & (ExtractInteger_cGUI(_tmp1, 8) & 1))
; ** SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, &CHARFORMATstruct) ; reverse the current effect
VarSetCapacity(_tmp1, 60, Chr(0)) ; CHARFORMAT struct
InsertInteger_cGUI(60, _tmp1, 0) ; cbSize
InsertInteger_cGUI(1, _tmp1, 4) ; dwMask
InsertInteger_cGUI(_tmp2, _tmp1, 8) ; dwEffects
Return DllCall("SendMessage", "UInt", _ctrlID, "UInt", 0x444, "UInt", "1", "UInt", &_tmp1)
} |
|
|
| Back to top |
|
 |
Daniel2 Guest
|
Posted: Sun May 27, 2007 8:53 pm Post subject: |
|
|
Cool!
| Quote: | | Well, I came up with a few functions for working with a few specific structs but I decided against adding them due to the overhead involved in trying to avoid creating global variables | Wouldn't one of the advantages of having cGUI_RICHEDIT handle RE wrapping be that it sort of encapsilates everything. The results of your struct functions should only have to be availiable to it..? Right?
I still haven't digested everything yet.. but I appreciate all your work so far!!  |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Mon May 28, 2007 7:30 am Post subject: |
|
|
| Quote: | | Out of curiousity, have you tried this instead? |
No. Its richedit specific. Thats why I said you can reuse the function above. everything is calculated you just have to fill up the structure. _________________
 |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Mon May 28, 2007 8:09 am Post subject: |
|
|
Since RichEdit has built-in methods for playing with fonts I decided to use them instead of using CreateFont for now. The CreateFont code will likely come in handy though .
It's slowly starting to look and behave a bit more like a RichEdit control (lots left to go though)... Updated to version 0.04 Beta- added: FontStyle _action to set/toggle Bold, Italic, UnderLine, Strikethrough for the current selection or current position (optional custom dwMask and dwEffects settings available also)
- added: FontColor _action to change the colour to selected text or change the colour at the current location (RRGGBB value or by name - same names/values as Object Colors in the AutoHotkey documentation)
- updated: BackColor _action to support colour names also
- updated: feature_demo.ahk script to test some of the newer features that have been added
Coming soon... change font, font size, GetTextRange... |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Mon May 28, 2007 8:40 am Post subject: |
|
|
| Quote: | | The CreateFont code will likely come in handy though . |
Yeah, I should definitely put this as separate func for ppl that need explicit font handles.
Thx for the update. This is approaching to real RichEdit.
One question (out of curiosity )
I guess cGUI is name for something bigger you want to have.
Is there any chance you provide more familiar include, something more appealing like, RichEdit_Create, RichEdit_SetSelectionEffect, etc...
Or even better, wait until we devise some standardisation of syntax for 3th party controls wrappers, but some things are already in most of the control wrappers like XXX_Create() to add control to the gui. _________________
 |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Mon May 28, 2007 5:49 pm Post subject: |
|
|
Great work! A feature that I would find very useful is custom word-breaks and delimiter chars. This can be done with EditWordBreakProc (requires callback). Overloads are confusing, I think you should switch to Chris' style of function names, i.e. RE_Add(), RE_SetText(), RE_LoadFile(), RE_Destroy() etc. _________________ GitHub • Scripts • IronAHK • Contact by email not private message. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Tue May 29, 2007 1:42 am Post subject: |
|
|
| Titan wrote: | | Great work! A feature that I would find very useful is custom word-breaks and delimiter chars. This can be done with EditWordBreakProc (requires callback). | Thanks . Custom word-breaks and delimiter chars are on the list but it might take me a little while longer to get to them. Thanks for the link. Here's a related link specific to the RichEdit control.
| Titan wrote: | | Overloads are confusing, I think you should switch to Chris' style of function names, i.e. RE_Add(), RE_SetText(), RE_LoadFile(), RE_Destroy() etc. | I'll be making a few structural changes with the next version but I'm not currently planning to switch to using separate functions for commands unless there's a really good reason.
I am planning to split things up a bit and add separate help documention though which will likely make it easier to locate commands, descriptions on usage, param values expected, syntax, examples, etc... |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Tue May 29, 2007 3:05 am Post subject: |
|
|
| majkinetor wrote: | One question (out of curiosity )
I guess cGUI is name for something bigger you want to have.
Is there any chance you provide more familiar include, something more appealing like, RichEdit_Create, RichEdit_SetSelectionEffect, etc... | Yes. I was thinking the same thing. I'll probably split the #Include file into 2 separate files and rename the cGUI_RICHEDIT() function to cRichEdit() instead.
| majkinetor wrote: | | Or even better, wait until we devise some standardisation of syntax for 3th party controls wrappers, but some things are already in most of the control wrappers like XXX_Create() to add control to the gui. | That was/is the thought behind cGUI(). I'm planning to use it for other controls also. Although it needs a few additional features, it can currently be used to add other controls to a script. After a bit more testing with it I'll likely move it to another topic... |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sun Jun 03, 2007 12:58 pm Post subject: |
|
|
Updated to version 0.05 beta
- modified: split the include files into cGUI.ahk and cRichEdit.ahk since cGUI.ahk might be used for other controls in the future.
- renamed: cGUI_RICHEDIT function to c_RichEdit() instead (easier to remember and less to type)
- modified: feature_demo.ahk to use a ListView to list/test commands instead of the buttons that were used previously. This method seems to allow more flexibility when adding/modifying/testing new options
- added: FontName _action to specify a font to use by name
- added: GetFontSize _action to get the font size of the current selection
- added: SetFontSize _action to set the font size of the current selection
|
|
| 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
|