Jump to content

What's best AutoIt-based way to display a formatted AU policy?


timmy2
 Share

Recommended Posts

I want to display a formatted (rich text?) Acceptable Use Policy in a scrollable window with OK and cancel buttons.

All the rich-text examples I've found thus far apply to creating edit boxes, and the examples I've read for the GuiRichEdit UDF appear intended for building text line by line. Wonderfully granular but seems like overkill for this application.

I'd prefer to just open an already formatted file and display it.

Before I continue looking for this needle in a haystack, anyone willing to suggest the most appropriate AutoIT functions or approaches I should consider (if such a thing exists)?

Thank you.

Link to comment
Share on other sites

You could always use html example:

#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WindowsConstants.au3>

Local $oIE = _IECreateEmbedded()
Local $sHTML = ""
$sHTML &= "<HTML>" & @CRLF
$sHTML &= "<HEAD>" & @CRLF
$sHTML &= "<TITLE>Acceptablue Usage Policy Sample</TITLE>" & @CRLF
$sHTML &= "</HEAD>" & @CRLF
$sHTML &= "<BODY>"
$sHTML &= "<h2>Sample Acceptable Usage Policy</h2>"
$sHTML &= "<p><strong>This document should be tailored to your organisation’s specific requirements.< /br>"
$sHTML &= "Remove, add or substitute text where appropriate.</strong></p>"
$sHTML &= "<p>This Acceptable Usage Policy covers the security and use of all (Acme Corporation’s) information and IT equipment. It also includes the use of email, internet, voice and mobile IT equipment. This policy applies to all (Acme Corporation’s) employees, contractors and agents (hereafter referred to as ‘individuals’).</p>"
$sHTML &= "<p>This policy applies to all information, in whatever form, relating to (Acme Corporation’s) business activities worldwide, and to all information handled by (Acme Corporation) relating to other organisations with whom it deals. It also covers all IT and information communications facilities operated by (Acme Corporation) or on its behalf.</p>"
$sHTML &= "<h3>Computer Access Control – Individual’s Responsibility</h3>"
$sHTML &= "<p>Access to the (Acme Corporation) IT systems is controlled by the use of User IDs, passwords and/or tokens. All User IDs and passwords are to be uniquely assigned to named individuals and consequently, individuals are accountable for all actions on the (Acme Corporation’s) IT systems.</p>"
$sHTML &= "<h3>Individuals must not:</h3>"
$sHTML &= "<ul>"
$sHTML &= "<li>Allow anyone else to use their user ID/token and password on any (Acme Corporation) IT system.</li>"
$sHTML &= "<li>Leave their user accounts logged in at an unattended and unlocked computer.</li>"
$sHTML &= "<li>Use someone else’s user ID and password to access (Acme Corporation’s) IT systems.</li>"
$sHTML &= "<li>Leave their password unprotected (for example writing it down).</li>"
$sHTML &= "<li>Perform any unauthorised changes to (Acme Corporation’s) IT systems or information.</li>"
$sHTML &= "<li>Attempt to access data that they are not authorised to use or access.</li>"
$sHTML &= "<li>Exceed the limits of their authorisation or specific business need to interrogate the system or data.</li>"
$sHTML &= "<li>Connect any non-(Acme Corporation) authorised device to the (Acme Corporation) network or IT systems.</li>"
$sHTML &= "<li>Store (Acme Corporation) data on any non-authorised (Acme Corporation) equipment.</li>"
$sHTML &= "<li>Give or transfer (Acme Corporation) data or software to any person or organisation.</li>"
$sHTML &= "outside (Acme Corporation) without the authority of (Acme Corporation).</li>"
$sHTML &= "<p>Line managers must ensure that individuals are given clear direction on the extent and limits of their authority with regard to IT systems and data.</p>"
$sHTML &= "</BODY>"
$sHTML &= "</HTML>"
Global $idAccept, $idOKBtn, $bAccept = False
GUICreate("Embedded Web control Test", 640, 500, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
GUICtrlCreateObj($oIE, 10, 40, 600, 360)
$idAccept = GUICtrlCreateCheckbox("I accept the Acceptable Usage Policy.", 10, 410, 620, 20)
$idOKBtn = GUICtrlCreateButton("OK", 540, 435, 90, 30)
GUICtrlSetState($idOKBtn, $GUI_DISABLE)
Local $idCancelBtn = GUICtrlCreateButton("Cancel", 450, 435, 90, 30)
_IENavigate($oIE, "about:blank")
_IEDocWriteHTML($oIE, $sHTML)
_IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "return false")
GUISetState(@SW_SHOW)
AdlibRegister("_Accept_Toggle")
While 1
    Local $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

Func _Accept_Toggle()
    If BitAnd(GUICtrlRead($idAccept),$GUI_CHECKED) = $GUI_CHECKED Then
        If $bAccept = False Then GUICtrlSetState($idOKBtn, $GUI_ENABLE)
    Else
        If $bAccept = True Then GUICtrlSetState($idOKBtn, $GUI_DISABLE)
    EndIf
EndFunc

 

Link to comment
Share on other sites

@timmy2 You can use a Rich Edit control and use _GUICtrlRichEdit_StreamFromFile with an RTF file to display the rich text :)

All of the functions related to Rich Edit controls are in the User Defined Function Reference -> GUI -> GuiRichEdit section of the help file :D

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Some time ago I was trying to use TxTextControl with AutoIt.
I had some success, but this control has a unique licensing system and I was not able to use them with LicenseKey.

I think you can also try to use: 

but the text formating feature will be limited.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

15 hours ago, TheDcoder said:

@timmy2 You can use a Rich Edit control and use _GUICtrlRichEdit_StreamFromFile with an RTF file to display the rich text :)

All of the functions related to Rich Edit controls are in the User Defined Function Reference -> GUI -> GuiRichEdit section of the help file :D

Thank you for the suggestion, @TheDcoder. Since my preference was to simply open an already-formatted file I tried your suggestion first. I created a simple formatted file in WordPad but when it's opened by the GUICtrlRichEdit_StreamFromFile function in the following script the result is mostly just a bunch of question marks.  If I can't use a WYSIWYG editor to create the RTF file I'll try using HTML.

Oops. For some reason now that I opened the rtf file in Microsoft Word and then saved it as RTF the file is displayed properly. So I'm going to continue playing with this approach.  

 

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGui, $iMsg, $idBtnNext, $iStep = 0, $idLblMsg, $hRichEdit
    $hGui = GUICreate("stream from file test", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)

    GUISetState(@SW_SHOW)

    _GUICtrlRichEdit_SetText($hRichEdit, "")
    _GUICtrlRichEdit_StreamFromFile($hRichEdit, @DesktopDir & "\testrtf.rtf")
    GUICtrlSetData($idLblMsg, "Streamed from testrtf.rtf")

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

 

(initial) Result:

result.JPG.6ec3e5bd4fbadf8630ee5530ecbf3956.JPG

 

Result using RTF file saved in Word 2016.

5bedeb7b95823_result2.JPG.0478a2e4cf21b3f0ec9a0250eb34d6d3.JPG

 

Edited by timmy2
tried a different editor to save the RTF
Link to comment
Share on other sites

11 hours ago, mLipok said:

Some time ago I was trying to use TxTextControl with AutoIt.
I had some success, but this control has a unique licensing system and I was not able to use them with LicenseKey.

I think you can also try to use:

but the text formating feature will be limited.

Thank you for replying, @mLipok. Since formatting is more important to me than creating an editor I'm going to explore the HTML example.

Link to comment
Share on other sites

@Subz, your example is a revelation to me. I did not know I could use HTML. I'm going to study your example carefully. I hope to figure out how to create a compatible HTML file and open it in the script rather than hardcode it as in the example.  You've given me a great boost!  Thank you.

Link to comment
Share on other sites

7 hours ago, timmy2 said:

Oops. For some reason now that I opened the rtf file in Microsoft Word and then saved it as RTF the file is displayed properly. So I'm going to continue playing with this approach.  

Maybe it is something related to encoding, and MS Word seems to be using the correct encoding :)

 

You can also use an embedded IE control (COM Object) to display HTML as @Subz has suggested. This opens up more opportunities to you, as the ability to use JavaScript to make the page interactive.

To sum it up: Use IE if you want a more feature rich document which can display HTML or if you just need to display some formatted text in a simple manner, stick to Rich Edit controls :)

Rich Edit controls are lighter and are less likely to break across different versions than IE (which has gone through it's fair share of script breaking major changes)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

18 hours ago, TheDcoder said:

To sum it up: Use IE if you want a more feature rich document which can display HTML or if you just need to display some formatted text in a simple manner, stick to Rich Edit controls :)

Thank you , @TheDcoder.  I will post the resulting scripts (HTML and RTF) after commenting and clean-up. Do you know if it's possible to display pictures that are part of an HTML page?  The closest I've gotten with the HTML file is displaying a placeholder icon.  Am I wasting time trying to include pictures?

Link to comment
Share on other sites

On 15.11.2018 at 10:42 PM, timmy2 said:

Thank you for replying, @mLipok. Since formatting is more important to me than creating an editor I'm going to explore the HTML example.

Using RichEdit or even IE Embeded you can also create EDITOR this is only a matter  of approach, to your needs :)

For example:

 

As to your last question:

18 minutes ago, timmy2 said:

Do you know if it's possible to display pictures that are part of an HTML page?  The closest I've gotten with the HTML file is displaying a placeholder icon.  Am I wasting time trying to include pictures?

maybe you could try this:

https://stackoverflow.com/questions/8499633/how-to-display-base64-images-in-html

and take a look also here:

and here:

and here:

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

5 hours ago, timmy2 said:

Do you know if it's possible to display pictures that are part of an HTML page? 

Yes. you can use data url in the img tag as the source :), @mLipok has already mentioned this and has linked to useful pages.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...