Jump to content
Sign in to follow this  
timmy2

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

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.

Share this post


Link to post
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

 

Share this post


Link to post
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


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 *

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 * 

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 TaskScheduler

PDF Related:https://www.autoitscript.com/forum/topic/177368-how-to-get-reference-to-pdf-object-embeded-in-ie/ *

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 *

"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: 2020-09-20

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
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?

Share this post


Link to post
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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 *

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 * 

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 TaskScheduler

PDF Related:https://www.autoitscript.com/forum/topic/177368-how-to-get-reference-to-pdf-object-embeded-in-ie/ *

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 *

"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: 2020-09-20

Share this post


Link to post
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.


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...