Jump to content
Sign in to follow this  
TheSaint

Simple Dropbox For URL's

Recommended Posts

I've finally come up with a simple solution for dragging & dropping a URL.
It's not perfect, but it does the job. Mostly just a tweak of some Help file examples.

Thanks also to AutoBert, for his StringRegExp and example that set me on the right path.

I have seen this requested for many times, so enjoy!

It goes without saying, that any improvements are welcome. :D

Dropbox For URLs.au3

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

Global $hGui, $g_hRichEdit

Example()

Func Example()
   Local $cnt, $URL, $val, $text
   Local $iMsg, $state = $WS_CAPTION + $WS_POPUP + $WS_CLIPSIBLINGS + $WS_SYSMENU
   $hGui = GUICreate(StringTrimRight(@ScriptName, 4), 160, 100, -1, -1, $state, $WS_EX_TOPMOST)
   $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 140, 80, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
   GUISetState(@SW_SHOW)

   _GUICtrlRichEdit_SetEventMask($g_hRichEdit, $ENM_LINK)

   _GUICtrlRichEdit_AutoDetectURL($g_hRichEdit, True)

   $cnt = 0

   While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($g_hRichEdit)
                ExitLoop
             Case Else
               If $cnt = 20 Then
                  $text = _GUICtrlRichEdit_GetText($g_hRichEdit)
                  If $text <> "" Then
                     $val = StringRegExp($text, "(?s)((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)", 2)
                     If UBound($val) > 0 Then
                        $URL = $text
                        ClipPut($URL)
                        ;MsgBox(0, "URL", $URL, 0, $hGui)
                     Else
                        _GUICtrlRichEdit_SetText($g_hRichEdit, "Only URL's are supported!")
                        ;MsgBox(0, "Not URL", "Only URL's are supported!", 0, $hGui)
                     EndIf
                     Sleep(600)
                     _GUICtrlRichEdit_SetText($g_hRichEdit, "")
                  EndIf
                  $cnt = 0
               Else
                  $cnt = $cnt + 1
               EndIf
        EndSelect
    WEnd
EndFunc   ;==>Example

GUIDelete($hGui)

Exit

I also wanted a version that would work with an earlier version of AutoIt (v3.3.0.0), to use with updates for some older scripts (programs).

The following works fine on my Win XP laptop, but fails (also when compiled) on my Win 7 Netbook.

I found a RichEdit example in the GUICtrlCreateEdit function (Example 2) in the AutoIt v3.3.0.0 Help file, and modified that to suit my script.
Failure is no doubt due to 'MSCOMCT2.OCX' missing from the System32 folder, at the very least.

Any solution to getting the following to work on Win 7 would be greatly appreciated. Perhaps a different '.OCX' file etc.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

Global $oMyError

RichEditExample()

Exit

; Rich edit control EXAMPLE using GUICtrlCreateObj
; Author: Kåre Johansson
; AutoIt Version: 3.1.1.55
; Description: Very Simple example: Embedding RICHTEXT object
; Needs: MSCOMCT2.OCX in system32 but it's probably already there
; Date: 3 jul 2005
Func RichEditExample()
    Local $cnt, $DropBoxGUI, $GUIActiveX, $msg, $oRP, $state, $text, $URL, $val

    $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

    $oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")
    If @error Then Return

    $state = $WS_CAPTION + $WS_POPUP + $WS_CLIPSIBLINGS + $WS_SYSMENU
    $DropBoxGUI = GUICreate(StringTrimRight(@ScriptName, 4), 160, 100, -1, -1, $state, $WS_EX_TOPMOST)

    $GUIActiveX = GUICtrlCreateObj($oRP, 0, 0, 140, 80)
    GUICtrlSetPos($GUIActiveX, 5, 5, 150, 90)

    $cnt = 0

    With $oRP; Object tag pool
        .OLEDrag()
        .Font = 'Arial'
        .Text = @CRLF & @CRLF & "     Drag & Drop a URL here."
        .SelBold = True
        .BackColor = 0xff00
        ;.FileName = @ScriptDir & '\RichText.rtf'
        ;$oRP.AboutBox()
        ;$oRP.SelBold = False
        ;$oRP.SelItalic = False
        ;$oRP.SelUnderline = False
        ;$oRP.SelFontSize = 8
        ;$oRP.SaveFile(@ScriptDir & "\RichText.rtf", 0)
    EndWith

    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE
                GUIDelete($DropBoxGUI)
                ExitLoop
            Case Else
                If $cnt = 20 Then
                    $text = $oRP.Text
                    If $text <> "" Then
                        If $text = @CRLF & @CRLF & "     Drag & Drop a URL here." Then
                            Sleep(2000)
                        Else
                            $val = StringRegExp($text, "(?s)((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)", 2)
                            If UBound($val) > 0 Then
                                $URL = $text
                                ClipPut($URL)
                                ;MsgBox(0, "URL", $URL, 0, $hGui)
                                Sleep(600)
                            Else
                                With $oRP
                                    .Text = "Only URL's are supported!"
                                EndWith
                                ;MsgBox(0, "Not URL", "Only URL's are supported!", 0, $hGui)
                                Sleep(1500)
                            EndIf
                        EndIf
                        With $oRP
                            .Text = ""
                            .SelBold = False
                        EndWith
                    EndIf
                    $cnt = 0
                Else
                    $cnt = $cnt + 1
                EndIf
        EndSelect
    WEnd
EndFunc   ;==>RichEditExample

Func MyErrFunc()
    MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext , 5)
    ; Will automatically continue after 5 seconds

    Local $err = $oMyError.number
    If $err = 0 Then $err = -1

    SetError($err)  ; to check for after this function returns
EndFunc   ;==>MyErrFunc

And a slower embedded IE based version. This has an error in latest AutoIt, but works fine in v3.3.0.0.

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

Local $DropboxGUI, $GUIActiveX, $loaded, $loops, $oBody, $oIE, $sHTML, $timeout, $urlpage

_IEErrorHandlerRegister()

$oIE = _IECreateEmbedded()
$DropboxGUI = GUICreate("URL Dropbox", 140, 140, -1, -1, _
    $WS_OVERLAPPED + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_SYSMENU, $WS_EX_TOPMOST)
$GUIActiveX = GUICtrlCreateObj($oIE, 5, 5, 125, 100)

$oBody = _IETagNameGetCollection($oIE, "body", 0)
_IEDocInsertHTML($oBody, "", "afterbegin")

$loaded = _IEPropertyGet($oIE, "locationurl")

$urlpage = $loaded
$loops = 0

$sHTML = ""
$sHTML &= "<HTML>" & @CR
$sHTML &= "<HEAD>" & @CR
$sHTML &= "<TITLE>Drag And Drop Example</TITLE>" & @CR
$sHTML &= "</HEAD>" & @CR
$sHTML &= "<BODY>" & @CR
$sHTML &= "</BODY>" & @CR
$sHTML &= "</HTML>"

_IELoadWaitTimeout(1)

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ; Quit, Close or Exit window
        GUIDelete($DropboxGUI)
        ExitLoop
    Case Else
        ;;;
        If $loops = 10 Then
            $loops = 0
            $loaded = _IEPropertyGet($oIE, "locationurl")
            If $loaded <> $urlpage Then
                _IEAction($oIE, "stop")
                _IEDocWriteHTML($oIE, $sHTML)
                If $loaded = "res://ieframe.dll/navcancl.htm" Then $loaded = ""
                $urlpage = $loaded
                _IEBodyWriteHTML($oIE, '<p style="WORD-WRAP: normal; WORD-BREAK: break-all; FONT-SIZE: 8px">' & $loaded & '</p>')
            EndIf
        Else
            $loops = $loops + 1
        EndIf
    EndSelect
WEnd

Exit

 

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Added another method for earlier versions of AutoIt, that were before the inclusion of the RichEdit UDF.

NOTE - It works fine for me on Win XP, but fails on Win 7. Any solution to that would be greatly appreciated. :D


Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Well, I came up with a solution of sorts ... which works for me anyway, but not so great for sharing with an older AutoIt program of mine, that I hope to use it with, and I really do not want to recreate the program again in latest AutoIt, so I am still in need of a better solution.

I did quite a bit of research a few days ago, then went away for three days, so are just now attempting to recall the important bits, for those interested.

1. I installed the Visual Basic Runtime from here. That supposedly gave me the required library elements. This wasn't enough though.

2. Then doing some research both at the AutoIt Forum and online elsewhere, for the error message (Class is not licensed for use) that I was still getting, I came across Embedded activeX component - RichText. A post there mentions an ActiveX Fix, which I downloaded from here. The included reg file did the trick. I also came across what appears to be a similar thing, called vbctrls.reg, which is said to be located on the vb6 install CD, under \Common\tools\vb\controls. If that last had been at hand, I would have tried that first instead, but I have it buried away somewhere, and couldn't spare the time to find it ... and couldn't be bothered either. :P

P.S. I am not sure about the legality of that ActiveX Fix, so I have no intentions of recommending it. Users though, are free to do as they wish. It does seem odd to me though, that Microsoft have such a painful arrangement with these old controls, especially as the web is full of people struggling with a similar issue to mine. It is very much like VB .Net made VB6 programs redundant, which should not have been the case. According to what I have read, if the control was provided in a specific manner (attached to a form or something), then the licensing issue doesn't occur ... but I have no clue how to implement such in AutoIt ... if you even can.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Added a slower embedded IE based version. This has an error in latest AutoIt so doesn't run, but runs fine in v3.3.0.0. Tested on Win XP and Win 7 (32 bit).

Quite slow on my Win 7 Netbook, but I imagine it would be much faster on most PC's, so quite usable. It could however, be much slower with some links/URLs.

The slowness, it seems to me, is due to a minimum web page load time that cannot be avoided, that I know of. Would be great if we could avoid the web page for the URL from loading at all.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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.

  • Similar Content

    • By VeeDub
      Hello,
      I'm trying to write a script to allow pause / resume of Dropbox syncing; so that Dropbox syncing can be scheduled.
      So the idea is that the script will emulate what a user would normally do by clicking on Dropbox on the System Tray and then the script will toggle the sync operation
      If Dropbox currently syncing, will pause If syncing currently paused, will resume I'm writing this script for Windows 10
      I am able to open Dropbox from the System Tray, but I can't figure out how to enumerate the controls. 
      I would have been happy with the "simple" approach of using the Autoit Window Info tool to manually identify the values for the control. But unfortunately as soon as I click on the Finder Tool the Dropbox window closes.
      I then tried enumerating the controls with my script.
      I have experimented with a couple of scripts that others have shared, which while they don't error; don't return any values for the Controls.
      So at the moment I'm stuck and I'm after some ideas
      Is there a way to use a Windows Viewer tool with an app like Dropbox that doesn't remain visible?  (I had a quick look but could not find a solution) If I need to enumerate the controls myself, here is my current script. I'm using _EnumChildWindows from here #include <Array.au3> #include <GuiToolBar.au3> #include <_EnumChildWindows.au3> Local $hSysTray_Handle Local $hWnd="",$hControl=0,$sTitle=0,$sClass=0,$aEnumList Local $hNumber1Button=-1,$hNumber4Button=-1,$hPlusButton=-1,$hEqualButton=-1 $sSearchtext='Dropbox' $iButton=Get_SysTray_IconText($sSearchtext) _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iButton, "left", False, 1) ; MsgBox (64,'Searched Button','Button: '&$iButton&@CRLF&'Instance: '&@extended) If WinActivate($hSysTray_Handle, "") Then ; MsgBox($MB_SYSTEMMODAL, "", "Dropbox Window activated") ; Check Dropbox status - Either: ; 'Up to date' (i.e. syncing) ; 'Syncing paused' (paused) $hWnd = $hSysTray_Handle ; Important to wait for the window to fully 'create' itself before getting child windows! ; Note that other processes that become activated somewhere between WinWait and this will cause WinWaitActive() to wait for manual activation ;WinWaitActive($hWnd) ; bad idea in busy environment Sleep(3000) WinActivate($hWnd) ; this seems to be a better alternative, the window seems fully created after this is called in my tests ; Parameters to function ;$hControl=HWnd(0x########) ;$sTitle="^(\d|\+|=)$" ; PCRE - gets controls with numbers, + or = sign only (problem: no instance #'s!) ;$sClass="Button" $aEnumList=_EnumChildWindows($hWnd,$hControl,$sTitle,$sClass) ;,2) for RegExp Title If @Error Then Exit ; Find specific items [Certain versions of Calc won't return any text] For $i=1 to $aEnumList[0][0] Switch $aEnumList[$i][4] Case "1" $hNumber1Button=$aEnumList[$i][0] ConsoleWrite("'1' Advanced Mode Name (in current state): [CLASS:Button; INSTANCE:"&$aEnumList[$i][3]&"]"&@CRLF) Case "4" $hNumber4Button=$aEnumList[$i][0] ConsoleWrite("'4' Advanced Mode Name (in current state): [CLASS:Button; INSTANCE:"&$aEnumList[$i][3]&"]"&@CRLF) Case "+" $hPlusButton=$aEnumList[$i][0] ConsoleWrite("'+' Advanced Mode Name (in current state): [CLASS:Button; INSTANCE:"&$aEnumList[$i][3]&"]"&@CRLF) Case "=" $hEqualButton=$aEnumList[$i][0] ConsoleWrite("'=' Advanced Mode Name (in current state): [CLASS:Button; INSTANCE:"&$aEnumList[$i][3]&"]"&@CRLF) EndSwitch Next ; Add Headers $aEnumList[0][0]="Handle" $aEnumList[0][1]="Classname" $aEnumList[0][2]="Control ID" $aEnumList[0][3]="Iteration" $aEnumList[0][4]="Title/Text" ; Bring the window forward WinActivate($hWnd) ; Perform a simple calculation to show interaction If $hNumber1Button<>-1 Then ControlClick($hWnd,"",$hNumber1Button,"primary",3) ControlClick($hWnd,"",$hNumber4Button) Sleep(1000) ControlClick($hWnd,"",$hPlusButton) Sleep(1000) ControlClick($hWnd,"",$hNumber4Button,"primary",2) ; double click, but that's fine Sleep(1000) ControlClick($hWnd,"",$hEqualButton) EndIf ; And Display ALL Enumerated Windows _ArrayDisplay($aEnumList,"Enumerated controls for App") Else MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Dropbox Window not activated") EndIf Func Get_SysTray_IconText($sSearch) For $i = 1 To 99 ; Find systray handles $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:' & $i & ']') ; ConsoleWrite ("Handle: " & $hSysTray_Handle & @CRLF) If @error Then ;MsgBox(16, "Error", "System tray not found") ExitLoop EndIf ; Get systray item count Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) ConsoleWrite("iSysTray_ButCount: " & $iSysTray_ButCount & @CRLF ) If $iSysTray_ButCount = 0 Then ;MsgBox(16, "Error", "No items found in system tray") ContinueLoop EndIf Local $aSysTray_ButtonText[$iSysTray_ButCount] ; Look for wanted tooltip For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1 ConsoleWrite("iSysTray_ButtonNumber: " & $iSysTray_ButtonNumber & " Button_Text: " & _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber) & @CRLF ) If $sSearch= StringLeft(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber),StringLen($sSearch)) Then ConsoleWrite("Button Text: " & $sSearch & " Handle: " & $hSysTray_Handle & " Button Number: " & $iSysTray_ButtonNumber & @CRLF) Return SetError(0, $i, $iSysTray_ButtonNumber) EndIf Next Next Return SetError(1, -1, -1) EndFunc ;==>Get_SysTray_IconText Thanks,
      VW 
    • By HariKara
      I have a script that seems to launch perfectly fine with IECreate, however, I want to launch the Browser and a specific URL with the RunAs command. I fairly new to AutoIT and wanted to know if someone can point me in the right direction.
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = _IECreate($sURL)
      The above launches the website correctly with the correct URL, however, I have tried the below and this fails to load and browser?
      #include <AutoItConstants.au3>
      ;========================
      $oSleep = "200"
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = RunAs($args("username"), $args("domain"), $args("logonpassword"), "", "C:\Program Files (x86)\Internet Explorer\iexplore.exe http://somewebsite.com/DODA/admin/job.aspx")
      _IELoadWait($oIE)
       
      I get the following error back?
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
    • By nacerbaaziz
      hello sirs
      please i want to use the WinHttp to get the google drive file title using the api
      i searched in the forom but i didn't found any Google drive api UDF
      for that i liked to ask you for that
      i had read the google drive api documentation but i couldn't do it
      please help me
      here is the api doc
      note i've got the apikey and i have the file id
      what i want is to get the title of the file (the file name)
      because i want to download the files from the google drive using the autoit
      please help me for that
      am sorry because i didn't gave you any example or what i tried but all what tried was  failed
      thanks in advance
    • By nacerbaaziz
      hello sirs
      i've some questions about StringRegExpReplace i hope you can help me
       
      i tried to make a function that give me the host of the url and other give me the url with out host
      for example i've this link
      https://www.example.com/vb/result.php
      i need the first give me the
      example.com
      and the other give me 
      /vb/result.php
      i find that
      $s_source = "https://www.google.com/vb/index.php" Local $s_Host = StringRegExpReplace($s_Source, '.*://(.*?)/.*', '\1') Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*)', '\1') msgBox(64, $s_Host, $s_Page)  
      but i found some problems i need your help to correct it
      first: when i get the host if the url has www i want to remove it
      second: if the url with out host did not have other things 
      i need the result to be ""
      e.g
      https://www.example.com
      the first i want it
      example.com
      and the second i want it to be ""
      i hope that you can help me
      thanks in advance
×
×
  • Create New...