Sign in to follow this  
Followers 0
eltorro

Toast

12 posts in this topic

#1 ·  Posted (edited)

Here's a popup notification script. The script is run as a daemon (_AIEPopupNotifyd.au3) and is called by other scripts using WM_COPYDATA.

Compile it and run it. The tray icon will flash and go away.

[autoit]#include <GuiConstants.au3>

#include-once

;------------------------------------------------------------------------------

; AutoIt Version : 3.2

; Language : English

; Description : Display a popup message over system tray.

; Author(s) Stephen Podhajecki <gehossafats at netmdc dot com />

;

;------------------------------------------------------------------------------

;Opt("MustDeclareVars",1)

;===================================================================================================

; global vars

;===================================================================================================

Local $old = Opt("TrayIconHide", 1) ;Hide the AutoIt icon.

Global Enum Step * 2 $PN_TITLE, $PN_EXIT, $PN_IMAGE, $PN_LINK, $PN_MESSAGE, $PN_FUNC

Global Enum $POP_TITLE = 0, $POP_TITLE_SIZE, $POP_MESSAGE, $POP_MESSAGE_TYPE, $POP_PARAM, $POP_WIDTH, $POP_HEIGHT

Global Enum $POP_FOREGROUND = $POP_HEIGHT + 1, $POP_BACKGROUND1, $POP_BACKGROUND2, $POP_FONTSIZE, $POP_USEGRADIENT, $POP_GRAD_TYPE

Global Enum $POP_BACKGROUND_IMAGE = $POP_GRAD_TYPE + 1,$POP_SPEED,$POP_TIME,$POP_RETURN

Global $AUTOITIE_EVENT, $AIEERRHANDLER

Global Const $StructDef_COPYDATA = "ptr;dword;ptr"

; The custom Struct (Must be the same in Sender and Receiver)

Global Const $STRUCTDEF_AU3MESSAGE = "char[128];byte;char[256];int;char[256];int;int;char[10];char[10];char[10];byte;byte;byte;char[256];int;int;char[128]"

Global Const $STRUCTDEF_AU3RETURN = "int"

; Create Reciver window

$hwmd_Reciver = GUICreate("_AIEPOPUPDAEMON")

; Register Windows Messages

GUIRegisterMsg($WM_COPYDATA, "_GUIRegisterMsgProc")

GUIRegisterMsg($WM_CLOSE, "_GUIRegisterMsgProc")

;wait.

While 1

Sleep(250)

WEnd

;==============================================================================

;creates and shows the msn style popup.

;==============================================================================

Func _AIEShowPopup($aPopData)

$speed = $aPopData[$POP_SPEED]

$time = $aPopData[$POP_TIME]

Local $OldEventMode = AutoItSetOption("GuiOnEventMode", 1)

Local $PreviousMode = AutoItSetOption("WinTitleMatchMode", 4)

Local $TrayWnd = WinGetPos("classname=Shell_TrayWnd")

AutoItSetOption("WinTitleMatchMode", $PreviousMode)

Local $PopUpWnd[2] = [0, 0], $w, $h

If $aPopData[$POP_WIDTH] < 75 Then

$w = 75

Else

$w = $aPopData[$POP_WIDTH]

EndIf

If $aPopData[$POP_HEIGHT] < 75 Then

$h = 75

Else

$h = $aPopData[$POP_HEIGHT]

EndIf

$PopUpWnd[0] = $TrayWnd[2] - $w - 1

$PopUpWnd[1] = $TrayWnd[1] - $h - 1

Local $AUTOITPOPUP = GUICreate("Popup", $w, $h, $PopUpWnd[0], $PopUpWnd[1], $WS_POPUP, $WS_EX_TOOLWINDOW)

Local $AUTOITIE = ObjCreate("Shell.Explorer")

Local $AUTOITIECTRL = GUICtrlCreateObj($AUTOITIE, 0, 0, $w, $h)

$AUTOITIE.navigate ("about:blank")

$AUTOITIE.document.open

$AUTOITIE.document.Write (_AIEMakeBody($aPopData))

$AUTOITIE.document.close

Do

Sleep(100)

Until Not $AUTOITIE.Busy

Local $AUTOITIEOBJ = $AUTOITIE.document.body

If Not IsObj($AUTOITIEOBJ) Then Return SetError(3, 0, 0)

$AUTOITIEOBJ.setAttribute ("params", 1)

Local $AUTOITIEHANDLER = ObjEvent($AUTOITIEOBJ, "IEEvent_")

$AIEERRHANDLER = ObjEvent("AutoIt.Error", "AIEErrorHandler");

WinSetTrans($AUTOITPOPUP, "", 1) ;set the window invisible.

GUISetState(@SW_SHOWNOACTIVATE)

$AUTOITIE_EVENT = 0

WinSetOnTop($AUTOITPOPUP, "", 1)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $AUTOITPOPUP, "int", 0, "long", 0x00090000);fade-out

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $AUTOITPOPUP, "int", $speed, "long", 0x00040008);slide-in from bottom

Local $sleeptime = TimerInit()

While TimerDiff($sleeptime) < $time

Sleep(10)

If $AUTOITIE_EVENT Then ExitLoop

WinSetOnTop($AUTOITPOPUP, "", 1)

WinSetOnTop($AUTOITPOPUP, "", 0)

WEnd

WinSetOnTop($AUTOITPOPUP, "", 1)

WinSetOnTop($AUTOITPOPUP, "", 0)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $AUTOITPOPUP, "int", $speed, "long", 0x00050004);slide-out to bottom

GUIDelete($AUTOITPOPUP)

$AUTOITIEHANDLER = 0

$AUTOITIEOBJ = 0

$AUTOITIE = 0

_AIESendReturn($aPopData[$POP_RETURN],$AUTOITIE_EVENT)

EndFunc ;==>_AIEShowPopup

;==============================================================================

;Check for set bit

;==============================================================================

Func _AIEHasBit($iVal, $iCompare)

Return ((BitAND($iVal, $iCompare) = $iCompare))

EndFunc ;==>_AIEHasBit

;==============================================================================

;very basic

;==============================================================================

Func _AIEPath2URL($sFile)

Local $temp = StringReplace($sFile, "\", "/")

$temp = StringReplace($temp, " ", "%20")

If StringLeft($temp, 3) = "htt" Or StringLeft($temp, 3) = "ftp" Then

Return $temp

Else

Return "file:///" & $temp

EndIf

EndFunc ;==>_AIEPath2URL

;==============================================================================

;change hex prefix for css

;==============================================================================

Func _AIEGetColor($color)

Return StringReplace($color, "0x", "#")

EndFunc ;==>_AIEGetColor

;==============================================================================

;create the html document

;==============================================================================

Func _AIEMakeBody($aPopData)

Local $size = 5

If $aPopData[$POP_FONTSIZE] > 0 And $aPopData[$POP_FONTSIZE] < 6 Then $size = $aPopData[$POP_FONTSIZE]

Local $html = '<html>'

$html &= "<head>"

$html &= _AIEGetScript()

$html &= _AIEGetStyle($aPopData)

$html &= "</head>"

$html &= "<body>"

$html &= '<div>'

If _AIEHasBit($aPopData[$POP_MESSAGE_TYPE], $PN_EXIT) Then

$html &= '<a name="exit_click" id="exit_btn" onclick="AutoitCallback(this)">'

;$html &= '<img class="floatRight" src="' & _AIEPath2URL("C:\Program Files\AutoIt3\Include\user\exit.bmp") & '">'

$html &= '<img class="floatRight" src="' & _AIEPath2URL("http://tbn0.google.com/images?q=tbn:MJ292oJj-ij2DM:http://www.c21sunbelt.com/images/close_button.gif") & '">'

$html &= '</a>'

EndIf

If _AIEHasBit($aPopData[$POP_MESSAGE_TYPE], $PN_TITLE) Then

If $aPopData[$POP_TITLE] <> "" Then

$html &= '<h' & $size & '>' & $aPopData[$POP_TITLE] & '</h' & $size & '>'

Else

$html &= '<h' & $size & '></h' & $size & '><br />'

EndIf

EndIf

$html &= ' </div>'

If $aPopData[$POP_MESSAGE] <> '' Then

$html &= '<div class="bkg"><p style="margin-left: 55px; font-size:' & $aPopData[$POP_FONTSIZE] & 'pt">'

$html &= '<a id="'

$html &= $aPopData[$POP_MESSAGE_TYPE] & '" onclick="AutoitCallback(this)">'

If _AIEHasBit($aPopData[$POP_MESSAGE_TYPE], $PN_LINK) Or _AIEHasBit($aPopData[$POP_MESSAGE_TYPE], $PN_FUNC) Then

$html &= '<u>'&_AIEFixCr($aPopData[$POP_MESSAGE]) & '</u></a>' & @LF

Else

$html &=_AIEFixCr($aPopData[$POP_MESSAGE]) & '</a>' & @LF

EndIf

EndIf

$html &= '<br /></p><br /></div>' & @LF

$html &= '</body></html>' & @LF

;ConsoleWrite($html&@LF)

Return $html

EndFunc ;==>_AIEMakeBody

Func _AIEFixCr($szString)

$szString = StringReplace($szString, @CRLF, "<br />")

$szString = StringReplace($szString, @CR, "<br />")

$szString = StringReplace($szString, @LF, "<br />")

Return $szString

EndFunc ;==>_AIEFixCr

;==============================================================================

;Create the css for the dialog

;==============================================================================

Func _AIEGetStyle($aPopData)

Local $szStyle = '<style>' & @LF

$szStyle &= 'body {overflow: hidden; background-color: ' & _AIEGetColor($aPopData[$POP_BACKGROUND1]) & ';' & @LF

$szStyle &= 'color:' & _AIEGetColor($aPopData[$POP_FOREGROUND]) & ';' & @LF

If $aPopData[$POP_USEGRADIENT] Then

$szStyle &= " filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=" & $aPopData[$POP_GRAD_TYPE] & ", StartColorStr='" & _AIEGetColor($aPopData[$POP_BACKGROUND1]) & "', EndColorStr='" & _AIEGetColor($aPopData[$POP_BACKGROUND2]) & "'); }" & @LF

Else

$szStyle &= " }" & @LF

EndIf

If BitAND($aPopData[$POP_MESSAGE_TYPE], $PN_LINK) <> $PN_LINK Then

$szStyle &= 'a{color:' & _AIEGetColor($aPopData[$POP_FOREGROUND]) & '; text-decoration: none; }' & @LF

EndIf

$szStyle &= 'img.floatLeft { float: left; margin: 4px; border: 0px;} ' & @LF

$szStyle &= 'img.floatRight { float: right; margin: 4px; border: 0px; } ' & @LF

$szStyle &= 'div.bkg {'

$szStyle &= 'background-image: url(' & _AIEPath2URL($aPopData[$POP_BACKGROUND_IMAGE]) & '); ' & @LF

; $szStyle &= 'background-position: 0 0; '& @LF

$szStyle &= 'background-repeat: no-repeat;}' & @LF

$szStyle &= '</style>' & @LF

Return $szStyle

EndFunc ;==>_AIEGetStyle

;==============================================================================

; Other peoples stuff

;==============================================================================

Func _GUIRegisterMsgProc($hWnd, $MsgID, $WParam, $LParam)

If $MsgID = $WM_COPYDATA Then

; We Recived a WM_COPYDATA Message

; $LParam = Pointer to a COPYDATA Struct

$vs_cds = DllStructCreate($StructDef_COPYDATA, $LParam)

; Member No. 3 of COPYDATA Struct (PVOID lpData;) = Pointer to custom Struct

$vs_msg = DllStructCreate($STRUCTDEF_AU3MESSAGE, DllStructGetData($vs_cds, 3))

Local $pop[17]

For $x =1 to 17

$pop[$x-1] = DllStructGetData($vs_msg, $x)

Next

_AIEShowPopup($pop)

ElseIf $MsgID = $WM_CLOSE Then

; We Recived a WM_CLOSE Message

Exit

EndIf

EndFunc ;==>_GUIRegisterMsgProc

Func _AIESendReturn($hWnd,$iEventId)

ToolTip("")

;WinWait("_AIEPOPUPRETURN")

If WinExists($hWnd) Then

; Get Handle of to the Reciver

$hwnd_Reciver = WinGetHandle($hWnd)

; Create Structs

$vs_cds = DllStructCreate($StructDef_COPYDATA)

$vs_msg = DllStructCreate($STRUCTDEF_AU3RETURN)

; Stuff the data into the custom Struct

DllStructSetData($vs_msg, 1, $iEventId)

; Now Put the information needed about the custom struct

; into the COPYDATA struct

DllStructSetData($vs_cds, 1, 1)

DllStructSetData($vs_cds, 2, DllStructGetSize($vs_msg))

DllStructSetData($vs_cds, 3, DllStructGetPtr($vs_msg))

; Send it out

DllCall('User32.dll', 'int', 'SendMessage', 'HWnd', $hwnd_Reciver, _

'Int', $WM_COPYDATA, 'int', 0, _

'Ptr', DllStructGetPtr($vs_cds))

EndIf

EndFunc

;Create the javascript for the dialog (modified)

; Author (s) : autoit Forum http : //bbs.yidabu.com/forum-2-1.html

Func _AIEGetScript()

Local $szScript = '<script type="text/javascript">' & @LF

$szScript &= 'function AutoitCallback(obj){var targetObj = document.body; targetObj.params = new function(){this.obj=obj;} }' & @LF

$szScript &= 'function keyDown(e){AutoitCallback(event.srcElement);}' & @LF

$szScript &= 'document.onbeforeactivate=keyDown;' & @LF

$szScript &= '</script>' & @LF

Return $szScript

EndFunc ;==>_AIEGetScript

;===============================================================================

; Function Name: IEEvent_onpropertychange

; Description : put the incident triggered the target Scientology, how to operate all

; Parameter(s):

; Requirement(s):

; Return Value(s):

; Author (s) : autoit Forum http : //bbs.yidabu.com/forum-2-1.html

;===============================================================================

Func IEEvent_onpropertychange()

ConsoleWrite("IEEvent_onpropertychange" & @LF)

Local $oElement = @COM_EventObj

If Not IsObj($oElement) Then Return False

If Not IsObj($oElement.params) Then Return False

If IsObj($oElement.params.obj) Then

$AUTOITIE_EVENT = $oElement.params.obj.getAttribute ("id")

EndIf

; just in case anything else triggers onpropertychange; just in case anything else triggers onpropertychange

$oElement.params = 1

EndFunc ;==>IEEvent_onpropertychange

Func IEEvent_($Eventname)

If $AUTOITIE_EVENT > 0 Then Return

Switch $Eventname

Case "onmouseup"

;

Case "onclick"

;ConsoleWrite("onclick"&@LF)

$AUTOITIE_EVENT = 1

Case "onmousemove"

;

Case Else

;ConsoleWrite($Eventname & @LF)

EndSwitch

EndFunc ;==>IEEvent_

Func _AIEErrorHandler()

Local $HexNumber

;===============================================================================

$HexNumber = Hex($AIEERRHANDLER.number, 8)

Local $msg = "COM Error with DOM!" & @CRLF & @CRLF & _

"err.description is: " & @TAB & $AIEERRHANDLER.description & @CRLF & _

"err.windescription:" & @TAB & $AIEERRHANDLER.windescription & @CRLF & _

"err.number is: " & @TAB & $HexNumber & @CRLF & _

"err.lastdllerror is: " & @TAB & $AIEERRHANDLER.lastdllerror & @CRLF & _

"err.scriptline is: " & @TAB & $AIEERRHANDLER.scriptline & @CRLF & _

"err.source is: " & @TAB & $AIEERRHANDLER.source & @CRLF & _

"err.helpfile is: " & @TAB & $AIEERRHANDLER.helpfile & @CRLF & _

"err.helpcontext is: " & @TAB & $AIEERRHANDLER.helpcontext

MsgBox(0, @AutoItExe, $msg)

Return SetError($HexNumber)

EndFunc ;==>_AIEErrorHandler

Edited by eltorro

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Very nice :)

Bug:

On the first popup I clicked the "x" I got an error saying:

"Line -1

Error: The requested action with this object has failed."

Windows XP SP2 here.

I was able to duplicate it once right after I read your reply. But I can't get it to do it again.

Edit:

I added a better COM error handler to the daemon script. If it happens again maybe this will give some more meaningful information.

I am posting it here because the first post is messing up when I try to edit the post.

Edit: Script removed. Reposted to first post.

Edited by eltorro

Share this post


Link to post
Share on other sites

I just tried it on another computer and it was fine there too. What version of IE are you running?

Share this post


Link to post
Share on other sites

Same error here with all popups created with it.


Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 

Share this post


Link to post
Share on other sites

Same error here with all popups created with it.

Edit the scripts to get rid of line breaks which are a result of copying from the forum. They are pretty obvious if you look.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I did that as well. There was a problem with a [ at the end.

Yes, but hopefully you realised that it should have been continued with the next line, ie '[' is not at the end.

Equally, the lines

===================

should be at the ends of the previous lines and not new lines.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Posted Image

Well, I tracked the source of the bug. I tracked it to the href attributes pointing to about:blank in the anchor tags. IE7 doesn't like it.

I posted updated scripts in the first post.

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  
Followers 0