Jump to content

Search the Community

Showing results for tags 'rtf'.

  • 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 6 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 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
  2. First I want to thanks to RoyGlanfield for : Printing RichEdit A long time ago I was wondering how to print RTF files in the background. I just used to use this solution: ShellExecuteWait($sRTF_FileFullPath, '', '', 'print') Unfortunately, it is slow and is not done, in the background. A few days ago I was looking for a solution through google. I found a solution at home and exactly here. I modified it a little, and behold, here it is: #include-once #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #Tidy_Parameters=/sort_funcs /reel #Region RTF PRINTER Include# #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <SendMessage.au3> #include <Array.au3> #EndRegion RTF PRINTER Include# #Region RTF PRINTER HEADER# ; #INDEX# ======================================================================================================================= ; Title .........: UDF for Printing RTF files ; AutoIt Version : 3.3.10.2++ ; Language ......: English ; Description ...: UDF for Printing RTF files ; Author(s) .....: mLipok, RoyGlanfield ; Modified ......: ; =============================================================================================================================== #cs Title: UDF for Printing RTF files Filename: RTF_Printer.au3 Description: UDF for Printing RTF files Author: RoyGlanfield, mLipok Modified: Last Update: 2014/06/15 Requirements: AutoIt 3.3.10.2 or higher http://www.autoitscript.com/forum/topic/127580-printing-richedit/ http://www.autoitscript.com/forum/topic/161831-rtf-printer-printing-richedit/ Update History: =================================================== 2014/06/04 v0.1 First official version 2014/06/04 v0.2 * Global Variable renaming by adding $__ * extended $__API_RTF_Printer * new function: _RTF_SetMargins($vMarginLeft = 1, $vMarginTop = 1, $vMarginRight = 1, $vMarginBottom = 1) * new function: _RTF_SetNumberOfCopies($iNumberOfCopies = 1) * added #Region RTF PRINTER initialization# * CleanUp * added #forceref * added #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 2014/06/12 v0.3 * Global Variable Renaming add 'RTF' to variable names and added $__ to be sure that no one else used the name * Global Variable renaming $aPageInfo to $__aRTFPageInfo to be sure that no one else used the name * variable renaming $hInput* to $iCtrlInput* * in _RTF_PrintFile() new parameter $fAddIndex * Setting RTF_Printer Window Title * fix problem with printing more than 16 RTF files >> GUIDelete($__API_RTF_Printer[$__hRTF_Gui]) * new internal function __RTF_AddLeadingZeros * added some more comments * brand new RTF_Printer_Examples.au3 2014/06/15 v0.4 * $sRTF_FileFullPath_or_Stream - A string value. Full path to the RTF file to be printed or Stream Data from _GUICtrlRichEdit_StreamToVar * Now you can create documents in RichEdit and print them without the need to save the RTF file. * You can also download the documents from the database and print them without having to save them to disk as RTF files. * new RTF_Printer_Examples.au3 * new #Region MSDN Links , Help, Doc * some minior variable renaming #CE #EndRegion RTF PRINTER HEADER# #Region RTF PRINTER Constants# ; #CONSTANTS# =================================================================================================================== ; $__<UDF>_CONSTANT_<NAME> Global Const $__PDtags = "align 1 ;DWORD lStructSize;" & _ "HWND hwndOwner;" & _ "handle hDevMode;" & _ "handle hDevNames;" & _ "handle hDC;" & _ "DWORD Flags;" & _ "WORD nFromPage;" & _ "WORD nToPage;" & _ "WORD nMinPage;" & _ "WORD nMaxPage;" & _ "WORD nCopies;" & _ "handle hInstance;" & _ "LPARAM lCustData;" & _ "ptr lpfnPrintHook;" & _ "ptr lpfnSetupHook;" & _ "ptr lpPrintTemplateName;" & _ "ptr lpSetupTemplateName;" & _ "handle hPrintTemplate;" & _ "handle hSetupTemplate" Global Enum _ $__hRTF_dcc, _ $__hRTF_Gui, $__hRichEditE, $__hRTF_RichEditPre, _ $__iRTFLabelPagegNow, $__iRTFLabelPagesTotal, _ $__vRTFMarginTop, $__vRTFMarginLeft, $__vRTFMarginRight, $__vRTFMarginBottom, _ $__iRTFNumberOfCopies, _ $__API_RTF_Printer_Count ; , $tDefaultPrinter, _ #EndRegion RTF PRINTER Constants# #Region RTF PRINTER Global Variables# Global $__API_RTF_Printer[$__API_RTF_Printer_Count] Global $__aRTFPageInfo[2]; $__aRTFPageInfo[0]= total num of pages $__aRTFPageInfo[1.....] = 1st char number of each page #EndRegion RTF PRINTER Global Variables# #Region RTF PRINTER initialization# _RTF_SetMargins() _RTF_SetNumberOfCopies() #EndRegion RTF PRINTER initialization# #Region RTF PRINTER CURRENT# ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_PrintFile ; Description ...: Print Selected File in the background or with custom window dialog ; Syntax ........: _RTF_PrintFile($sRTF_FileFullPath_or_Stream[, $sDocTitle = Default[, $fPrintNow = True[, $fAddIndex = False]]]) ; Parameters ....: $sRTF_FileFullPath_or_Stream - A string value. Full path to the RTF file to be printed or Stream Data from _GUICtrlRichEdit_StreamToVar ; $sDocTitle - [optional] A string value. Default is Default. If Default then $sDocTitle = FileName ; $fPrintNow - [optional] A boolean value. Default is True. If true then printing is running in the background. ; $fAddIndex - [optional] A boolean value. Default is False. If true then add Indexing to Document Name in spooler ; Return values .: None ; TODO ; Author ........: mLipok, RoyGlanfield ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/161831-rtf-printer-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func _RTF_PrintFile($sRTF_FileFullPath_or_Stream, $sDocTitle = Default, $fPrintNow = True, $fAddIndex = False) Static $__iRTF_Printer_Counter If $__iRTF_Printer_Counter = '' Then $__iRTF_Printer_Counter = 1 ; chcecking if Streamed Data insteed FileFullPath If StringLeft($sRTF_FileFullPath_or_Stream, 5) = '{\rtf' Then If $sDocTitle = Default Then $sDocTitle = 'RichEdit Data' EndIf Else If Not FileExists($sRTF_FileFullPath_or_Stream) Then Return -1 ; setting DocTitle (document Name in spooler) - if Default then FileName If $sDocTitle = Default Then $sDocTitle = StringRegExp($sRTF_FileFullPath_or_Stream, '(?i).+\\(.+)', 3)[0] EndIf EndIf ; adding index (as prefix) to the DocTitle (document Name in spooler) If $fAddIndex Then $sDocTitle = __RTF_AddLeadingZeros(String($__iRTF_Printer_Counter), 5) & '_' & $sDocTitle EndIf Local $hPrintDc = '' #forceref $hPrintDc Local $__aRTFPageInfo[2]; $__aRTFPageInfo[0]= total num of pages $__aRTFPageInfo[1.....] = 1st char number of each page Local $iPageInPreview = 1 ; the Page Now on show in the preview ; Printer dialog tags Local $tDefaultPrinter = __GetDefaultPrinter() ; Setting RTF_Printer Window Title Local $sRTF_Printer_Title = 'Print RTF ---- ' & $tDefaultPrinter $sRTF_Printer_Title = '[' & String($__iRTF_Printer_Counter) & '] ' & $sRTF_Printer_Title $__API_RTF_Printer[$__hRTF_Gui] = GUICreate($sRTF_Printer_Title, 430, 580, -1, -1) ; Control whose contents is to be printed--------MUST be RichEdit. ; any size will do---- has no effect on the printed copy $__API_RTF_Printer[$__hRichEditE] = _GUICtrlRichEdit_Create($__API_RTF_Printer[$__hRTF_Gui], "", 10, 50, 400, 124, $ES_MULTILINE + $WS_VSCROLL) ;+ $ES_AUTOVSCROLL) ; 21000 push the preview control off the page ; to be resized and positioned after paper size and orientation has been chosen [print dialog or default] $__API_RTF_Printer[$__hRTF_RichEditPre] = _GUICtrlRichEdit_Create($__API_RTF_Printer[$__hRTF_Gui], "", 21000, 10, 10, 10, $ES_MULTILINE) ;+ $ES_AUTOVSCROLL) $__API_RTF_Printer[$__iRTFLabelPagegNow] = GUICtrlCreateLabel("0", 60, 180, 40, 20, $SS_RIGHT) GUICtrlCreateLabel(" of ", 100, 180, 20, 20, $SS_Center) $__API_RTF_Printer[$__iRTFLabelPagesTotal] = GUICtrlCreateLabel("0", 120, 180, 40, 20, $SS_Left) Local $iButtonBack = GUICtrlCreateButton("Back", 160, 180, 50, 20) Local $iButtonNext = GUICtrlCreateButton("Next", 210, 180, 50, 20) Local $iButtonPrintNow = GUICtrlCreateButton("PrintNow", 280, 180, 100, 20) Local $EndPage = '' #forceref $EndPage GUICtrlCreateLabel('Margins-->', 0, 3, 50, 20) GUICtrlCreateLabel(' cm--->', 0, 30, 40, 20) GUICtrlCreateLabel('Left', 50, 3, 30, 15) GUICtrlCreateLabel('Top', 80, 3, 40, 15) GUICtrlCreateLabel('Right', 120, 3, 40, 15) GUICtrlCreateLabel('Bottom', 160, 3, 40, 15) GUICtrlCreateLabel('Copies', 230, 3, 40, 15) Local $iCtrlInputMarginLeft = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginLeft], 40, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginTop = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginTop], 80, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginRight = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginRight], 120, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginBottom = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginBottom], 160, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputNumberOfCopies = GUICtrlCreateInput($__API_RTF_Printer[$__iRTFNumberOfCopies], 230, 25, 40, 20) Local $iButtonPrint = GUICtrlCreateButton("Print", 280, 5, 55, 20) Local $iButtonPrintGeneral = GUICtrlCreateButton("General", 280, 25, 60, 20) Local $iButtonPrintSetup = GUICtrlCreateButton("Print Setup", 335, 5, 75, 20) Local $iButtonNoDialog = GUICtrlCreateButton("No dialog", 340, 25, 70, 20) ; chcecking if Streamed Data insteed FileFullPath If StringLeft($sRTF_FileFullPath_or_Stream, 5) = '{\rtf' Then _GUICtrlRichEdit_StreamFromVar($__API_RTF_Printer[$__hRichEditE], $sRTF_FileFullPath_or_Stream) Else _GUICtrlRichEdit_StreamFromFile($__API_RTF_Printer[$__hRichEditE], $sRTF_FileFullPath_or_Stream) EndIf ; TrayTip('_GUICtrlRichEdit_StreamFromFile',@error,4) ; for test only If $fPrintNow = False Then GUISetState() EndIf ; this does not work ---$r = _GUICtrlRichEdit_SetZoom($__API_RTF_Printer[$__hRichEditE], 1/2)-------------- ; Below works well---but does have to be reset after anything is streamed in------ ; OK--------$r = _SendMessage($h_RichEdit, $EM_SETZOOM, $tDefaultPrinterominator, $denominator) ; $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 1000, 2333) ; must be integer -- "1000, 2333" not "1, 2.333" ; $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 100, 200) ; eg 50% Local $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 100, 300) ; eg 33.3333333333% #forceref $r ; $r = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETZOOM, 100, 500) ; eg 20% Local $z Local $iMsg If $fPrintNow Then ; NO DIALOG ; $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) ; not needed as only prints 1copy ; "No dialog" ---No choices ; prints 1 copy using the default printer's settings $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterNoDialog() If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) EndIf ; PRINT NOW ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then __RTF_Print($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $sDocTitle, $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) $__iRTF_Printer_Counter += 1 Else EndIf $hPrintDc = '' ; GUISetState() ; for test only ; Sleep(3000) ; for test only Else While 1 Sleep(10) $__API_RTF_Printer[$__vRTFMarginLeft] = GUICtrlRead($iCtrlInputMarginLeft) $__API_RTF_Printer[$__vRTFMarginTop] = GUICtrlRead($iCtrlInputMarginTop) $__API_RTF_Printer[$__vRTFMarginRight] = GUICtrlRead($iCtrlInputMarginRight) $__API_RTF_Printer[$__vRTFMarginBottom] = GUICtrlRead($iCtrlInputMarginBottom) $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE GUIDelete() Exit Case $iMsg = $iButtonNoDialog; "No dialog" ; $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) ; not needed as only prints 1copy ; "No dialog" ---No choices ; prints 1 copy ; using the default printer's settings $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterNoDialog() If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintSetup; "PrintSetup" ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterSetup($__API_RTF_Printer[$__iRTFNumberOfCopies]) ; OK-- If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrint; "Print" ; "Print" ---choices-- ; number of copies ; Page range---All, from, to, Selection ; NO-- portrait/landscape choice $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_Printer($__API_RTF_Printer[$__iRTFNumberOfCopies]) ; OK--"Print" dialog If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintGeneral; "General" ; "General" ---choices-- ; number of copies ; Page range---All, Selection ; NO-- portrait/landscape choice----------- $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterGeneral($__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__iRTFNumberOfCopies]) If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintNow; ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then MsgBox(4096, '', __RTF_Print($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $sDocTitle, $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom])) Else EndIf $hPrintDc = '' Case $iMsg = $iButtonNext; If $iPageInPreview < $__aRTFPageInfo[0] Then $iPageInPreview += 1 __NextPage($iPageInPreview) EndIf Case $iMsg = $iButtonBack ; If $iPageInPreview > 1 Then $iPageInPreview -= 1 __NextPage($iPageInPreview) EndIf EndSelect WEnd EndIf ; CleanUp If IsHWnd($__API_RTF_Printer[$__hRTF_Gui]) Then GUIDelete($__API_RTF_Printer[$__hRTF_Gui]) EndFunc ;==>_RTF_PrintFile ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_SetMargins ; Description ...: Set Margins size in cm [centimeters] ; Syntax ........: _RTF_SetMargins([$vMarginLeft = 1[, $vMarginTop = 1[, $vMarginRight = 1[, $vMarginBottom = 1]]]]) ; Parameters ....: $vMarginLeft - [optional] A variant value. Default is 1. ; $vMarginTop - [optional] A variant value. Default is 1. ; $vMarginRight - [optional] A variant value. Default is 1. ; $vMarginBottom - [optional] A variant value. Default is 1. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _RTF_SetMargins($vMarginLeft = 1, $vMarginTop = 1, $vMarginRight = 1, $vMarginBottom = 1) $__API_RTF_Printer[$__vRTFMarginLeft] = $vMarginLeft ; initial minimum Left margin $__API_RTF_Printer[$__vRTFMarginTop] = $vMarginTop ; initial minimum Top margin $__API_RTF_Printer[$__vRTFMarginRight] = $vMarginRight ; initial minimum Right margin $__API_RTF_Printer[$__vRTFMarginBottom] = $vMarginBottom ; initial minimum Bottom margin EndFunc ;==>_RTF_SetMargins ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_SetNumberOfCopies ; Description ...: Set number of copies ; Syntax ........: _RTF_SetNumberOfCopies([$iNumberOfCopies = 1]) ; Parameters ....: $iNumberOfCopies - [optional] An integer value. Default is 1. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _RTF_SetNumberOfCopies($iNumberOfCopies = 1) $__API_RTF_Printer[$__iRTFNumberOfCopies] = $iNumberOfCopies ; initial number of Copies to print EndFunc ;==>_RTF_SetNumberOfCopies #EndRegion RTF PRINTER CURRENT# #Region RTF PRINTER INTERNAL# ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterSetup ; Description ...: Get the device context of a "PrinterSetup" Dialog box ; Syntax ........: __GetDC_PrinterSetup([$iCopies = 1]) ; Parameters ....: $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- portrait/landscape, printer, paper size ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterSetup($iCopies = 1) Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Constants--$PD_RETURNDC = 0x100----$PD_PRINTSETUP = 0x40 DllStructSetData($strcPD, "Flags", 0x100 + 0x40) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies ; DllStructSetData($strcPD,"nFromPage", 1) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterSetup ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_Printer ; Description ...: Get the device context of a "Print" Dialog box ; Syntax ........: __GetDC_Printer([$iCopies = 1]) ; Parameters ....: $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- many, but no portrait/landscape ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_Printer($iCopies = 1) Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Constant--$PD_RETURNDC = 0x100 DllStructSetData($strcPD, "Flags", 0x100) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies DllStructSetData($strcPD, "nFromPage", 1) ; start from page # DllStructSetData($strcPD, "nToPage", 0xFFFF) DllStructSetData($strcPD, "nMinPage", 1) DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_Printer ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterNoDialog ; Description ...: Get the device context of the default printer ; Syntax ........: __GetDC_PrinterNoDialog() ; Parameters ....: ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Uses the default printers settings ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterNoDialog() Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Const--RETURNDEFAULT = 0x400---RETURNDC = 0x100----PRINTSETUP = 0x40 DllStructSetData($strcPD, "Flags", 0x100 + 0x40 + 0x400) ; different flags open different dialogue boxes ; DllStructSetData($strcPD, "nCopies", $iCopies) ; only set this if a dialog is shown ; DllStructSetData($strcPD,"nFromPage", 1) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterNoDialog ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterGeneral ; Description ...: Get the device context of a "PrinterSetup General tab" Dialog box ; Syntax ........: __GetDC_PrinterGeneral($hRichEditCtrl[, $iCopies = 1]) ; Parameters ....: $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- many, but no portrait/landscape ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterGeneral($hRichEditCtrl, $iCopies = 1) ; Printer Setup, general options---NO landscape! Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) DllStructSetData($strcPD, "hwndOwner", $hRichEditCtrl) ; ; Constant--$PD_RETURNDC = 0x100 DllStructSetData($strcPD, "Flags", 0x100) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies ; DllStructSetData($strcPD,"nFromPage", 10) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterGeneral ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDefaultPrinter ; Description ...: Get default printer dialog tags ; Syntax ........: __GetDefaultPrinter() ; Parameters ....: ; Return values .: Printer dialog tags ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDefaultPrinter() Local $tags1 = DllStructCreate("dword") DllCall("winspool.drv", "int", "GetDefaultPrinter", "str", '', "ptr", DllStructGetPtr($tags1)) Local $tags2 = DllStructCreate("char[" & DllStructGetData($tags1, 1) & "]") DllCall("winspool.drv", "int", "GetDefaultPrinter", "ptr", DllStructGetPtr($tags2), "ptr", DllStructGetPtr($tags1)) Return DllStructGetData($tags2, 1) EndFunc ;==>__GetDefaultPrinter ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __NextPage ; Description ...: Show selected page in preview ; Syntax ........: __NextPage($iPageNumber) ; Parameters ....: $iPageNumber - An integer value. ; Return values .: None ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __NextPage($iPageNumber) ; stream into preview all up to the end of the page to show ; _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRichEditE], 0, $__aRTFPageInfo[$iPageNumber + 1] - 1) ; '-1' because $__aRTFPageInfo[$iPageNumber+1] is the 1st char of next page _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRichEditE], 0, $__aRTFPageInfo[$iPageNumber + 1]) ; '-1' because $__aRTFPageInfo[$iPageNumber+1] is the 1st char of next page Local $stream = _GUICtrlRichEdit_StreamToVar($__API_RTF_Printer[$__hRichEditE]) _GUICtrlRichEdit_StreamFromVar($__API_RTF_Printer[$__hRTF_RichEditPre], $stream) _GUICtrlRichEdit_HideSelection($__API_RTF_Printer[$__hRTF_RichEditPre]) ; now delete all before the page to show this way the font size etc. is continued, rather than reverting to the default. _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRTF_RichEditPre], 0, $__aRTFPageInfo[$iPageNumber]) _GUICtrlRichEdit_ReplaceText($__API_RTF_Printer[$__hRTF_RichEditPre], '') Local $r = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETZOOM, 100, 500) ; eg 20% #forceref $r GUICtrlSetData($__API_RTF_Printer[$__iRTFLabelPagegNow], $iPageNumber) EndFunc ;==>__NextPage Func __RTF_AddLeadingZeros($iDigitToExpand, $iNumberOfDigits) Return StringRight("00000000000000000000000000000000000" & String($iDigitToExpand), $iNumberOfDigits) EndFunc ;==>__RTF_AddLeadingZeros ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __RTF_Preview ; Description ...: Show a "Print Preview" from RichEdit control ; Syntax ........: __RTF_Preview($hPrintDc, $hRichEditCtrl[, $LeftMinMargin = 1[, $TopMinMargin = 1[, $RightMinMargin = 1[, $BottomMinMargin = 1]]]]) ; Parameters ....: $hPrintDc - A handle value. Handle of Printer's device context. ; $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $LeftMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the left. ; $TopMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the top. ; $RightMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Right. ; $BottomMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Bottom. ; Return values .: None ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Orientation, paper size, number of copies, and which printer are set when the Printer's device context is generated. ; Unexpected results may be caused by single line/paragaph orphin tags in the rtf. ; The Preview RichEdit Control is resized and zoomed 20% ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __RTF_Preview($hPrintDc, $hRichEditCtrl, $LeftMinMargin = 1, $TopMinMargin = 1, $RightMinMargin = 1, $BottomMinMargin = 1) ; convert the margins 0.1 inches to twips ; $TopMinMarg = $TopMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $LeftMinMarg = $LeftMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $PageMinMarg = $PageMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $BottomMinMarg = $BottomMinMarg * 144; eg 10*144 = 1440 which 1 inch ; convert the margins 1 cm to twips $TopMinMargin = $TopMinMargin * 567; eg 2.539cm * 567= ~1440 which 1 inch $LeftMinMargin = $LeftMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $RightMinMargin = $RightMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $BottomMinMargin = $BottomMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch ; $hPrintDc ; Divice Context handle----------- ; dots per inch depends on the printer quality setting-------X and Y can be different! Local $dotInchX = _WinAPI_GetDeviceCaps($hPrintDc, 88) ; Const LOGPIXELSX = 88 Local $dotInchY = _WinAPI_GetDeviceCaps($hPrintDc, 90) ; Const LOGPIXELSY = 90 ; printer dots per inch ; get the printable area [Page] and paper area [Paper] Local $vPageWidth = _WinAPI_GetDeviceCaps($hPrintDc, 8) ; Const HORZRES= 8 Local $vPageHeight = _WinAPI_GetDeviceCaps($hPrintDc, 10) ; Const VERTRES = 10 Local $vPaperWidth = _WinAPI_GetDeviceCaps($hPrintDc, 110) ; Const PHYSICALWIDTH = 110 Local $vPaperHeight = _WinAPI_GetDeviceCaps($hPrintDc, 111) ; Const PHYSICALHEIGHT = 111 ; none printable margins Local $OffSetX = _WinAPI_GetDeviceCaps($hPrintDc, 112) ; Const PHYSICALOFFSETX = 112 Local $OffSetY = _WinAPI_GetDeviceCaps($hPrintDc, 113) ; Const PHYSICALOFFSETY = 113 Local $vRightMargin = $vPaperWidth - $vPageWidth - $OffSetX Local $vBottomMargin = $vPaperHeight - $vPageHeight - $OffSetY ; conversion factors to use later----------- Local $TwipsInchX = $dotInchX / 1440 ; convert dots to twips [per inch] Local $TwipsInchY = $dotInchY / 1440 ; convert dots to twips [per inch] ; convert all measurments to twips $OffSetX = $OffSetX / $TwipsInchX ; convert Left dots to twips $OffSetY = $OffSetY / $TwipsInchY ; convert Left dots to twips $vPageWidth = $vPageWidth / $TwipsInchX ; convert Right dots to twips $vPageHeight = $vPageHeight / $TwipsInchY ; convert Right dots to twips $vPaperWidth = $vPaperWidth / $TwipsInchX ; convert Paper Width dots to twips $vPaperHeight = $vPaperHeight / $TwipsInchY ; convert Paper Width dots to twips ; Set the margins and keep everything in the printable area Local $Left1 = $LeftMinMargin - $OffSetX If $Left1 < 0 Then $Left1 = 0 ; dont print before printable area starts Local $Top1 = $TopMinMargin - $OffSetY If $Top1 < 0 Then $Top1 = 0 ; dont print before printable area starts Local $Right1 = $RightMinMargin - $vRightMargin If $Right1 < 0 Then $Right1 = 0 ; dont print after printable area ends ; $Right1 = $vPaperWidth - $Right1 - $OffSetX $Right1 = $vPageWidth - $Right1 ; $OffSetX+$Left1-$vRightMargin Local $Bottom1 = $BottomMinMargin - $vBottomMargin If $Bottom1 < 0 Then $Bottom1 = 0 ; dont print after printable area ends $Bottom1 = $vPageHeight - $Bottom1 Local $z = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETTARGETDEVICE, $hPrintDc, $Right1 - $Left1) ; If $z = 0 Then Return 'Cant find RichEdit Control' If _GUICtrlRichEdit_GetTextLength($hRichEditCtrl) < 1 Then Return 'Nothing to Print.' ; must have a selection on the richEdit control--------------- _SendMessage($hRichEditCtrl, $EM_SETSEL, 0, -1) ; ok----select all Local $dcHTags = "HANDLE hdc;HANDLE hdcTarget;" Local $pgTags = "int Left1 ;int Top1 ;int Right1 ;int Bottom1 ;int Left2;int Top2;int Right2;int Bottom2;" Local $rgTags = "LONG cpMin;LONG cpMax" ; create a structure for the printed page Local $strcPage = DllStructCreate($dcHTags & $pgTags & $rgTags) DllStructSetData($strcPage, "hdc", $hPrintDc) ; printer DllStructSetData($strcPage, "Left1", $Left1) ; twip--------printer DllStructSetData($strcPage, "Right1", $Right1) ; twip--------printer DllStructSetData($strcPage, "Top1", $Top1) ; twip--------printer DllStructSetData($strcPage, "Bottom1", $Bottom1) ; twip--------printer ; next 7 lines seem to have, no effect or crash printer jobs queue---why??? ; "HANDLE hdc;" is the printer------- before conecting printer to rtf??? ; "HANDLE hdcTarget;" is the target RichEdit control that has the rtf ???? ; DllStructSetData($strcPage,"hdcTarget",$hPrintDc) ; richEdit scource??? ; DllStructSetData($strcPage,"Left2",$Left1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Top2",$Top1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Right2",$Page1/$dotInchX*96/3) ; twip------richEdit scource??? ; DllStructSetData($strcPage,"Bottom2",$Bottom1/$dotInchX*96/3) ; twip-----richEdit scource??? ; get the pointer to all that will be printed??? {I think????????} Local $a = DllStructGetPtr($strcPage) + DllStructGetSize(DllStructCreate($dcHTags & $pgTags)) ; use this pointer----------- _SendMessage($hRichEditCtrl, $EM_EXGETSEL, 0, $a) ReDim $__aRTFPageInfo[2] $__aRTFPageInfo[1] = 1 $__aRTFPageInfo[0] = 0 ; the total number of pages Local $iPageInPreview = 1 ; the page number of the preview now showing #forceref $iPageInPreview ; find the last char of the document to be printed Local $cpMax = DllStructGetData($strcPage, "cpMax") ; set the 1st page start char----------- Local $cpMin = 0 Local $cpMin2 = -1 ; ----------------------------------------------------------- ; make a loop to format each printed page and exit when ; $cpMin reaches the $cpMax ; $cpMin is less than 0---{I have seen -1 but I forget when}--- ; ALSO-- ExitLoop if $cpMin = $cpMin 2---if it stops finding the start of next page While $cpMax > $cpMin And $cpMin > -1 ; get the 1st char of the next page, {but how does it work ???} $cpMin2 = $cpMin $cpMin = _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, True, DllStructGetPtr($strcPage)) If $cpMin2 = $cpMin Then ExitLoop; get out of loop before more pages are added ; set the next page start char----------- DllStructSetData($strcPage, "cpMin", $cpMin) $__aRTFPageInfo[0] += 1 ; increment page the total page count ; update array --- for what to show in the preview _ArrayAdd($__aRTFPageInfo, $cpMin) ; start char-number of each page ; end the page and loop again for the next page until the end of document WEnd _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, False, 0) ; adjust the preview shape/size WinMove($__API_RTF_Printer[$__hRTF_RichEditPre], '', 210 - $vPaperWidth / 1440 * 96 / 5 / 2, 200, $vPaperWidth / 1440 * 96 / 5 + 15, $vPaperHeight / 1440 * 96 / 5 + 15) ; the printer starts printing at offsetX and offsetY but the preview windiw starts at 1 and 1 ; so add offsetX and offsetY to the page margins to the printer would use _GUICtrlRichEdit_SetRECT($__API_RTF_Printer[$__hRTF_RichEditPre], ($Left1 + $OffSetX) / $dotInchX * 96 / 5, ($Top1 + $OffSetY) / $dotInchY * 96 / 5, 460, 500) __NextPage(1) GUICtrlSetData($__API_RTF_Printer[$__iRTFLabelPagesTotal], $__aRTFPageInfo[0]) Return $__aRTFPageInfo[0] EndFunc ;==>__RTF_Preview ; #FUNCTION# ==================================================================================================================== ; Name ..........: __RTF_Print ; Description ...: Print from RichEdit control ; Syntax ........: __RTF_Print($hPrintDc, $hRichEditCtrl, $sDocTitle[, $LeftMinMargin = 1[, $TopMinMargin = 1[, $RightMinMargin = 1[, ; $BottomMinMargin = 1]]]]) ; Parameters ....: $hPrintDc - A handle value. Printer's device context. ; $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $sDocTitle - An unknown value. Printer's job title. ; $LeftMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the left ; $TopMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Top ; $RightMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Right ; $BottomMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Bottom ; Return values .: Success - 'Sent to the printer.' ; Failure - 'Printing aborted.' ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Orientation, paper size, number of copies, and which printer are set when the Printer's device context is generated. ; Unexpected results may be caused by single line/paragaph orphin tags in the rtf. ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __RTF_Print($hPrintDc, $hRichEditCtrl, $sDocTitle, $LeftMinMargin = 1, $TopMinMargin = 1, $RightMinMargin = 1, $BottomMinMargin = 1) ; convert the margins 0.1 inches to twips ; $TopMinMarg = $TopMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $LeftMinMarg = $LeftMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $PageMinMarg = $PageMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $BottomMinMarg = $BottomMinMarg * 144; eg 10*144 = 1440 which 1 inch ; convert the margins 1 cm to twips $TopMinMargin = $TopMinMargin * 567; eg 2.539cm * 567= ~1440 which 1 inch $LeftMinMargin = $LeftMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $RightMinMargin = $RightMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $BottomMinMargin = $BottomMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch ; $hPrintDc ; Divice Context handle----------- ; dots per inch depends on the printer quality setting-------X and Y can be different! Local $dotInchX = _WinAPI_GetDeviceCaps($hPrintDc, 88) ; Const LOGPIXELSX = 88 Local $dotInchY = _WinAPI_GetDeviceCaps($hPrintDc, 90) ; Const LOGPIXELSY = 90 ; printer dots per inch ; get the printable area [Page] and paper area [Paper] Local $vPageWidth = _WinAPI_GetDeviceCaps($hPrintDc, 8) ; Const HORZRES= 8 Local $vPageHeight = _WinAPI_GetDeviceCaps($hPrintDc, 10) ; Const VERTRES = 10 Local $vPaperWidth = _WinAPI_GetDeviceCaps($hPrintDc, 110) ; Const PHYSICALWIDTH = 110 Local $vPaperHeight = _WinAPI_GetDeviceCaps($hPrintDc, 111) ; Const PHYSICALHEIGHT = 111 ; none printable margins Local $OffSetX = _WinAPI_GetDeviceCaps($hPrintDc, 112) ; Const PHYSICALOFFSETX = 112 Local $OffSetY = _WinAPI_GetDeviceCaps($hPrintDc, 113) ; Const PHYSICALOFFSETY = 113 Local $vRightMargin = $vPaperWidth - $vPageWidth - $OffSetX Local $vBottomMargin = $vPaperHeight - $vPageHeight - $OffSetY ; conversion factors to use later----------- Local $TwipsInchX = $dotInchX / 1440 ; convert dots to twips [per inch] Local $TwipsInchY = $dotInchY / 1440 ; convert dots to twips [per inch] ; convert all measurments to twips $OffSetX = $OffSetX / $TwipsInchX ; convert Left dots to twips $OffSetY = $OffSetY / $TwipsInchY ; convert Left dots to twips $vPageWidth = $vPageWidth / $TwipsInchX ; convert Right dots to twips $vPageHeight = $vPageHeight / $TwipsInchY ; convert Right dots to twips $vPaperWidth = $vPaperWidth / $TwipsInchX ; convert Paper Width dots to twips $vPaperHeight = $vPaperHeight / $TwipsInchY ; convert Paper Width dots to twips ; Set the margins and keep everything in the printable area Local $Left1 = $LeftMinMargin - $OffSetX If $Left1 < 0 Then $Left1 = 0 ; dont print before printable area starts Local $Top1 = $TopMinMargin - $OffSetY If $Top1 < 0 Then $Top1 = 0 ; dont print before printable area starts Local $Right1 = $RightMinMargin - $vRightMargin If $Right1 < 0 Then $Right1 = 0 ; dont print after printable area ends ; $Right1 = $vPaperWidth - $Right1 - $OffSetX $Right1 = $vPageWidth - $Right1 ;+$Left1 ; $OffSetX Local $Bottom1 = $BottomMinMargin - $vBottomMargin If $Bottom1 < 0 Then $Bottom1 = 0 ; dont print after printable area ends $Bottom1 = $vPageHeight - $Bottom1 ;+$Top1 Local $z = _SendMessage($hRichEditCtrl, $EM_SETTARGETDEVICE, 0) ; 0=wrap----anything else is 1 char per page!!!!! If $z = 0 Then Return 'Cant find RichEdit Control' If _GUICtrlRichEdit_GetTextLength($hRichEditCtrl) < 1 Then Return 'Nothing to Print.' ; must have a selection on the richEdit control--------------- _SendMessage($hRichEditCtrl, $EM_SETSEL, 0, -1) ; ok----select all Local $pgTags = "int Left1 ;int Top1 ;int Right1 ;int Bottom1 ;int Left2;int Top2;int Right2;int Bottom2;" Local $rgTags = "LONG cpMin;LONG cpMax" Local $dcHTags = "HANDLE hdc;HANDLE hdcTarget;" ; create a structure for the printed page Local $strcPage = DllStructCreate($dcHTags & $pgTags & $rgTags) DllStructSetData($strcPage, "hdc", $hPrintDc) ; printer DllStructSetData($strcPage, "Left1", $Left1) ; twip--------printer DllStructSetData($strcPage, "Right1", $Right1) ; twip--------printer DllStructSetData($strcPage, "Top1", $Top1) ; twip--------printer DllStructSetData($strcPage, "Bottom1", $Bottom1) ; twip--------printer ; next 7 lines seem to have, no effect or crash printer jobs queue---why??? ; "HANDLE hdc;" is the printer------- before conecting printer to rtf??? ; "HANDLE hdcTarget;" is the target RichEdit control that has the rtf ???? ; DllStructSetData($strcPage,"hdcTarget",$hPrintDc) ; richEdit scource??? ; DllStructSetData($strcPage,"Left2",$Left1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Top2",$Top1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Right2",$Page1/$dotInchX*96/3) ; twip------richEdit scource??? ; DllStructSetData($strcPage,"Bottom2",$Bottom1/$dotInchX*96/3) ; twip-----richEdit scource??? ; get the pointer to all that will be printed??? {I think????????} Local $a = DllStructGetPtr($strcPage) + DllStructGetSize(DllStructCreate($dcHTags & $pgTags)) ; use this pointer----------- _SendMessage($hRichEditCtrl, $EM_EXGETSEL, 0, $a) ; find the last char of the document to be printed Local $cpMax = DllStructGetData($strcPage, "cpMax") ; set the 1st page start char----------- Local $cpMin = 0 Local $cpMin2 = -1 ; ----------------------------------------------------------- ; create a Document structure for the print job title Local $strDocNm = DllStructCreate("char DocName[" & StringLen($sDocTitle & Chr(0)) & "]") DllStructSetData($strDocNm, "DocName", $sDocTitle & Chr(0)) Local $strDoc = DllStructCreate("int Size;ptr DocName;ptr Output;ptr Datatype;dword Type") DllStructSetData($strDoc, "Size", DllStructGetSize($strDoc)) ; insert the document name structure into the document structure DllStructSetData($strDoc, "DocName", DllStructGetPtr($strDocNm)) DllCall("gdi32.dll", "long", "StartDoc", "hwnd", $hPrintDc, "ptr", DllStructGetPtr($strDoc)) ; ----------------------------------------------------------- ; make a loop to format each printed page and exit when ; $cpMin reaches the $cpMax ; $cpMin is less than 0---{I have seen -1 but I forget when}--- ; ALSO-- ExitLoop if $cpMin = $cpMin 2---if it stops finding the start of next page Local $StartPage, $EndPage #forceref $StartPage While $cpMax > $cpMin And $cpMin > -1 ; start a new page----------- $StartPage = DllCall("Gdi32.dll", "int", "StartPage", "HANDLE", $hPrintDc) ; increment page the count----------- ; if not done now it will exit the loop before counting the last page ; get the 1st char of the next page, {but how does it work ???} $cpMin2 = $cpMin $cpMin = _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, True, DllStructGetPtr($strcPage)) ; ExitLoop when $cpMin = $cpMin 2---just in case it stops finding the start of next page If $cpMin2 = $cpMin Then ExitLoop; get out of loop before more pages are added ; set the next page start char----------- DllStructSetData($strcPage, "cpMin", $cpMin) ; this sends it to the printer $EndPage = DllCall("Gdi32.dll", "int", "EndPage", "HANDLE", $hPrintDc) ; end the page and loop again for the next page until the end of document WEnd _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, False, 0) If $EndPage[0] > 0 Then DllCall("Gdi32.dll", "int", "EndDoc", "HANDLE", $hPrintDc) Return 'Sent to the printer.' Else DllCall("Gdi32.dll", "int", "AbortDoc", "HANDLE", $hPrintDc) Return 'Printing aborted.' EndIf EndFunc ;==>__RTF_Print #EndRegion RTF PRINTER INTERNAL# #Region MSDN Links , Help, Doc ;~ How to Print the Contents of Rich Edit Controls ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/bb787875(v=vs.85).aspx ;~ http://blogs.msdn.com/b/oldnewthing/archive/2007/01/12/1455972.aspx ;~ How To Use GetDeviceCaps to Determine Margins on a Page ;~ http://support.microsoft.com/kb/193943 ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd162833(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd162931(v=vs.85).aspx ;~ http://support.microsoft.com/kb/139652 ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646962(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646964(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646966(v=vs.85).aspx #EndRegion MSDN Links , Help, Doc HOW TO USE THIS: #include-once #include <RTF_Printer.au3> _RTF_PrintFile($sRTF_FileFullPath, Default, True, True) ; or take a look in attached RTF_Printer_Examples.au3 ; Regards mLipok EDIT: attachment changed (before 6 downloads) RTF_Printer.au3.Download.html
  3. Hi, For an internal project I want to write internal script to mail some special request to an external party. To make it a little bit universal I decided that the user should be able to write or edit the e-mail signature. Because I wanted to put a logo into the e-mail, I decided to use RichEdit. I I found the following code by @UEZ and adapted it a little to save and load. When I start the script and edit the text only, I can save and load the signature.rtf. However the moment I resize one of the images (with the mouse), the script wil only save the edited image. Somehow resizing an image deletes the other content of the RichEdit object. Does anyone know a solution for me? P.s. you need to delete signature.rtf to reset the file. #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGui, $iMsg, $idBtnExit, $hRichEdit $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 520, 550, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 500, 490, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnExit = GUICtrlCreateButton("Exit", 10, 510, 40, 30) $GoodRead = False If FileExists(@ScriptDir & "\signature.rtf") Then $ResSFF = _GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\signature.rtf") If $ResSFF=true then $GoodRead = True EndIf If $GoodRead=False Then _GUICtrlRichEdit_InsertText($hRichEdit, "Inserting image..." & @LF & @LF) _GUICtrlRichEdit_InsertText($hRichEdit, @LF & "JPG image scaled:" & @LF & @LF) _GUICtrlRichEdit_InsertBitmap($hRichEdit, "c:\Program Files (x86)\AutoIt3\Examples\GUI\mslogo.jpg", "\qc", "\picw6747\pich1058\picwgoal6690\pichgoal1860\") ;\qc = centered _GUICtrlRichEdit_InsertText($hRichEdit, @LF & @LF & "PNG image:" & @LF & @LF) _GUICtrlRichEdit_InsertBitmap($hRichEdit, "c:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png") _GUICtrlRichEdit_InsertText($hRichEdit, @LF & @LF & "Done.") EndIf GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idBtnExit _GUICtrlRichEdit_StreamToFile($hRichEdit, @ScriptDir & "\signature.rtf") _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes GUIDelete() Exit EndSwitch WEnd EndFunc ;==>Example Func _GUICtrlRichEdit_InsertBitmap($hWnd, $sFile, $sFormatFunctions = "\", $sBitmapFunctions = "\", $iBgColor = Default) ;coded by UEZ build 2016-02-16 If Not FileExists($sFile) Then Return SetError(0, 0, 1) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(0, 0, 2) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then _GDIPlus_Shutdown() Return SetError(0, 0, 3) EndIf Local Const $aDim = _GDIPlus_ImageGetDimension($hImage) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1]), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) If $iBgColor = Default Then $iBgColor = 0xFF000000 + _WinAPI_SwitchColor(_GUICtrlRichEdit_GetBkColor($hWnd)) EndIf _GDIPlus_GraphicsClear($hGfx, $iBgColor) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $aDim[0], $aDim[1]) _GDIPlus_GraphicsDispose($hGfx) Local $binStream = _GDIPlus_StreamImage2BinaryString($hBitmap, "BMP") If @error Then _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return SetError(0, 0, 4) EndIf Local $binBmp = StringMid($binStream, 31) Local Const $binRtf = "{\rtf1\viewkind4" & $sFormatFunctions & " {\pict{\*\picprop}" & $sBitmapFunctions & "dibitmap " & $binBmp & "}\par}" ;check out http://www.biblioscape.com/rtf15_spec.htm _GUICtrlRichEdit_AppendText($hWnd, $binRtf) $binStream = 0 $binBmp = 0 _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return 1 EndFunc ;==>_GUICtrlRichEdit_InsertBitmap Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "JPG", $iQuality = 80, $bSave = False, $sFileName = @ScriptDir & "\Converted.jpg") ;coded by UEZ 2013 build 2014-01-25 (based on the code by Andreik) Local $sImgCLSID, $tGUID, $tParams, $tData Switch $sFormat Case "JPG" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Case "PNG", "BMP", "GIF", "TIF" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Case Else Return SetError(1, 0, 0) EndSwitch Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(2, 0, 0) _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams)) If @error Then Return SetError(3, 0, 0) Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(4, 0, 0) Local $iMemSize = _MemGlobalSize($hMemory) If Not $iMemSize Then Return SetError(5, 0, 0) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) If $bSave Then Local $hFile = FileOpen($sFileName, 18) If @error Then Return SetError(6, 0, $bData) FileWrite($hFile, $bData) FileClose($hFile) EndIf Return $bData EndFunc ;==>_GDIPlus_StreamImage2BinaryString
  4. Here: https://github.com/nachbar/TRichViewToPdfUsingDebenu/blob/master/Unit1.cpp I found a code in C++ for file format conversion from RTF to PDF with using Debenu QuickPDF. I know how to use Debenu QuickPDF in AutoIt . My question is about RTF part of this code: HDC hdcNew = debenu->GetCanvasDC( RTFPRINTINGDOTSPERINCH * RTFPAGEWIDTHININCHES, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); canvas = new TCanvas; canvas->Handle = hdcNew; RVReportHelper1->DrawPage( PageCounter, canvas, true, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); // LastPageHeight); First there is hdcNew declaration , and this is not the problem. My problem is in converting the following code snippet, to AutoIt canvas = new TCanvas; canvas->Handle = hdcNew; RVReportHelper1->DrawPage( PageCounter, canvas, true, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); // LastPageHeight); If you remember, I created RTFPrinter sometime ago. But it was some time ago , and created by trial and error, rather than in-depth analysis. Also, it was just a modification of another script, not my own work from scratch. So now I'm looking for help how to adapt this code snippet to AutoIt. Any tips ? Regards, mLIpok
  5. I am seeing a weird result when pasting some lines from the forum into WordPad, even while using Paste Special > Unformatted Text ... Example: copy the reply from the first post here: Go to WordPad and Paste Special > Unformatted Text (Ctrl + Alt + v) Result is two fonts instead of one "unformatted" (I took out the blank lines): If you analyze the .rtf code, it has this font command in it: {\f1\fnil\fcharset134 SimSun;}} (1) Why is that there, or how can it even get through Paste Special? Is it really there, or is it a one-in-a-million text combo that triggers WordPad formatting? (2) Speaking in general, if you would run this through AutoIt, or you copied it with AutoIt, how would you prevent it? What could you filter out? Is this some kind of control code that can be filtered simply, or would you have to do a regex for these patterns? Thanks
  6. When I stream richtedit content to a .rtf file and want to open it, word tells me the file is locked by another user (I guess it's my program). Now, if I close my program or open the file in read-only mode, the document is empty. Here's the code I used: $MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}" $where = FileSaveDialog("Plan Speichern", $MyDocsFolder,"Rich Text Files (*.rtf)", 2) If StringInStr($where,".rtf") Then _FileCreate($where) $infile = _GUICtrlRichEdit_StreamToFile($Edit1, $where) Else $where = $where & ".rtf" _FileCreate($where) $infile = _GUICtrlRichEdit_StreamToFile($Edit1, $where) EndIf Why is the document locked and has no content?
×
×
  • Create New...