Jump to content

Search the Community

Showing results for tags 'richedit rich text tool'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 2 results

  1. To test as intended: see read me! file in zip This program is still under development, but feel free to make this code better with suggestions and better code There is a (closed) ticket for a bug in _GUICtrlRichEdit_StreamToFile so the script uses a workaround: https://www.autoitscript.com/trac/autoit/ticket/4038#ticket Wanna take a look at the code? Here you go: #cs name: MiniMark function: a minimalistic editor for custom rtf files version: 4 made by: TheAutomator project: https://www.autoitscript.com/forum/topic/212763-minimark-a-minimalistic-rtf-editor todo: • make user level install possible (requested by argumentum) • allow dropping files to gui • add shortcut to incert and change checkmarks • consider sort lines, remove duplicate lines, remove whitespace button • add file changed indicator • add right click menu on edit • check if programfiles exist when opened • look into embedding images and sounds into compiled exe • make variable names better (autoit rules) bugs in AutoIT rich edit functions: https://www.autoitscript.com/trac/autoit/ticket/4038#ticket https://www.autoitscript.com/trac/autoit/ticket/4040#ticket should be fixed in next version! remarks: to test MiniMark without compilation: • copy "MiniMark.au3" in the "MiniMark" folder and run it (title font will be the default one if you don't install the font) to install and test MiniMark as intended: • compile minimark to exe (with options, the exe will apear in the "MiniMark" folder) • compile setup to exe (with options) • use the setup to install MiniMark • restart computer (if things don't update directly) • rightclick to create a new mnm file • double click it and tadaaaah! hystory: version 1 + added some changes inspired by Werty + code revised + added functionality like opening files with a window, noticed by Argumentum + added sounds version 2 + scrolling is now possible thanks to Pixelsearch + scroll code was revised by Nine + changed some code to prevent a sound to be played twice + added "return $gui_rundefmsg" to "func wm_command" version 3 + made an installer/uninstaller (needs install path choice) + removed unnecessary guictrlcreatedummy code + undo buffer is set to empty when file loaded + added search function with custom gui (work in progress) + added scroll bar (that is buggy AF) version 4 + code revised again + made find and replace work better + better custom scrollbar (based on cursor position in edit) + added "save as" shortcut + added option to silence sounds + added option to save zoom amount (bug -> see ticket) + new search gui + added settings gui + added ini file to save settings + added custom popups in same style as MiniMark + added about button with link to forum + added per-monitor v2 dpi awareness (requires windows 10 creators update or later) + added better way to create controls on the fly (not as many images needed) + added checkmarks + added upper and lower case hotkeys + added incert date and time hotkey #ce #Region au3 #autoit3wrapper_icon=setup\icon.ico #autoit3wrapper_outfile_x64=MiniMark\MiniMark.exe #autoit3wrapper_usex64=y #NoTrayIcon #include <guirichedit.au3> #include <guiconstants.au3> #include <winapisyswin.au3> #include <array.au3> #include <date.au3> #EndRegion au3 #Region MiniMark constants ; colors Const $color_text_white = 0x00ffffff Const $color_text_gray = 0x00c0c0c0 Const $color_element_gray = 0x606060 Const $color_control_gray = 0x404040 Const $color_border_gray = 0x202020 Const $color_text_red = 0x006600ff Const $color_text_green = 0x0000ff66 Const $color_text_blue = 0x00ff6600 Const $color_transparent_background = 0xff00ff ; font names Const $font_handel_gothic_bt = 'handelgothic bt' Const $font_lucida_console = 'lucida console' ; sound effects Const $sound_start = @ScriptDir & '\sounds\start.wav' Const $sound_click = @ScriptDir & '\sounds\click.wav' Const $sound_alert = @ScriptDir & '\sounds\alert.wav' Const $sound_stop = @ScriptDir & '\sounds\stop.wav' ; user interface images Const $image_alert = @ScriptDir & '\images\alert.bmp' Const $image_button = @ScriptDir & '\images\button.bmp' Const $image_MiniMark = @ScriptDir & '\images\MiniMark.bmp' Const $image_scroll = @ScriptDir & '\images\scroll.bmp' Const $image_scroll_down = @ScriptDir & '\images\scroll_down.bmp' Const $image_scroll_up = @ScriptDir & '\images\scroll_up.bmp' Const $image_search = @ScriptDir & '\images\search.bmp' Const $image_settings = @ScriptDir & '\images\settings.bmp' Const $image_size_down = @ScriptDir & '\images\size_down.bmp' Const $image_size_up = @ScriptDir & '\images\size_up.bmp' Const $image_tick_on = @ScriptDir & '\images\tick_on.bmp' Const $image_tick_off = @ScriptDir & '\images\tick_off.bmp' ; files Const $file_intro = @ScriptDir & '\data\MiniMark.mnm' Const $file_settings = @ScriptDir & '\data\settings.ini' #EndRegion MiniMark constants #Region custom gui create functions ; create titles. Func title_create($title, $w) Local $title_handle = GUICtrlCreateLabel($title, 5, 5, $w, 20, BitOR($ss_centerimage, $ss_center), $gui_ws_ex_parentdrag) ; use label to drag form GUICtrlSetFont(Default, 12, 400, 0, $font_handel_gothic_bt) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $gui_bkcolor_transparent) Return $title_handle EndFunc ;==>title_create ; create buttons. Func button_create($text, $tip, $sub, $x, $y) Local $button_handle = GUICtrlCreatePic($image_button, $x, $y, 70, 20) GUICtrlSetTip(Default, $tip, $sub) Local $button_label = GUICtrlCreateLabel($text, $x, $y, 70, 20, BitOR($ss_centerimage, $ss_center)) GUICtrlSetFont(Default, 9, 400, 0, $font_handel_gothic_bt) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $gui_bkcolor_transparent) Return $button_handle EndFunc ;==>button_create ; create checkboxes. Func checkbox_create($text, $tip, $sub, $x, $y, $state = 0) Local $checkbox_handle = GUICtrlCreatePic($state ? $image_tick_on : $image_tick_off, $x, $y, 70, 20) GUICtrlSetTip(Default, $tip, $sub) Local $checkbox_label = GUICtrlCreateLabel($text, $x, $y, 50, 20, BitOR($ss_centerimage, $ss_center)) GUICtrlSetFont(Default, 9, 400, 0, $font_handel_gothic_bt) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $gui_bkcolor_transparent) Return $checkbox_handle EndFunc ;==>checkbox_create ; create inputs (+5 on the left, -5 on the right; so we don't overlap the corners). Func input_create($x, $y, $tip) Local $input_handle = GUICtrlCreateInput('', $x, $y, 210, 20, $es_autohscroll, 0) GUICtrlSetTip(Default, $tip) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $color_control_gray) GUICtrlSetFont(Default, 12, 400, 0, $font_handel_gothic_bt) Return $input_handle EndFunc ;==>input_create #EndRegion custom gui create functions #Region checkbox messages Func checkbox_toggle($checkbox_handle, ByRef $checkbox_state) play_sound($sound_click) $checkbox_state = $checkbox_state ? 0 : 1 GUICtrlSetImage($checkbox_handle, $checkbox_state ? $image_tick_on : $image_tick_off) EndFunc ;==>checkbox_toggle #EndRegion checkbox messages #Region sound effects $checkbox_sound_state = Int(IniRead($file_settings, 'settings', 'sound', 1)) ; read from ini Func play_sound($name, $wait = 0) If $checkbox_sound_state Then SoundPlay($name, $wait) EndFunc ;==>play_sound #EndRegion sound effects #Region custom msgbox ; alert constants Const $alert_ok = 0 Const $alert_link_close = 1 Const $alert_yes_no_cancel = 2 ; a custom messagebox, used for warnings and notifications Func alert($title = 'Alert', $text = '', $type = $alert_ok) Local $alert_form = GUICreate('Alert', 230, 120, Default, Default, $ws_popup, BitOR($ws_ex_layered, $ws_ex_topmost)) GUISetBkColor($color_transparent_background) Local $alert_background = GUICtrlCreatePic($image_alert, 0, 0, 230, 120) GUICtrlSetState(Default, $gui_disable) Local $alert_title = title_create($title, 220) Local $alert_text = GUICtrlCreateLabel($text, 10, 35, 210, 50, $ss_center) ;, bitor($ss_centerimage, $ss_center, $bs_multiline)) GUICtrlSetFont(Default, 8, 400, 0, $font_handel_gothic_bt) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $color_control_gray) Local $alert_button_1 = -14, $alert_button_2 = -14, $alert_button_3 = -14 Switch $type Case $alert_ok $alert_button_2 = button_create('Ok', '', Default, 80, 95) Case $alert_link_close $alert_button_1 = button_create('Link', 'Go to the AutoIt forum to check for MiniMark updates.', Default, 5, 95) $alert_button_3 = button_create('Close', '', Default, 155, 95) Case $alert_yes_no_cancel $alert_button_1 = button_create('Yes', '', Default, 5, 95) $alert_button_2 = button_create('No', '', Default, 80, 95) $alert_button_3 = button_create('Cancel', '', Default, 155, 95) EndSwitch _WinAPI_SetLayeredWindowAttributes($alert_form, $color_transparent_background) ; set the transparant gui color GUISetState(@SW_SHOW) play_sound($sound_alert) Local $choice ; to return what button was clicked While 1 Switch GUIGetMsg() Case $gui_event_close $choice = 0 ExitLoop Case $alert_button_1 $choice = 1 ExitLoop Case $alert_button_2 $choice = 2 ExitLoop Case $alert_button_3 $choice = 3 ExitLoop EndSwitch WEnd play_sound($sound_click) GUIDelete($alert_form) Return $choice EndFunc ;==>alert #EndRegion custom msgbox #Region dll calls ; set per-monitor v2 dpi awareness (requires windows 10 creators update or later) dllcall("user32.dll", "bool", "setprocessdpiawarenesscontext", "ptr", -4) #EndRegion dll calls #Region parameters Func get_filename() Local $path_split = StringSplit($cmdline[1], '\', 3) Return StringTrimRight($path_split[UBound($path_split) - 1], 4) EndFunc ;==>get_filename Func wrong_file_extension($path = $cmdline[1]) Return StringRight($path, 4) <> '.mnm' EndFunc ;==>wrong_file_extension Func set_default_file() Global $cmdline = [1, $file_intro] ; overwrite if empty to load default intro file EndFunc ;==>set_default_file If $cmdline[0] = 1 Then If wrong_file_extension() Then alert('Wrong file type!', 'You can only open *.mnm files with this program.', $alert_ok) set_default_file() EndIf Else set_default_file() EndIf #EndRegion parameters #Region MiniMark gui $MiniMark_form = GUICreate('MiniMark', 380, 380, Default, Default, $ws_popup, $ws_ex_layered) GUISetBkColor($color_transparent_background) $MiniMark_background = GUICtrlCreatePic($image_MiniMark, 0, 0, 380, 380) GUICtrlSetState(Default, $gui_disable) $MiniMark_title = title_create(get_filename(), 370) $MiniMark_edit = _GUICtrlRichEdit_Create($MiniMark_form, 'Loading...', 10, 35, 270, 335, BitOR($es_multiline, $es_autovscroll, $es_nohidesel), 0) ; $es_nohidesel for visible selection when using search function _GUICtrlRichEdit_SetBkColor($MiniMark_edit, $color_control_gray) $button_settings = button_create('Options', 'Open settings.', Default, 305, 30) $button_open = button_create('Open', 'Open a new *.mnm file.', 'ctrl + o', 305, 55) $button_bold = button_create('Bold', 'Make selection bold.', 'ctrl + b', 305, 80) $button_italic = button_create('Italic', 'Make selection italic.', 'ctrl + i', 305, 105) $button_struck = button_create('Struck', 'Make selection struck.', 'ctrl + t', 305, 130) $button_underline = button_create('Underline', 'Make selection underlined.', 'ctrl + u', 305, 155) $button_red = button_create('Red', 'Make selection red.', 'shift + ctrl + r', 305, 180) $button_green = button_create('Green', 'Make selection green.', 'shift + ctrl + g', 305, 205) $button_blue = button_create('Blue', 'Make selection blue.', 'shift + ctrl + b', 305, 230) $button_white = button_create('White', 'Make selection white.', 'shift + ctrl + w', 305, 255) $button_default = button_create('Default', 'Make selection default style and gray.', 'shift + ctrl + d', 305, 280) $button_search = button_create('Search', 'Find and replace text.', 'ctrl + f', 305, 305) $button_save = button_create('save', 'Save file / save file as.', 'ctrl + s / shift + ctrl + s', 305, 330) $save_as = GUICtrlCreateDummy() $button_now = GUICtrlCreateDummy() $button_tick = GUICtrlCreateDummy() $button_upper = GUICtrlCreateDummy() $button_lower = GUICtrlCreateDummy() $button_quit = button_create('Quit', 'Quit the program.', 'escape', 305, 355) $MiniMark_scroll_up = GUICtrlCreatePic($image_scroll_up, 290, 30, 10, 10) $MiniMark_scroll_thumb = GUICtrlCreatePic($image_scroll, 290, 45, 10, 20) ; scroll background: 290, 45, 10, 315 $MiniMark_scroll_down = GUICtrlCreatePic($image_scroll_down, 290, 365, 10, 10) _WinAPI_SetLayeredWindowAttributes($MiniMark_form, $color_transparent_background) ;set the transparant gui color GUISetState(@SW_SHOW, $MiniMark_form) play_sound($sound_start) ; play MiniMark startup sound. #EndRegion MiniMark gui #Region edit messages ; we need this becouse the rich edit keeps changing the text to the default style. GUIRegisterMsg($wm_command, wm_command) Func wm_command($hwnd, $imsg, $wparam, $lparam) If $MiniMark_edit <> $lparam Then Return $gui_rundefmsg If _GUICtrlRichEdit_IsTextSelected($MiniMark_edit) Then Return $gui_rundefmsg If _GUICtrlRichEdit_GetFont($MiniMark_edit)[1] <> $font_lucida_console Then _GUICtrlRichEdit_SetFont($MiniMark_edit, 9, $font_lucida_console) _GUICtrlRichEdit_SetCharColor($MiniMark_edit, $color_text_gray) EndIf Return $gui_rundefmsg EndFunc ;==>wm_command ; we need this to make the rich edit scrollable with no $ws_vscroll set (we use a custom scrollbar instead). _GUICtrlRichEdit_SetEventMask($MiniMark_edit, $enm_scrollevents) GUIRegisterMsg($wm_notify, wm_notify) Func wm_notify($hwnd, $imsg, $wparam, $lparam) Local $tfilter = DllStructCreate($tagmsgfilter, $lparam) If $tfilter.hwndfrom = $MiniMark_edit Then _GUICtrlRichEdit_ScrollLines($tfilter.hwndfrom, $tfilter.wparam ? 1 : -1) Return $gui_rundefmsg EndFunc ;==>wm_notify #EndRegion edit messages #Region markup functions ; function that handles text color actions. Func colorize($color) ; if already in selected color -> make default color again play_sound($sound_click) If _GUICtrlRichEdit_GetCharColor($MiniMark_edit) <> $color Then _GUICtrlRichEdit_SetCharColor($MiniMark_edit, $color) Else _GUICtrlRichEdit_SetCharColor($MiniMark_edit, $color_text_gray) EndIf If $color = $color_text_gray Then _GUICtrlRichEdit_SetCharAttributes($MiniMark_edit, '-bo-it-un-st') EndFunc ;==>colorize ; function that handles text style actions. Func stylize($style) ; if already in selected style -> undo style play_sound($sound_click) If StringInStr(_GUICtrlRichEdit_GetCharAttributes($MiniMark_edit), $style & '+') Then _GUICtrlRichEdit_SetCharAttributes($MiniMark_edit, '-' & $style) Else _GUICtrlRichEdit_SetCharAttributes($MiniMark_edit, '+' & $style) EndIf EndFunc ;==>stylize #EndRegion markup functions #Region tools Func change_case($upper) Local $selection = _GUICtrlRichEdit_GetSel($MiniMark_edit) If $selection[0] = $selection[1] Then Return Local $selection_text = _GUICtrlRichEdit_GetSelText($MiniMark_edit) If $upper Then $selection_text = StringUpper($selection_text) Else $selection_text = StringLower($selection_text) EndIf _GUICtrlRichEdit_ReplaceText($MiniMark_edit, $selection_text) _GUICtrlRichEdit_SetSel($MiniMark_edit, $selection[0], $selection[1]) EndFunc Func tickmark() Local $first_char = _GUICtrlRichEdit_GetFirstCharPosOnLine($MiniMark_edit) Local $line_from_char = _GUICtrlRichEdit_GetLineNumberFromCharPos($MiniMark_edit, $first_char) Local $tick_type = StringLeft(_GUICtrlRichEdit_GetTextInLine($MiniMark_edit, $line_from_char), 1) Local $tick_replace Switch $tick_type ; ■□○●• Case '☐' $tick_replace = '☑' Case '☑' $tick_replace = '☐' Case Else _GUICtrlRichEdit_SetSel($MiniMark_edit, $first_char, $first_char) _GUICtrlRichEdit_InsertText($MiniMark_edit, '☐ ') Return endSwitch _GUICtrlRichEdit_SetSel($MiniMark_edit, $first_char, $first_char + 1) _GUICtrlRichEdit_ReplaceText($MiniMark_edit, $tick_replace) EndFunc #EndRegion tools #Region scroller messages ; the scrollbar of hell! ; https://www.autoitscript.com/forum/topic/212778-goto-specific-line-in-rich-edit-control Const $scroll_x = 290 ; x of $scroll control at all times Const $scroll_t = 45, $scroll_m = 295 ; top and maximum Local $scroll_drag = False ; are we dragging the scroll button? Local $scroll_selection ; remember the current selection before we change it Func edit_clicked() Local $scroll_cursor = GUIGetCursorInfo($MiniMark_form) ; get x, y position of cursor If $scroll_cursor[0] >= 5 And $scroll_cursor[0] <= 285 And $scroll_cursor[1] >= 30 And $scroll_cursor[1] <= 375 Then Local $scroll_y Local $scroll_line = _GUICtrlRichEdit_GetLineNumberFromCharPos($MiniMark_edit, _GUICtrlRichEdit_GetSel($MiniMark_edit)[1]) - 1 Local $scroll_last = _GUICtrlRichEdit_GetLineCount($MiniMark_edit) - 1 If $scroll_last = 0 Then $scroll_y = $scroll_t Else $scroll_y = $scroll_t + (($scroll_line / $scroll_last) * $scroll_m) EndIf GUICtrlSetPos($MiniMark_scroll_thumb, $scroll_x, $scroll_y) ; drag scroll button within range of background bar EndIf EndFunc ;==>edit_clicked Func thumb_clicked() Local $scroll_cursor = GUIGetCursorInfo($MiniMark_form) If $scroll_cursor[0] >= 290 And $scroll_cursor[0] <= 300 And $scroll_cursor[1] >= 45 And $scroll_cursor[1] <= 360 Then $scroll_drag = True $scroll_selection = _GUICtrlRichEdit_GetSel($MiniMark_edit) EndIf EndFunc ;==>thumb_clicked Func thumb_motion() If Not $scroll_drag Then Return Local $scroll_x = 290 ; x of $scroll control at all times Local $scroll_min_y = 55, $scroll_max_y = 350 ; range of y movement for $scroll (top of frame till bottom - height) Local $scroll_cursor = GUIGetCursorInfo($MiniMark_form)[1] ; get y position of cursor If $scroll_cursor < $scroll_min_y Then $scroll_cursor = $scroll_min_y If $scroll_cursor > $scroll_max_y Then $scroll_cursor = $scroll_max_y GUICtrlSetPos($MiniMark_scroll_thumb, $scroll_x, $scroll_cursor - 10) ; drag scroll button within range of background bar Local $scroll_ratio = ($scroll_cursor - $scroll_min_y) / ($scroll_max_y - $scroll_min_y) ; calculate scroll position percentage between 0 and 1 Local $scroll_last = _GUICtrlRichEdit_GetLineCount($MiniMark_edit) Local $scroll_calculate = $scroll_ratio * $scroll_last ; calculate where to walk to Local $scroll_line = _GUICtrlRichEdit_GetFirstCharPosOnLine($MiniMark_edit, $scroll_calculate) _GUICtrlRichEdit_SetSel($MiniMark_edit, $scroll_line, $scroll_line) EndFunc ;==>thumb_motion Func thumb_released() If $scroll_drag Then Local $scroll_new_pos = _GUICtrlRichEdit_GetScrollPos($MiniMark_edit) _GUICtrlRichEdit_SetSel($MiniMark_edit, $scroll_selection[0], $scroll_selection[1]) _GUICtrlRichEdit_SetScrollPos($MiniMark_edit, $scroll_new_pos[0], $scroll_new_pos[1]) $scroll_drag = False EndIf EndFunc ;==>thumb_released #EndRegion scroller messages #Region shortcuts ; here we set all the shortcuts for the buttons. Dim $hotkeysaccel[18][2] = [ _ ['+^d', $button_default], _ ['^b', $button_bold], _ ['^i', $button_italic], _ ['^u', $button_underline], _ ['^t', $button_struck], _ ['+^r', $button_red], _ ['+^g', $button_green], _ ['+^b', $button_blue], _ ['+^w', $button_white], _ ['^o', $button_open], _ ['^s', $button_save], _ ['+^s', $save_as], _ ['{f5}', $button_now], _ ['!t', $button_tick], _ ['!u', $button_upper], _ ['!l', $button_lower], _ ['^f', $button_search], _ ['{esc}', $button_quit] _ ] GUISetAccelerators($hotkeysaccel, $MiniMark_form) #EndRegion shortcuts #Region search gui $search_form = GUICreate('Search', 305, 105, Default, Default, $ws_popup, BitOR($ws_ex_layered, $ws_ex_topmost)) GUISetBkColor($color_transparent_background) GUICtrlCreatePic($image_search, 0, 0, 305, 105) GUICtrlSetState(Default, $gui_disable) $search_title = title_create('Find and replace', 295) $input_find = input_create(10, 30, 'What to look for.') $input_replace = input_create(10, 55, 'Replace by what.') $checkbox_case_state = 0 $checkbox_case = checkbox_create('Case', 'Toggle casesence.', Default, 230, 30) $checkbox_word_state = 0 $checkbox_word = checkbox_create('Word', 'Toggle whole word only.', Default, 230, 55) $button_search_find = button_create('Find', 'find string.', Default, 5, 80) $button_search_replace = button_create('Replace', 'Replace current match.', Default, 80, 80) $button_search_replace_all = button_create('Replace all', 'Replace all matches.', Default, 155, 80) $button_search_close = button_create('Close', '', Default, 230, 80) _WinAPI_SetLayeredWindowAttributes($search_form, $color_transparent_background) ;set the transparant gui color #EndRegion search gui #Region search functions Func find() Local $find_text = GUICtrlRead($input_find) If $find_text = '' Then Return play_sound($sound_click) Local $selection = _GUICtrlRichEdit_GetSel($MiniMark_edit) $selection = _GUICtrlRichEdit_FindTextInRange($MiniMark_edit, $find_text, $selection[1], -1, $checkbox_case_state = 1, $checkbox_word_state = 1) If $selection[0] = -1 And $selection[1] = -1 Then alert('Search ended', 'No more matches found.' & @CRLF & 'Next time when you press the [Find] button, the search function will start looking from the beginning of the text.', $alert_ok) _GUICtrlRichEdit_SetSel($MiniMark_edit, 0, 0) Else _GUICtrlRichEdit_SetSel($MiniMark_edit, $selection[0], $selection[1]) EndIf EndFunc ;==>find Func replace() Local $find_text = GUICtrlRead($input_find) If $find_text = '' Then Return play_sound($sound_click) Local $replace_text = GUICtrlRead($input_replace) _GUICtrlRichEdit_ReplaceText($MiniMark_edit, $replace_text) find() EndFunc ;==>replace Func replace_all() Local $find_text = GUICtrlRead($input_find) If $find_text = '' Then Return play_sound($sound_click) Local $replace_text = GUICtrlRead($input_replace) Local $selection = _GUICtrlRichEdit_FindTextInRange($MiniMark_edit, $find_text, 0, -1, $checkbox_case_state = 1, $checkbox_word_state = 1) While $selection[0] > -1 And $selection[1] > -1 _GUICtrlRichEdit_SetSel($MiniMark_edit, $selection[0], $selection[1]) _GUICtrlRichEdit_ReplaceText($MiniMark_edit, $replace_text) $selection = _GUICtrlRichEdit_FindTextInRange($MiniMark_edit, $find_text, $selection[1], -1, $checkbox_case_state = 1, $checkbox_word_state = 1) WEnd alert('Search ended', 'No more matches found.' & @CRLF & 'All matches are replaced (if there were are any).', $alert_ok) EndFunc ;==>replace_all Func find_and_replace() play_sound($sound_click) local $selection_text = _GUICtrlRichEdit_GetSelText($MiniMark_edit) if @error <> -1 then GUICtrlSetData($input_find, $selection_text) GUISetState(@SW_SHOW, $search_form) While 1 Switch GUIGetMsg() Case $gui_event_close, $button_search_close play_sound($sound_click) GUISetState(@SW_HIDE, $search_form) ExitLoop Case $checkbox_case checkbox_toggle($checkbox_case, $checkbox_case_state) Case $checkbox_word checkbox_toggle($checkbox_word, $checkbox_word_state) Case $button_search_find find() Case $button_search_replace replace() Case $button_search_replace_all replace_all() EndSwitch WEnd EndFunc #EndRegion search functions #Region settings $font_size = Int(IniRead($file_settings, 'settings', 'fontsize', 100)) $settings_form = GUICreate('Settings', 230, 80, Default, Default, $ws_popup, BitOR($ws_ex_layered, $ws_ex_topmost)) GUISetBkColor($color_transparent_background) GUICtrlCreatePic($image_settings, 0, 0, 230, 80) GUICtrlSetState(Default, $gui_disable) $settings_title = title_create('Settings', 220) $checkbox_sound = checkbox_create('Sound', 'play sounds?', Default, 5, 30, $checkbox_sound_state) $button_settings_save = button_create('Save', 'Save settings.', Default, 5, 55) $button_settings_info = button_create('Info', 'About MiniMark.', Default, 155, 30) $button_settings_reset = button_create('Reset', 'Reset to default settings.', Default, 80, 55) $button_settings_close = button_create('Close', '', Default, 155, 55) $number_step = GUICtrlCreateInput($font_size, 85, 30, 45, 20, BitOR($es_center, $es_number, $es_autohscroll), 0) GUICtrlSetTip(Default, 'Custom font size (zoom).') GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $color_control_gray) GUICtrlSetFont(Default, 12, 400, 0, $font_handel_gothic_bt) GUICtrlSetLimit(Default, 8) $number_step_up = GUICtrlCreatePic($image_size_up, 130, 30, 20, 10) $number_step_down = GUICtrlCreatePic($image_size_down, 130, 40, 20, 10) _WinAPI_SetLayeredWindowAttributes($settings_form, $color_transparent_background) ;set the transparant gui color #EndRegion settings #Region settings function Func settings() play_sound($sound_click) GUICtrlSetData($number_step, Int(_GUICtrlRichEdit_GetZoom($MiniMark_edit))) GUISetState(@SW_SHOW, $settings_form) While 1 Switch GUIGetMsg() Case $gui_event_close, $button_settings_close play_sound($sound_click) GUISetState(@SW_HIDE, $settings_form) ExitLoop Case $checkbox_sound checkbox_toggle($checkbox_sound, $checkbox_sound_state) Case $number_step_up number_step(1) Case $number_step_down number_step(-1) Case $button_settings_info If alert('About', 'MiniMark version 4.' & @CRLF & 'Created by:' & @CRLF & 'Tom Schrauwen (TheAutomator).', $alert_link_close) = 1 Then ShellExecute('https://www.autoitscript.com/forum/topic/212763-MiniMark-a-minimalistic-rtf-editor') Case $button_settings_reset settings_reset() Case $button_settings_save settings_save() EndSwitch WEnd EndFunc #EndRegion settings function #Region settings messages ; write ini Func number_step($amount) Local $number = GUICtrlRead($number_step) $number += $amount GUICtrlSetData($number_step, $number) play_sound($sound_click) EndFunc ;==>number_step Func settings_reset() If Not $checkbox_sound_state Then checkbox_toggle($checkbox_sound, $checkbox_sound_state) GUICtrlSetData($number_step, 100) play_sound($sound_click) EndFunc ;==>settings_reset Func settings_save() IniWrite($file_settings, 'settings', 'sound', $checkbox_sound_state) IniWrite($file_settings, 'settings', 'fontsize', GUICtrlRead($number_step)) _GUICtrlRichEdit_SetZoom($MiniMark_edit, GUICtrlRead($number_step)) play_sound($sound_click) EndFunc ;==>settings_save #EndRegion settings messages #Region file functions ; if this is not the case, or when there are no arguments, we just open the intro file instead. ; also extract the filename from $cmdline to display as title. Func load_file() ; add fileexists check? GUICtrlSetData($MiniMark_title, get_filename()) GUICtrlSetTip($MiniMark_title, $cmdline[1]) ; display full path on mouse over title _GUICtrlRichEdit_Deselect($MiniMark_edit) _GUICtrlRichEdit_StreamFromFile($MiniMark_edit, $cmdline[1]) _GUICtrlRichEdit_SetZoom($MiniMark_edit, Int($font_size)) ; needed becouse it resets after loading (https://www.autoitscript.com/forum/topic/190695-_guictrlrichedit_setzoom-parameter-limitation) _GUICtrlRichEdit_SetModified($MiniMark_edit, False) _GUICtrlRichEdit_EmptyUndoBuffer($MiniMark_edit) GUICtrlSetPos($MiniMark_scroll_thumb, $scroll_x, 340) ; put scroll button at end EndFunc ;==>load_file load_file() ; load input file ; before opening another file or before quitting, we need to check if the current file is modified. Func save_changes_cancel() ; returns true if we wanna cancel follow up actions If Not _GUICtrlRichEdit_IsModified($MiniMark_edit) Then Return Switch alert('Save changes?', 'This file was modified.' & @CRLF & 'Do you wanna save your work first?', $alert_yes_no_cancel) Case 1 ; yes save_file() Case 2 ; no Return Case Else Return True ; abort next actions EndSwitch EndFunc ;==>save_changes_cancel ; the function that saves the current text to a *.mnm file. ; _guictrlrichedit_streamtofile($edit, $cmdline[1]) -> bug, adds new paragraph every time (see ticket). Func save_file($as = False) ; as triggers a save to dialog If $as Then play_sound($sound_click) Local $new_file = FileSaveDialog('Save MiniMark file...', @DesktopDir, 'MiniMark file (*.mnm)', 16, '', $MiniMark_form) If @error Or wrong_file_extension() Then Return $cmdline[1] = $new_file GUICtrlSetTip($MiniMark_title, $new_file) ; display full path on mouse over title GUICtrlSetData($MiniMark_title, get_filename()) Else If Not _GUICtrlRichEdit_IsModified($MiniMark_edit) Then Return play_sound($sound_click) EndIf _GUICtrlRichEdit_Deselect($MiniMark_edit) Local $var = _GUICtrlRichEdit_StreamToVar($MiniMark_edit) $var = StringTrimRight($var, 9) & "}" ; bug will be resolved in future versions Local $file = FileOpen($cmdline[1], $fo_overwrite) Local $written = FileWrite($file, $var) FileClose($file) If $written = 1 Then ; 0 = failed to write, 1 = succes _GUICtrlRichEdit_SetModified($MiniMark_edit, False) Else alert('File write error!', "Can't save the file..." & @CRLF & 'Check if the file is read only.', $alert_ok) EndIf EndFunc ;==>save_file ; open a file with the open dialog. Func open_file() If save_changes_cancel() Then Return play_sound($sound_click) Local $file = FileOpenDialog('Open new MiniMark file...', @DesktopDir, 'MiniMark file (*.mnm)', 3, '', $MiniMark_form) If @error Or wrong_file_extension() Then Return $cmdline[1] = $file load_file() EndFunc ;==>open_file #EndRegion file functions #Region quit function ; when the program unloads we need to destroy the rich edit control and play the stop sound Func quit() If save_changes_cancel() Then Return play_sound($sound_stop, 1) _GUICtrlRichEdit_Destroy($MiniMark_edit) GUIDelete() Exit EndFunc ;==>quit #EndRegion quit function #Region main loop While 1 Switch GUIGetMsg() Case $gui_event_close, $button_quit quit() Case $button_now _GUICtrlRichEdit_InsertText($MiniMark_edit, _now()) Case $button_tick tickmark() Case $button_upper change_case(True) Case $button_lower change_case(False) Case $MiniMark_scroll_up play_sound($sound_click) _GUICtrlRichEdit_ScrollLines($MiniMark_edit, -1) Case $MiniMark_scroll_down play_sound($sound_click) _GUICtrlRichEdit_ScrollLines($MiniMark_edit, 1) Case $button_open open_file() Case $button_save save_file() Case $save_as save_file(True) Case $button_bold stylize('bo') Case $button_italic stylize('it') Case $button_struck stylize('st') Case $button_underline stylize('un') Case $button_red colorize($color_text_red) Case $button_green colorize($color_text_green) Case $button_blue colorize($color_text_blue) Case $button_white colorize($color_text_white) Case $button_default colorize($color_text_gray) Case $gui_event_primarydown thumb_clicked() Case $gui_event_mousemove thumb_motion() Case $gui_event_primaryup edit_clicked() thumb_released() Case $button_search find_and_replace() Case $button_settings settings() EndSwitch WEnd #EndRegion main loop And here is the code for the installer: SETUP FOR VERSION 4 STILL IN THE MAKING! #cs function: installer for MiniMark version: 3 made by: TheAutomator project: https://www.autoitscript.com/forum/topic/212763-minimark-a-minimalistic-rtf-editor todo: • check if programfiles exist when opened • add choice for install path and user level install • installer does'nt use the "fileinstall" function (yet) #ce #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #autoit3wrapper_icon=setup\setup.ico #autoit3wrapper_outfile=Setup.EXE #autoit3wrapper_compression=4 #autoit3wrapper_useupx=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #NoTrayIcon #RequireAdmin #include <guiconstants.au3> #include <winapisyswin.au3> const $source_path = @ScriptDir & '\minimark' const $setup_path = @ScriptDir & '\setup' const $install_path = @ProgramFilesDir & '\MiniMark' const $install_font = @ScriptDir & '\setup\handelgo.ttf' const $font_lucida = 'lucida console' const $image_background = @scriptdir & '\setup\setup.bmp' const $image_install = @scriptdir & '\setup\install.bmp' const $image_remove = @scriptdir & '\setup\remove.bmp' const $image_exit = @scriptdir & '\minimark\exit.bmp' const $color_gui_transparant = 0xff00ff const $color_edit_background = 0x323232 const $color_edit_gray = 0xb4b4b4 const $color_edit_red = 0xff0066 const $color_edit_green = 0x66ff00 const $sound_start = @scriptdir & '\minimark\start.wav' const $sound_click = @scriptdir & '\minimark\click.wav' const $sound_alert = @scriptdir & '\minimark\alert.wav' const $sound_stop = @scriptdir & '\minimark\stop.wav' local $check_installed = FileExists($install_path) soundplay($sound_start) ; startup sound $form = guicreate('MiniMark Setup', 310, 240, default, default, $ws_popup, $ws_ex_layered) guisetbkcolor($color_gui_transparant) $title = guictrlcreatelabel('', 10, 10, 280, 20, $SS_GRAYRECT, $gui_ws_ex_parentdrag) ; use label to drag form (hidden behind gui image) guictrlcreatepic($image_background, 0, 0, 310, 240) guictrlsetstate(default, $gui_disable) $console = GUICtrlCreateEdit('MiniMark V3 setup' & @CRLF & 'made by: TheAutomator', 20, 50, 270, 140, bitor($es_multiline, $es_autovscroll, $es_readonly), 0) GUICtrlSetColor(Default, $color_edit_gray) GUICtrlSetBkColor(Default, $color_edit_background) GUICtrlSetFont(Default, 9, 0, 0, $font_lucida) $button_install = guictrlcreatepic($check_installed ? $image_remove : $image_install, 10, 210, 50, 20) $button_exit = guictrlcreatepic($image_exit, 250, 210, 50, 20) $escape = guictrlcreatedummy() dim $hotkeysaccel[1][2] = [["{esc}", $escape]] guisetaccelerators($hotkeysaccel) _winapi_setlayeredwindowattributes($form, $color_gui_transparant) ; 0xff00ff is set as the transparant gui color guisetstate() func console($text) GUICtrlSetData($console, @crlf & @crlf & $text, 1) EndFunc console($check_installed ? 'it looks like MiniMark is already installed, press [remove] to uninstall' : 'it looks like MiniMark is not installed yet, press [install] to install it') func install_remove() ; needs admin rights, compiling installer to exe is probably needed... GUICtrlSetColor($console, $color_edit_green) soundplay($sound_click) GUICtrlSetState($button_install, $gui_hide) if $check_installed then ; remove it console('removing MiniMark from:') console($install_path) DirRemove($install_path, 1) console('removing MiniMark menu') RegDelete('HKEY_CLASSES_ROOT\.mnm') RegDelete('HKEY_CLASSES_ROOT\MiniMark') console('removing "handelgothic bt" font') RegDelete('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', 'HandelGothic BT (TrueType)') ; uninstall font in registery DllCall('gdi32.dll', 'int', 'RemoveFontResource', 'str', @WindowsDir & '\Fonts\handelgo.ttf') ; uninstall font in fonts folder DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', 0xFFFF, 'int', 0x1D, 'int', 0, 'int', 0) ; tell windows about font changes FileDelete(@WindowsDir & '\Fonts\handelgo.ttf') ; delete font in fonts folder $check_installed = FileExists($install_path) if $check_installed Then GUICtrlSetColor($console, $color_edit_red) soundplay($sound_alert) console('MiniMark was not removed correctly...') Else console('MiniMark was uninstalled succesfully!') EndIf Else ; install it console('installing MiniMark to:') console($install_path) DirCopy($source_path, $install_path, 1) ; $fc_overwrite console('installing MiniMark menu') RegWrite('HKEY_CLASSES_ROOT\.mnm', '', 'REG_SZ', 'MiniMark') ; add filetype RegWrite('HKEY_CLASSES_ROOT\.mnm', 'PerceivedType', 'REG_SZ', 'Document') ; tell windows it's a document RegWrite('HKEY_CLASSES_ROOT\.mnm\ShellNew', 'NullFile', 'REG_SZ', '') ; add it to the 'new' file menu RegWrite('HKEY_CLASSES_ROOT\MiniMark', '', 'REG_SZ', 'MiniMark File') ; add edit menu for *.mnm file RegWrite('HKEY_CLASSES_ROOT\MiniMark', 'BrowserFlags', 'REG_DWORD', '00000008') RegWrite('HKEY_CLASSES_ROOT\MiniMark', 'EditFlags', 'REG_DWORD', '00000000') RegWrite('HKEY_CLASSES_ROOT\MiniMark\DefaultIcon', '', 'REG_SZ', $install_path & '\MiniMark.exe,0') ; set icon for *.mnm file RegWrite('HKEY_CLASSES_ROOT\MiniMark\Shell\Open', 'Icon', 'REG_SZ', $install_path & '\MiniMark.exe,0') ; set icon for open menu RegWrite('HKEY_CLASSES_ROOT\MiniMark\Shell\Open\Command', '', 'REG_SZ', $install_path & '\MiniMark.exe "%1"') ; always open with MiniMark console('installing "handelgothic bt" font') FileCopy($install_font, @WindowsDir & '\Fonts\', 1) ; $FC_OVERWRITE (1) = overwrite existing files RegWrite('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', 'HandelGothic BT (TrueType)', 'REG_SZ', 'handelgo.ttf') ; install font in registery DllCall('gdi32.dll', 'int', 'AddFontResource', 'str', @WindowsDir & '\Fonts\handelgo.ttf') ; install font in fonts folder DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', 0xFFFF, 'int', 0x1D, 'int', 0, 'int', 0) ; tell windows about font changes DllCall('shell32.dll', 'none', 'SHChangeNotify', 'long', 0x08000000, 'uint', 0, 'ptr', 0, 'ptr', 0) ; refresh the icon cache (ie4uinit.exe -show) $check_installed = FileExists($install_path) if $check_installed Then console('MiniMark was installed succesfully!') Else GUICtrlSetColor($console, $color_edit_red) soundplay($sound_alert) console('MiniMark was not installed correctly...') EndIf EndIf guictrlsetimage($button_install, $check_installed ? $image_remove : $image_install) GUICtrlSetState($button_install, $gui_show) EndFunc func quit() soundplay($sound_stop, 1) exit endfunc while 1 switch guigetmsg() case $gui_event_close, $button_exit, $escape quit() case $button_install install_remove() endswitch wend TheAutomator. MiniMark 4 BETA.zip
  2. After a week’s work with RichEdit controls, I’ve made some observations and come to some conclusions that may help others. The main two are: Rich Text is relatively easy when used inside an AutoIt GUI ... as there are ample commands in the _GUICtrlRichText_*** UDF set. Rich Text is fairly difficult when you start to work with multiple fields and with RTF from other sources, largely because of the wide variations in implementations ... but sometimes due to AutoIt-specific support for rich text formats. As a result of my investigation—and with assistance from mLipok—I’ve produced a Rich Text Tool to help me follow the details of the embedded format definitions. I’m offering it here to help others fathom these details. In the paragraphs that follow the code, I list some of my observations/conclusions in hopes that others might shed additional light. ;======================================== ; Tool for analyzing AutoIt's Rich Text Processing Features ; (and to demonstrate serveral of the common methods) ; >> based on the example script developed by mLipok ; >> with these "tool" enhancements by qwert ; June, 2014 ;======================================== #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Local $hGui, $hRichEdit, $hRichEdit2, $hRichEdit3, $hRichEdit123 Local $iMsg $hGui = GUICreate("Rich Edit Tools", 1260, 400, -1, 200) ;#Region Create all RichEdit controls $hRichEdit1 = _GUICtrlRichEdit_Create($hGui, "This is a first test.", 10, 10, 300, 100, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit1, @CRLF & "This is more text" & @CRLF) _GUICtrlRichEdit_SetSel($hRichEdit1, 0, 22) _GUICtrlRichEdit_SetFont($hRichEdit1, 14, "Arial") _GUICtrlRichEdit_SetSel($hRichEdit1, -1, -1) $hRichEdit2 = _GUICtrlRichEdit_Create($hGui, "This is a second test.", 10, 130, 300, 100, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit2, @CRLF & "This is more text" & @CRLF) _GUICtrlRichEdit_SetSel($hRichEdit2, 10, 22) _GUICtrlRichEdit_SetFont($hRichEdit2, 14, "Arial") _GUICtrlRichEdit_SetSel($hRichEdit2, -1, -1) $hRichEdit3 = _GUICtrlRichEdit_Create($hGui, "This is a third test.", 10, 250, 300, 100, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit3, @CRLF & "This is more text" & @CRLF) _GUICtrlRichEdit_SetSel($hRichEdit3, 10, 21) _GUICtrlRichEdit_SetFont($hRichEdit3, 14, "Arial") _GUICtrlRichEdit_SetSel($hRichEdit3, -1, -1) $hRichEdit123 = _GUICtrlRichEdit_Create($hGui, "This is the combined result.", 320, 30, 300, 280, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit123, @CRLF & @CRLF) ;#EndRegion Create all RichEdit controls $hVerbatim = GUICtrlCreateEdit ("This is the resulting Rich Text.", 630, 30, 300, 280, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $hRichResult = _GUICtrlRichEdit_Create($hGui, "Reserved for process result.", 940, 30, 300, 280, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetFont(16, 700, 0, "Arial") GUICtrlCreateLabel("Combined", 324, 6, 120, 24) GUICtrlCreateLabel("Verbatim", 634, 6, 120, 24) GUICtrlCreateLabel("Result", 944, 6, 120, 24) GUICtrlCreateLabel("\", 562, 310, 120, 24) GUICtrlCreateLabel("\", 872, 310, 120, 24) GUICtrlCreateLabel("/", 680, 310, 120, 24) GUICtrlCreateLabel("/", 990, 310, 120, 24) GUISetFont(12, 400, 0, "Arial") GUICtrlCreateLabel("These tools use the copy/paste method of combining the rich text fields.", 320, 372, 500, 24) $Combine = GUICtrlCreateButton("Combine", 104, 364, 120, 24) GUICtrlSetTip(-1, "Click to redo the combining operation") $ProcessRich = GUICtrlCreateButton("Process", 564, 330, 120, 24) GUICtrlSetTip(-1, "Click to produce Verbatim from Combined") $ProcessVerb = GUICtrlCreateButton("Process", 874, 330, 120, 24) GUICtrlSetTip(-1, "Click to produce Result from Verbatim") GUISetState(@SW_SHOW) Sleep(800) ; for effect only _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit1, $hRichEdit123) ; Copying $hRichEdit1 to $hRichEdit123 Sleep(800) _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit2, $hRichEdit123) ; Copying $hRichEdit2 to $hRichEdit123 Sleep(800) _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit3, $hRichEdit123) ; Copying $hRichEdit3 to $hRichEdit123 Local $Var = _GUICtrlRichEdit_StreamToVar($hRichEdit123, True) $Var = StringReplace($Var, "MS Shell Dlg", "Arial", 0) ; <<<< example of a DIRECT EDIT to change the default font Sleep(800) ;MsgBox(0, "Result", $Var, 0) ; OPTION to view before storing _GUICtrlRichEdit_StreamFromVar ($hRichEdit123, $Var) _GUICtrlRichEdit_StreamToFile($hRichEdit123, @ScriptDir & "\Rich123.rtf", True) GUICtrlSetData($hVerbatim, $Var) Sleep(800) ; again, for effect MsgBox(0, "", "Done", 1) While True $iMsg = GUIGetMsg() Select Case $iMsg = $Combine _GUICtrlRichEdit_SetSel($hRichEdit123, 0, -1) _GUICtrlRichEdit_ReplaceText($hRichEdit123, "New result:" & @CRLF & @CRLF) Sleep(800) ; for effect only _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit1, $hRichEdit123) Sleep(800) ; for effect only _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit2, $hRichEdit123) Sleep(800) ; for effect only _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit3, $hRichEdit123) Sleep(800) ; again, for effect MsgBox(0, "", "Done" & @CRLF & "Verbatim is unchanged at this point." & @CRLF & "Click Process to update it.", 2) Case $iMsg = $ProcessRich Local $Var = _GUICtrlRichEdit_StreamToVar($hRichEdit123, True) GUICtrlSetData($hVerbatim, $Var) MsgBox(0, "", "Done", 1) Case $iMsg = $ProcessVerb _GUICtrlRichEdit_StreamFromVar ($hRichResult, GUICtrlRead($hVerbatim)) MsgBox(0, "", "Done", 1) Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit1) ; needed unless script crashes _GUICtrlRichEdit_Destroy($hRichEdit2) ; needed unless script crashes _GUICtrlRichEdit_Destroy($hRichEdit3) ; needed unless script crashes _GUICtrlRichEdit_Destroy($hRichResult) ; needed unless script crashes _GUICtrlRichEdit_Destroy($hRichEdit123) ; needed unless script crashes ; GUIDelete() ; is OK too Exit EndSelect WEnd Func _GUICtrlRichEdit_CopyAllToRichEdit(ByRef $hSourceRichEdit, ByRef $hDestinationRichEdit) Local $aSelection = _GUICtrlRichEdit_GetSel($hSourceRichEdit) ; check for current selection in source control _GUICtrlRichEdit_SetSel($hSourceRichEdit, 0, -1) ; select all contents in source control _GUICtrlRichEdit_Copy($hSourceRichEdit) ; copy selected contents from source control _GUICtrlRichEdit_Paste($hDestinationRichEdit) ; paste content to destination control _GUICtrlRichEdit_SetSel($hSourceRichEdit, $aSelection[0], $aSelection[1]) ; revert back selection in source control EndFunc ;==>_GUICtrlRichEdit_CopyAllToRichEdit Observations of AutoIt’s features and limitations: There is no effective way to assign a default font/size for a RichEdit control. You must assign the font/size to existing segments of characters ... or to the entire contents of a control (with Select All). There is no "native method" to directly write more that one control to a file*. StreamToFile handles formatting well, but can only stream out one named control to a named file. There is no option to append to these files (as there is with normal writes). (* as demonstrated by this tool, methods exist to combine RichEdit controls into a single control for use with the StreamToFile operation.) Likewise, copy to clipboard (_GuiCtrlRichEdit_Copy) preserves RichText formatting and can be useful in moving field content. From what I understand, the clipboard maintains both the RTF and text-only versions of the content. Paste and Paste Special determine which version an application receives. AutoIt's normal file and line writes are for text/data only and cannot be used for RichText controls. _GuiCtrlRichEdit_GetText gets only the text content, without character formatting. If you want to work directly with the RTF syntax, you must first to stream the RichEdit to a Variable ... and then use normal search/replace/add string operations to alter the contents of the variable. You must then update the original RichEdit using StreamFromVar in order to display your result or write to a file (StreamToFile). In Summary Think of a RichEdit control as a “processed container” for format-encoded text. The content is displayed according to rules that are embedded with the text. You can’t see the rules. You only observe their effects. And you can only use the RichEdit UDF actions to make changes to the content in a RichEdit control. If you want to see and work with those rules “verbatim”, first stream the RichEdit contents into a variable and then place the contents of that variable into a normal edit control. Once there, you can parse the rich text statements and apply literal edits and exchanges using String operations. Stream the contents of the edit control back into a RichEdit control to see the effects of those changes. The Rich Edit Tools script provides examples of the types of conversions that can be made. The field on the far right is the “interpreted result” of the verbatim text. Note the direct edit of the default font in the script. (A question: note the use of ByRef in the Function. Since it works without them, what is their purpose in this instance?) Everything I’ve outlined here is subject to correction by anyone with more in-depth experience and understanding. Please feel free to contribute. Thanks to mLipok for posting the basis for this example script, in particular, the _GUICtrlRichEdit_CopyAllToRichEdit method for combining field content.
×
×
  • Create New...