AutoHotkey Community

It is currently May 25th, 2012, 6:53 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 106 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 8  Next
Author Message
 Post subject:
PostPosted: May 26th, 2007, 4:25 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
It was something simple I was missing with loading a RichEdit 2.0 control :oops: .


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2007, 6:39 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2007, 9:51 pm 
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!! :))


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2007, 11:42 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
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... :) .


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2007, 12:45 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2007, 7:10 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2007, 9:21 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
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)
  }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2007, 9:53 pm 
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? :?: :roll:
I still haven't digested everything yet.. but I appreciate all your work so far!! :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2007, 8:30 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2007, 9:09 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2007, 9:40 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2007, 6:49 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2007, 2:42 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
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'sa 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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2007, 4:05 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2007, 1:58 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2540
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 106 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 8  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], Leef_me, tkmmkt and 15 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