Jump to content

Recommended Posts

Posted (edited)

image.thumb.png.5d0ff1dc2528dc3604272afa15bb0911.png

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 an open 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

    function:   minimalistic program that edits custom rtf files
    version:    3
    made by:    TheAutomator
    project:    https://www.autoitscript.com/forum/topic/212763-minimark-a-minimalistic-rtf-editor

    todo:

        • make find and replace work better
        • custom scrollbar control is buggy
        • make user level install possible (requested by argumentum)
        • allow dropping files to gui
        • add shortcut to incert and change checkmarks
        • add upper/lower case function
        • add incert dcurrent time and date function
        • consider sort lines, remove duplicate lines, remove whitespace button
        • add file changed indicator
        • add option to silence sounds
        • add right click menu on edit
        • consider bigger gui
        • check if programfiles exist when opened

    wanna help debugging the AutoIT rich edit?

        https://www.autoitscript.com/trac/autoit/ticket/4038#ticket

    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)

#ce

#region ;**** directives created by autoit3wrapper_gui ****
#autoit3wrapper_icon=setup\icon.ico
#autoit3wrapper_outfile_x64=minimark\MiniMark.exe
#autoit3wrapper_usex64=y
#endregion ;**** directives created by autoit3wrapper_gui ****

#notrayicon

#include <guirichedit.au3>
#include <guiconstants.au3>
#include <winapisyswin.au3>

#region constants

    const $font_lucida = 'lucida console'
    const $font_handel = 'handelgothic bt'

    const $image_gui_background = @scriptdir & '\gui.bmp'
    const $image_blue = @scriptdir & '\blue.bmp'
    const $image_bold = @scriptdir & '\bold.bmp'
    const $image_default = @scriptdir & '\default.bmp'
    const $image_exit = @scriptdir & '\exit.bmp'
    const $image_green = @scriptdir & '\green.bmp'
    const $image_italic = @scriptdir & '\italic.bmp'
    const $image_open = @scriptdir & '\open.bmp'
    const $image_red = @scriptdir & '\red.bmp'
    const $image_save = @scriptdir & '\save.bmp'
    const $image_struck = @scriptdir & '\struck.bmp'
    const $image_under = @scriptdir & '\under.bmp'
    const $image_white = @scriptdir & '\white.bmp'
    const $image_search_background = @scriptdir & '\search.bmp'
    const $image_case_on = @scriptdir & '\case_on.bmp'
    const $image_case_off = @scriptdir & '\case_off.bmp'
    const $image_word_on = @scriptdir & '\word_on.bmp'
    const $image_word_off = @scriptdir & '\word_off.bmp'
    const $image_find = @scriptdir & '\find.bmp'
    const $image_next = @scriptdir & '\next.bmp'
    const $image_replace = @scriptdir & '\replace.bmp'
    const $image_all = @scriptdir & '\all.bmp'
    const $image_close = @scriptdir & '\close.bmp'

    const $sound_start = @scriptdir & '\start.wav'
    const $sound_click = @scriptdir & '\click.wav'
    const $sound_alert = @scriptdir & '\alert.wav'
    const $sound_stop = @scriptdir & '\stop.wav'

    const $color_gui_transparant = 0xff00ff
    const $color_title = 0x999999
    const $color_edit_background = 0x00323232
    const $color_scroll_gray = 0x4d4d4d
    const $color_edit_gray = 0x00b4b4b4
    const $color_edit_red = 0x006600ff
    const $color_edit_green = 0x0000ff66
    const $color_edit_blue = 0x00ff6600
    const $color_edit_white = 0x00ffffff

    const $file_manual = @scriptdir & '\MiniMark.mnm'

#endregion

func wrong_filetype($file) ; check if filetype is *.mnm
    if stringright($file, 4) <> '.mnm' then
        msgbox(48, 'Wrong file type!', 'You can only use *.mnm files with this program.')
        return true
    endif
endfunc

if $cmdline[0] = 0 Or wrong_filetype($cmdline[1]) then local $cmdline = [1, $file_manual] ; no / wrong input file -> opens minimark.mnm

func title_get() ; extract filename to display as title
    local $path_split = stringsplit($cmdline[1], '\', 3)
    return stringtrimright($path_split[ubound($path_split)-1], 4)
endfunc

soundplay($sound_start) ; startup sound

#region gui

    $form = guicreate('MiniMark', 380, 400, default, default, $ws_popup, $ws_ex_layered)
        guisetbkcolor($color_gui_transparant)

    guictrlcreatepic($image_gui_background, 0, 0, 380, 400)
        guictrlsetstate(default, $gui_disable)

    $edit = _guictrlrichedit_create($form, '', 20, 50, 260, 330, bitor($es_multiline, $es_autovscroll, $es_nohidesel), 0) ; $es_nohidesel for visible selection when using search functions
        _guictrlrichedit_setbkcolor($edit, $color_edit_background)
        load_file()

        guiregistermsg($wm_command, wm_command)
        func wm_command($hwnd, $imsg, $wparam, $lparam) ; we need this becouse rich edit keeps changing to default style
            if $edit <> $lparam then return $gui_rundefmsg
            if _guictrlrichedit_istextselected($edit) then return $gui_rundefmsg
            if _guictrlrichedit_getfont($edit)[1] <> $font_lucida then
                _guictrlrichedit_setfont($edit, 9, $font_lucida)
                _guictrlrichedit_setcharcolor($edit, $color_edit_gray)
            endif
            return $gui_rundefmsg
        endfunc

        _guictrlrichedit_seteventmask($edit, $enm_scrollevents)
        guiregistermsg($wm_notify, wm_notify)
        func wm_notify($hwnd, $imsg, $wparam, $lparam)
            local $tfilter = dllstructcreate($tagmsgfilter, $lparam)
            if $tfilter.hwndfrom = $edit then _guictrlrichedit_scrolllines($tfilter.hwndfrom, $tfilter.wparam ? 1 : -1)
            return $gui_rundefmsg
        endfunc

    $scroll = guictrlcreatelabel('', 300, 60, 10, 20)
        GUICtrlSetBkColor(Default, $color_scroll_gray)

    $button_exit = guictrlcreatepic($image_exit, 320, 40, 50, 20)
        guictrlsettip(default, 'Quit the program.', 'escape')

    $button_open = guictrlcreatepic($image_open, 320, 70, 50, 20)
        guictrlsettip(default, 'Open a new *.mnm file.', 'ctrl + o')

    $button_save = guictrlcreatepic($image_save, 320, 100, 50, 20)
        guictrlsettip(default, 'Save the current file.', 'ctrl + s')

    $button_bold = guictrlcreatepic($image_bold, 320, 130, 50, 20)
        guictrlsettip(default, 'Make selection bold.', 'ctrl + b')

    $button_italic = guictrlcreatepic($image_italic, 320, 160, 50, 20)
        guictrlsettip(default, 'Make selection italic.', 'ctrl + i')

    $button_struck = guictrlcreatepic($image_struck, 320, 190, 50, 20)
        guictrlsettip(default, 'Make selection struck.', 'ctrl + t')

    $button_under = guictrlcreatepic($image_under, 320, 220, 50, 20)
        guictrlsettip(default, 'Make selection underlined.', 'ctrl + u')

    $button_red = guictrlcreatepic($image_red, 320, 250, 50, 20)
        guictrlsettip(default, 'Make selection red.', 'shift + ctrl + r')

    $button_green = guictrlcreatepic($image_green, 320, 280, 50, 20)
        guictrlsettip(default, 'Make selection green.', 'shift + ctrl + g')

    $button_blue = guictrlcreatepic($image_blue, 320, 310, 50, 20)
        guictrlsettip(default, 'Make selection blue.', 'shift + ctrl + b')

    $button_white = guictrlcreatepic($image_white, 320, 340, 50, 20)
        guictrlsettip(default, 'Make selection white.', 'shift + ctrl + w')

    $button_default = guictrlcreatepic($image_default, 320, 370, 50, 20)
        guictrlsettip(default, 'Make selection default style and gray.', 'shift + ctrl + d')

    $button_search = guictrlcreatedummy()

    $title = guictrlcreatelabel(title_get(), 10, 10, 360, 20, bitor($ss_centerimage, $ss_center), $gui_ws_ex_parentdrag) ; use label to drag form
        guictrlsettip(default, $cmdline[1]) ; display full path on mouse over
        guictrlsetfont(default, 12, 400, 0, $font_handel)
        guictrlsetcolor(default, $color_title)
        guictrlsetbkcolor(default, $gui_bkcolor_transparent)

    _winapi_setlayeredwindowattributes($form, $color_gui_transparant) ; 0xff00ff is set as the transparant gui color

    guisetstate(@SW_SHOW, $form)

#endregion

#region searchbox

    $search = guicreate('Search', 310, 130, default, default, $ws_popup, $ws_ex_layered)
        guisetbkcolor($color_gui_transparant)

    guictrlcreatepic($image_search_background, 0, 0, 310, 130)
        guictrlsetstate(default, $gui_disable)

    $find_box = GUICtrlCreateInput('', 15, 40, 200, 20, $es_autohscroll, 0)
        GUICtrlSetColor(Default, $color_edit_gray)
        GUICtrlSetBkColor(Default, $color_edit_background)
        guictrlsetfont(default, 12, 400, 0, $font_handel)

    $replace_box = GUICtrlCreateInput('', 15, 70, 200, 20, $es_autohscroll, 0)
        GUICtrlSetColor(Default, $color_edit_gray)
        GUICtrlSetBkColor(Default, $color_edit_background)
        guictrlsetfont(default, 12, 400, 0, $font_handel)

    $checkbox_case = guictrlcreatepic($image_case_on, 230, 40, 70, 20)
        guictrlsettip(default, 'Toggle casesence.')
        $toggle_case = True

    $checkbox_word = guictrlcreatepic($image_word_off, 230, 70, 70, 20)
        guictrlsettip(default, 'Toggle whole word only.')
        $toggle_word = False

    $button_find = guictrlcreatepic($image_find, 10, 100, 50, 20)
        guictrlsettip(default, 'Search for the string in the first input field.')

    $button_next = guictrlcreatepic($image_next, 70, 100, 50, 20)
        guictrlsettip(default, 'Search for the next match.')

    $button_replace = guictrlcreatepic($image_replace, 130, 100, 50, 20)
        guictrlsettip(default, 'Replace current selection and look for the next match.')

    $button_all = guictrlcreatepic($image_all, 190, 100, 50, 20)
        guictrlsettip(default, 'Replace all matches.')

    $button_close = guictrlcreatepic($image_close, 250, 100, 50, 20)
        guictrlsettip(default, 'Close the find and replace window.')

    $title = guictrlcreatelabel('Find And Replace', 10, 10, 290, 20, bitor($ss_centerimage, $ss_center), $gui_ws_ex_parentdrag) ; use label to drag form
        guictrlsetfont(default, 12, 400, 0, $font_handel)
        guictrlsetcolor(default, $color_title)
        guictrlsetbkcolor(default, $gui_bkcolor_transparent)

    _winapi_setlayeredwindowattributes($search, $color_gui_transparant) ; 0xff00ff is set as the transparant gui color

#endregion

#Region shortcuts
    dim $hotkeysaccel[13][2] = [ _
        ["+^d", $button_default], _
        ["^b", $button_bold], _
        ["^i", $button_italic], _
        ["^u", $button_under], _
        ["^t", $button_struck], _
        ["+^r", $button_red], _
        ["+^g", $button_green], _
        ["+^b", $button_blue], _
        ["+^w", $button_white], _
        ["^o", $button_open], _
        ["^s", $button_save], _
        ["^f", $button_search], _
        ["{esc}", $button_exit] _
    ]
    guisetaccelerators($hotkeysaccel, $form)
#EndRegion

func load_file()
    _guictrlrichedit_deselect($edit)
    _guictrlrichedit_streamfromfile($edit, $cmdline[1])
    _guictrlrichedit_setmodified($edit, false)
    _GUICtrlRichEdit_EmptyUndoBuffer($edit)
endfunc

func save()
    _guictrlrichedit_deselect($edit)
    Local $var = _guictrlrichedit_streamtovar($edit)
    $var = stringtrimright($var, 9) & "}"
    $file = fileopen($cmdline[1], $fo_overwrite)
    filewrite($file, $var)
    fileclose($file)
    _guictrlrichedit_setmodified($edit, false)
;~  _guictrlrichedit_streamtofile($edit, $cmdline[1]) ; bug adds new paragraph every time (see ticket)
endfunc

func check_save_changes()
    if _guictrlrichedit_ismodified($edit) then
        if msgbox(8228,'Save changes?','So you wanna save your work first?') = 6 then save() ; 6 = yes, 7 = no
    endif
endfunc

func quit()
    check_save_changes()
    soundplay($sound_stop, 1)
    _guictrlrichedit_destroy($edit)
    guidelete()
    exit
endfunc

func open()
    check_save_changes()
    soundplay($sound_click)
    Local $file = FileOpenDialog('Open new MiniMark file...', @DesktopDir, 'MiniMark file (*.mnm)', 3, '', $form)
    if @error Or wrong_filetype($file) then
        soundplay($sound_alert)
        return
    endif
    $cmdline[1] = $file
    load_file()
    GUICtrlSetData($title, title_get())
endfunc

func colorize($color) ; if already in selected color -> make default color again
    if _guictrlrichedit_getcharcolor($edit) <> $color then
        _guictrlrichedit_setcharcolor($edit, $color)
    else
        _guictrlrichedit_setcharcolor($edit, $color_edit_gray)
    endif
    soundplay($sound_click)
endfunc

func stylize($style) ; if already in selected style -> undo style
    if stringinstr(_guictrlrichedit_getcharattributes($edit), $style & '+') then
        _guictrlrichedit_setcharattributes($edit, '-' & $style)
    else
        _guictrlrichedit_setcharattributes($edit, '+' & $style)
    endif
    soundplay($sound_click)
endfunc

func find() ; work in progress
    local $find_text = guictrlread($find_box)
    if $find_text = '' then return
    _guictrlrichedit_setsel($edit, 0, 0)
    local $selection = _guictrlrichedit_findtext($edit, $find_text, True, $toggle_case, $toggle_word)
    if $selection <> -1 then
        _guictrlrichedit_setsel($edit, $selection, $selection + stringlen($find_text))
    endif
endfunc

func find_next() ; work in progress
    local $find_text = guictrlread($find_box)
    if $find_text = '' then return
    local $current_sel = _guictrlrichedit_getsel($edit)[1]
    local $selection = _guictrlrichedit_findtextinrange($edit, $find_text, $current_sel, Default, $toggle_case, $toggle_word)
    if _guictrlrichedit_getsel($edit)[0] = $current_sel then
        $selection = _guictrlrichedit_findtextinrange($edit, $find_text, 0, Default, $toggle_case, $toggle_word)
    endif
    if isarray($selection) then
        _guictrlrichedit_setsel($edit, $selection[0], $selection[1])
    endif
endfunc

func replace() ; work in progress
    local $replace_text = guictrlread($replace_box)
    if $replace_text = '' then return
    _guictrlrichedit_replacetext($edit, $replace_text)
    find()
endfunc

func replace_all() ; work in progress
    local $find_text = guictrlread($find_box)
    local $replace_text = guictrlread($replace_box)
    if $find_text = '' then return
    _guictrlrichedit_setsel($edit, 0, 0)
    local $selection
    do
        $selection = _guictrlrichedit_findtext($edit, $find_text, True, $toggle_case, $toggle_word)
        if $selection = -1 then exitloop

        _guictrlrichedit_setsel($edit, $selection, $selection + stringlen($find_text))
        _guictrlrichedit_replacetext($edit, $replace_text)
    until false
endfunc

#Region scrollbar

    $scroll_drag = False ; are we dragging the scroll button?

    Func check_scroll_clicked() ; always sets $scroll_cursor variable
        Local $scroll_cursor = GUIGetCursorInfo($form)
        If _
            $scroll_cursor[0] >= 300 And _
            $scroll_cursor[0] <= 310 And _
            $scroll_cursor[1] >= 60 And _
            $scroll_cursor[1] <= 369 _
        Then $scroll_drag = True
    EndFunc

    Func scroll() ; label : 300, 60, 10, 20 bar: 300, 60, 10, 310 lies visible: around 28
        Local $scroll_x = 300 ; x of $scroll control at all times
        Local $scroll_min_y = 60, $scroll_max_y = 350 ; range of y movement for $scroll (top of frame till bottom - height)

        $scroll_cursor = GUIGetCursorInfo($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($scroll, $scroll_x, $scroll_cursor) ; drag scroll button within range of background bar

        $scroll_ratio = ($scroll_cursor - $scroll_min_y) / ($scroll_max_y - $scroll_min_y) ; calculate scroll position percentage between 0 and 1
        $scroll_last = _GUICtrlRichEdit_GetLineCount($Edit)

        If $scroll_last > 27 then $scroll_last -= 25 ; scroll to end but not over end
        $scroll_first = _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($edit)

        $scroll_calculate = Int($scroll_ratio * $scroll_last) - $scroll_first ; calculate where to walk to

        consolewrite(_GUICtrlRichEdit_GetLineCount($Edit) & '---' & $scroll_calculate & '---' & $scroll_ratio & @CRLF)
        _GUICtrlRichEdit_ScrollLines($edit, $scroll_calculate)
    EndFunc

#endregion

while 1
    switch guigetmsg()
        case $gui_event_close, $button_exit
            quit()

        case $GUI_EVENT_PRIMARYDOWN
            check_scroll_clicked()

        Case $GUI_EVENT_MOUSEMOVE
            If $scroll_drag Then scroll()

        Case $GUI_EVENT_PRIMARYUP
            $scroll_drag = False

        case $button_open
            open()

        case $button_save
            if _guictrlrichedit_ismodified($edit) then
                save() ; only overwrite when needed
                soundplay($sound_click)
            endif

        case $button_bold
            stylize('bo')

        case $button_italic
            stylize('it')

        case $button_struck
            stylize('st')

        case $button_under
            stylize('un')

        case $button_red
            colorize($color_edit_red)

        case $button_green
            colorize($color_edit_green)

        case $button_blue
            colorize($color_edit_blue)

        case $button_white
            colorize($color_edit_white)

        case $button_default
            colorize($color_edit_gray)
            ; _guictrlrichedit_setcharattributes($edit, '-bo-it-un-st')

        Case $button_search
            soundplay($sound_click)
            GUICtrlSetData($find_box, _GUICtrlRichEdit_GetSelText($edit))
            guisetstate(@SW_SHOW, $search)

        Case $checkbox_case
            $toggle_case = not $toggle_case
            GUICtrlSetImage($checkbox_case, $toggle_case ? $image_case_on : $image_case_off)
            soundplay($sound_click)

        Case $checkbox_word
            $toggle_word = not $toggle_word
            GUICtrlSetImage($checkbox_word, $toggle_word ? $image_word_on : $image_word_off)
            soundplay($sound_click)

        Case $button_find
            find()

        Case $button_next
            find_next()

        Case $button_replace
            replace()

        Case $button_all
            replace_all()

        Case $button_close
            soundplay($sound_click)
            GUISetState(@SW_HIDE, $search)

    endswitch
wend

And here is the code for the installer:

#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 3.zip

Edited by TheAutomator
added installer
Posted (edited)

It's usually called "Strike(through)", not "Stripe", and maybe put an Underline under the characters in the bmp's that can be ctrl'ed, and maybe put a lowercase "u" in front of "uLine".

It looks nice, havent tried it though, cant be bothered installing fonts nor compile it as exe. :)

Btw, please put all the files in a folder before zipping, so people dont have to create a folder in their examples scripts folder themselfes.

Edited by Werty

Some guy's script + some other guy's script = my script!

Posted
7 hours ago, Werty said:

It's usually called "Strike(through)", not "Stripe", and maybe put an Underline under the characters in the bmp's that can be ctrl'ed, and maybe put a lowercase "u" in front of "uLine".

It looks nice, havent tried it though, cant be bothered installing fonts nor compile it as exe. :)

Btw, please put all the files in a folder before zipping, so people dont have to create a folder in their examples scripts folder themselfes.

Good advice!
Made some adjustments :)

btw, you can run the script as is (no compiling needed for that) if you wanna test it out, it just opens the helpfile with no arguments as you can see in the picture.

Posted (edited)

UPDATE:

  1. code cleanup
  2. added minimalistic sci-fi sounds
  3. better text on buttons and they have labels now
  4. better shortcuts
  5. open and save buttons now work as intended
  6. helpfile got an update
  7. code can be tested when not compiled
  8. removed a bug

Enjoy and let me know what you think :)

PS:

If anyone knows how to make the edit scroll up / down when I use the mouse to scroll, let me know.
I looked at this topic, but have no clue what to make of the code:

 

 

 

Edited by TheAutomator
Posted
17 hours ago, TheAutomator said:

If anyone knows how to make the edit scroll up / down when I use the mouse to scroll, let me know.

Does this work for you ?

_GUICtrlRichEdit_SetEventMask($edit, BitOR($ENM_SCROLL, $ENM_SCROLLEVENTS))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

...

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd($tNMHDR.hWndFrom)
    $iCode = $tNMHDR.Code
    Switch $hWndFrom
        Case $edit
            Select
                Case $iCode = $EN_MSGFILTER
                    Local $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam)
                    Switch $tMsgFilter.msg
                        Case $WM_VSCROLL
                            _GUICtrlRichEdit_ScrollLines($edit, ($tMsgFilter.wparam = 1 ? 1 : -1))
                    EndSwitch
            EndSelect
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

"I think you are searching a bug where there is no bug..."

Posted (edited)

Pixelsearch,

6 hours ago, pixelsearch said:

Does this work for you ?

_GUICtrlRichEdit_SetEventMask($edit, BitOR($ENM_SCROLL, $ENM_SCROLLEVENTS))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

...

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd($tNMHDR.hWndFrom)
    $iCode = $tNMHDR.Code
    Switch $hWndFrom
        Case $edit
            Select
                Case $iCode = $EN_MSGFILTER
                    Local $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam)
                    Switch $tMsgFilter.msg
                        Case $WM_VSCROLL
                            _GUICtrlRichEdit_ScrollLines($edit, ($tMsgFilter.wparam = 1 ? 1 : -1))
                    EndSwitch
            EndSelect
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Nice! You made my day! :D

The code you provided worked like a charm, but did raise some questions (if you don't mind replying to them).

1: why the #forcref, is it needed in this code?
2: why using 'switch' and 'select' if we can simply use 'if'?

The version i'm gonna put in the project:

_guictrlrichedit_seteventmask($edit, bitor($enm_scroll, $enm_scrollevents))

guiregistermsg($wm_notify, "wm_notify")

func wm_notify($hwnd, $imsg, $wparam, $lparam) ; make scrolling in the edit possible (thanks pixelsearch!)
    local $tnmhdr, $hwndfrom, $icode
    $tnmhdr = dllstructcreate($tagnmhdr, $lparam)
    $hwndfrom = hwnd($tnmhdr.hwndfrom)
    $icode = $tnmhdr.code
    if $hwndfrom = $edit then
        if $icode = $en_msgfilter then
            local $tmsgfilter = dllstructcreate($tagmsgfilter, $lparam)
            if $tmsgfilter.msg = $wm_vscroll then _guictrlrichedit_scrolllines($edit, ($tmsgfilter.wparam = 1 ? 1 : -1))
        endif
    endif
    return $gui_rundefmsg
endfunc

Thanks for the help!
Figuring out how to correctly do more advanced specific stuff, like finding the right parameters, using dllstructs and worrying about not using code correctly can be dificult at times :sweating:

MiniMark (now version 2) is uploaded.
 

Edited by TheAutomator
Posted

@TheAutomator glad it helped you.

By the way, as you don't want to add scrollbars (in your richedit control styles) then you can simplify the mask, keeping only $ENM_SCROLLEVENTS to take care of notifications for mouse wheel events :

; _GUICtrlRichEdit_SetEventMask($edit, BitOR($ENM_SCROLL, $ENM_SCROLLEVENTS))
_GUICtrlRichEdit_SetEventMask($edit, $ENM_SCROLLEVENTS)

 

Just now, TheAutomator said:

1: why the #forcref, is it needed in this code?

You'll find the answer in this thread and also in that one

Just now, TheAutomator said:

2: why using 'switch' and 'select' if we can simply use 'if'?

No problem. If you prefer to code with 'if' it will give the same result :)

"I think you are searching a bug where there is no bug..."

Posted

In fact if you set the mask to only scroll events :

_GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_SCROLLEVENTS)

then the WM_NOTIFY message proc can be as simple as :

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  Local $tFilter = DllStructCreate($tagMSGFILTER, $lParam)
  If $tFilter.hwndFrom = $hRichEdit Then _GUICtrlRichEdit_ScrollLines($tFilter.hwndFrom, $tFilter.wParam ? 1 : -1)
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Posted
9 hours ago, Nine said:

In fact if you set the mask to only scroll events :

_GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_SCROLLEVENTS)

then the WM_NOTIFY message proc can be as simple as :

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  Local $tFilter = DllStructCreate($tagMSGFILTER, $lParam)
  If $tFilter.hwndFrom = $hRichEdit Then _GUICtrlRichEdit_ScrollLines($tFilter.hwndFrom, $tFilter.wParam ? 1 : -1)
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Perfect! Love it! :D Thank you so much!
Gonna put it like that inside of the code now :)

Posted
28 minutes ago, TheAutomator said:

Next task:

Spoiler
const $source_path = @ScriptDir & '\minimark'
Const $image_background = $source_path & '\gui.bmp'
Const $image_blue = $source_path & '\blue.bmp'
Const $image_bold = $source_path & '\bold.bmp'
Const $image_default = $source_path & '\default.bmp'
Const $image_exit = $source_path & '\exit.bmp'
Const $image_green = $source_path & '\green.bmp'
Const $image_italic = $source_path & '\italic.bmp'
Const $image_open = $source_path & '\open.bmp'
Const $image_red = $source_path & '\red.bmp'
Const $image_save = $source_path & '\save.bmp'
Const $image_struck = $source_path & '\struck.bmp'
Const $image_under = $source_path & '\under.bmp'
Const $image_white = $source_path & '\white.bmp'

Const $sound_start = $source_path & '\start.wav'
Const $sound_click = $source_path & '\click.wav'
Const $sound_alert = $source_path & '\alert.wav'
Const $sound_stop = $source_path & '\stop.wav'

Const $color_gui_transparant = 0xff00ff
Const $color_title = 0x999999
Const $color_edit_background = 0x00323232
Const $color_edit_gray = 0x00b4b4b4
Const $color_edit_red = 0x006600ff
Const $color_edit_green = 0x0000ff66
Const $color_edit_blue = 0x00ff6600
Const $color_edit_white = 0x00ffffff

Const $file_manual = $source_path & '\minimark.mnm'

..fix the new paths in MiniMark.au3 :lol:

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

argumentum,

Can you tell me why making an extra variable would be better? Does @scriptdir slow the script down when used a lot? :think:

1 hour ago, argumentum said:

Request: Portable version, script version, and user level install too ( for office workers ).

PS: there is code in the help file ( I if memory serves, else, the forum ) to load the font without installing it first, from file or resource.

About the request for the fonts, you mean this right?
https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_AddFontResourceEx.htm

I'm not sure if temporary installing the font every time the script get's opened is a good idea, as shown in the link it installs the font only for the current session but still installs it... I need to reseach it a little more to be sure tho.

Script version is already possible if you mean running it uncompiled?

And user level install means commenting out this line from the installer I suppose:

#RequireAdmin

Compiling MiniMark to an exe and leaving the sounds, images and help file with it technically makes it portable.
Using fileinstall is also an option, do you have a preference?
If you mean working with embedded resources, well thats new for me, I might make mistakes but i'll give it a try.

Edited by TheAutomator
Posted (edited)
4 hours ago, TheAutomator said:

Compiling MiniMark to an exe and leaving the sounds, images and help file with it technically makes it portable.

#autoit3wrapper_icon=setup\setup.ico, 201
... ...
DllCall('shell32.dll', 'long', 'SetCurrentProcessExplicitAppUserModelID', 'wstr', StringStripWS(@ScriptName, 8)) ; look at _WinAPI_SetCurrentProcessExplicitAppUserModelID()
$form = GUICreate('MiniMark Setup', 300, 300, Default, Default, $ws_popup, $ws_ex_layered)
Gui_SetIconIf("setup\icon.ico", 201)
Func Gui_SetIconIf($sIconFile, $iIconID)
    If @AutoItExe = @ScriptFullPath And Not FileGetSize($sIconFile) Then
        GUISetIcon(@AutoItExe, $iIconID)
    Else
        GUISetIcon($sIconFile)
    EndIf
EndFunc   ;==>Gui_SetIconIf

That function I use in one of my scripts where if compiled uses the internal Icon, else, use the file but if is there, maybe the user wanted a different one so use the one on disk.

 Similarly you can keep all the files on disk or embed it in the executable, or both as described above. 

4 hours ago, TheAutomator said:

And user level install means commenting out this line from the installer I suppose:

It would take installing to where a user can modify anything that a non-admin could. @AppDataDir could be a good folder as @ProgramFilesDir requires admin level.
In cv.exe there is code to elevate and de-elevate. You can use that or scrape the forum for the original sources. That would give the user the option to install as admin or user.

4 hours ago, TheAutomator said:

Can you tell me why making an extra variable would be better? Does @scriptdir slow the script down when used a lot? :think:

Oh, that. I wanted to edit as little as possible and, have what I wanted, hence the extra variable. As is from the download, it didn't run.

4 hours ago, TheAutomator said:

Script version is already possible if you mean running it uncompiled?

Yes it is. The reason for my requests is to have a nice product that would please as many users as possible, in as many circumstances as there may be.
Maybe 10 users will use your script as a product, or a million, no clue. But if your script is an example of how to code something, better :)

These requests are perfectly doable. Is just a matter of coding it that way, if is not too far from what you had in mind.

5 hours ago, TheAutomator said:

Next task: adding a find/replace window.

Along those lines of expanding capabilities, making the GUI resizable would be nice.

Resize the font too ( for those that need bigger letters because they don't see very well ).
"Zoom in / out: ctrl + scroll" with memory, for the next time is loaded.

One feature at the time is good.

Thanks for paying attention to my demands requests :) 

Edited by argumentum
English

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

argumentum,

I added it to the example scripts to share it with users who like this kind of software, and to show others how to use the rich edit control and create custom GUIs. 🙂

The goal is to have a minimalistic RTF editor with files that have custom icons and open directly with MiniMark. Personally, I use it as a quick notes app for all kinds of lists (to-dos, series to binge, things to buy...) that I can just double-click and edit when needed. I'm not planning to tweak the icons, style, or add a huge amount of options becouse that would make it "maximalistic" :mellow:.

That being said, allowing users to choose the installation location is a great idea and will be added soon! Keep in mind that the software is designed to be compiled and installed (custom icons, fonts, and right-click menu entries). Making it portable would mean users have to manually open or drag icon-less files into the executable, which isn’t very convenient..

For testing the script as is please check the README: drag MiniMark.au3 into the MiniMark folder so it can access its files properly, then it should work.

I'm doing my best to make it work as smooth as possible in my free time, but this is an open-source project in a forum full of developers who can tweak it to their liking. That doesn’t mean I’m ignoring requests, I gladly accept help with code and small handy improvements for those who want to contribute!

It’s all about finding the right balance between keeping it light but good. An update is coming soon, so let’s see what I can do. 😃

Edited by TheAutomator
a few typos removed
Posted (edited)

MiniMark 3 is here!

Now we have:

  • a custom (still buggy) scrollbar
  • a search window to find and replace text (ctrl+f -> should also make a button for it that)
  • installer is a little smaller

Upcoming:

  • user level install option (as deman... I mean, requested by argumentum) ;)
  • a settings window, and writing an INI file to remember some settings (like enabeling sounds or the last zoom amount)

Making the gui resizable is not as easy as it seems, I tried to do that in the past with a custom gui and got very frustrated when using a borderles window that could get maximized by hitting the top of the screen but not register as maximized for example... We'll see :)

Readers of this post, I kindly request your help!

Please have a look at the custom scrollbar, and let me know if there is a way to scroll the rich edit to a specific line without moving the caret or changing the selection of the edit control, that's what i'm trying to do but the code is a little dirty. :huh2:

#Region scrollbar

    $scroll_drag = False ; are we dragging the scroll button?

    Func check_scroll_clicked() ; always sets $scroll_cursor variable
        Local $scroll_cursor = GUIGetCursorInfo($form)
        If _
            $scroll_cursor[0] >= 300 And _
            $scroll_cursor[0] <= 310 And _
            $scroll_cursor[1] >= 60 And _
            $scroll_cursor[1] <= 369 _
        Then $scroll_drag = True
    EndFunc

    Func scroll() ; label : 300, 60, 10, 20 bar: 300, 60, 10, 310 lies visible: around 28
        Local $scroll_x = 300 ; x of $scroll control at all times
        Local $scroll_min_y = 60, $scroll_max_y = 350 ; range of y movement for $scroll (top of frame till bottom - height)

        $scroll_cursor = GUIGetCursorInfo($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($scroll, $scroll_x, $scroll_cursor) ; drag scroll button within range of background bar

        $scroll_ratio = ($scroll_cursor - $scroll_min_y) / ($scroll_max_y - $scroll_min_y) ; calculate scroll position percentage between 0 and 1
        $scroll_last = _GUICtrlRichEdit_GetLineCount($Edit)

        If $scroll_last > 27 then $scroll_last -= 25 ; scroll to end but not over end
        $scroll_first = _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($edit)

        $scroll_calculate = Int($scroll_ratio * $scroll_last) - $scroll_first ; calculate where to walk to

        consolewrite(_GUICtrlRichEdit_GetLineCount($Edit) & '---' & $scroll_calculate & '---' & $scroll_ratio & @CRLF)
        _GUICtrlRichEdit_ScrollLines($edit, $scroll_calculate)
    EndFunc

#endregion

while 1
    switch guigetmsg()
        case $gui_event_close, $button_exit
            quit()

        case $GUI_EVENT_PRIMARYDOWN
            check_scroll_clicked()

        Case $GUI_EVENT_MOUSEMOVE
            If $scroll_drag Then scroll()

        Case $GUI_EVENT_PRIMARYUP
            $scroll_drag = False
            
            ...

Thanks to everyone that contributed, liked and suported this project!
See you soon with updates and replys :D

Edited by TheAutomator

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...