Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/02/2017 in all areas

  1. If you look to output PDF's from your application (generate reports, graphics, tables etc), this UDF can be very useful. In the zip file are examples, images for testing and the UDF. Enjoy! I have removed some of the previous versions due to the lack of space, but they are still available on request. [uPDATED June 22] v.1.0.1 Added more page formats, two more fonts, example table ... [uPDATED July 30] v1.0.2 Solved issues with Adobe Reader. StuffByDennis added two more functions (Thanks Dennis). [uPDATED August 10] v1.0.3 Rewrote entirely _LoadResImage function - optimize for speed/size of the pdf. Fixed the Example_Image2PDF Thanks to xavierh for finding a missing space in the _LoadFontTT function (even it looks insignificant, that solved an issue with text justification when using Adobe Reader, not Foxit Reader) Total downloads old versions: 2044 + 21 Version 1.0.3: MPDFv103.zip
    1 point
  2. Kronitron, Add some error-checking to your code to confirm you have an array before trying to access it. M23
    1 point
  3. As far as I rember here on the forum are 2 udf for SAPI. But as I see you are looking for voice recognition?
    1 point
  4. n3wbie, <snip> M23 Edit: I see on re-reading that you want to get text from an audio file - not what I first understood.
    1 point
  5. You could use _ArraySearch to receive the index or _ArrayFindall to find all indexes _ArraySearch example: #include <Array.au3> Global $aResult[0][2] Search('Cat') _ArrayDisplay($aResult) Func Search($sSearch) Local $hostfile = @ScriptDir & '\Search.ini' Local $aSection = IniReadSection($hostfile, "Search Animals") If @error Then MsgBox(4096, "Error", "Unable to read section.") Return EndIf Local $iSearch = _ArraySearch($aSection, $sSearch, 0, 0, 0, 0, 1, 1) If $iSearch = -1 Then MsgBox(4096, 'Error', 'Unable to find ' & $sSearch) Return EndIf _ArrayAdd($aResult, $sSearch & '|' & $iSearch) EndFunc
    1 point
  6. Here is a simple example at draws the pixels of a rectangle to the desktop, #include <WinAPI.au3> _WinAPI_DrawRect(20, 20, @DesktopWidth / 2, @DesktopHeight / 2, 0x0000FF) Func _WinAPI_DrawRect($start_x, $start_y, $iWidth, $iHeight, $iColor) Local $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) Local $tRect = DllStructCreate($tagRECT) DllStructSetData($tRect, 1, $start_x) DllStructSetData($tRect, 2, $start_y) DllStructSetData($tRect, 3, $iWidth) DllStructSetData($tRect, 4, $iHeight) Local $hBrush = _WinAPI_CreateSolidBrush($iColor) _WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $hBrush) ; clear resources _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC(0, $hDC) EndFunc ;==>_WinAPI_DrawRect Here is a more complex example that draws your rectangles to a layered window on the desktop. #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; Modified from http://www.autoitscript.com/forum/index.php?s=&showtopic=97126&view=findpost&p=698489 Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client Main() Func Main() Local $hBitmap, $hGui, $hGraphic, $hImage2, $GuiSizeX = @DesktopWidth, $GuiSizeY = @DesktopHeight Local $GuiSize = 70, $hWnd, $hDC, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend Local $iX1 = 0, $iY1 = 0, $tPoint, $pPoint, $hBMPBuff, $hGraphicGUI, $hPen, $aMPos, $aMPosNew Local $iOpacity = 255, $dll = DllOpen("user32.dll") $hGui = GUICreate("L1", $GuiSizeX, $GuiSizeY, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetState() _GDIPlus_Startup() $hWnd = _WinAPI_GetDC(0) $hDC = _WinAPI_CreateCompatibleDC($hWnd) $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $GuiSizeX, $GuiSizeY) _WinAPI_SelectObject($hDC, $hBitmap) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphic) $hGraphicGUI = _GDIPlus_ImageGetGraphicsContext($hBMPBuff) _GDIPlus_GraphicsClear($hGraphic); Add ,0x01000000) to disable underling desktop $hPen = _GDIPlus_PenCreate(0xffff0000, 3) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $GuiSizeX);$iWidth ) DllStructSetData($tSize, "Y", $GuiSizeY);$iHeight) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) $tPoint = DllStructCreate($tagPOINT); Create point destination structure here $pPoint = DllStructGetPtr($tPoint); Create pointer to this dll data structure, $pPTDest parameter DllStructSetData($tPoint, "X", $iX1) DllStructSetData($tPoint, "Y", $iY1) _WinAPI_UpdateLayeredWindow($hGui, $hWnd, $pPoint, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) Do Select Case _IsPressed("01", $dll); Ctrl mouse button to move $aMPos = MouseGetPos() Do Sleep(10) Until Not _IsPressed("01", $dll) $aMPosNew = MouseGetPos() ;_GDIPlus_GraphicsDrawLine($hGraphic, $aMPosNew[0], $aMPosNew[1], $aMPos[0], $aMPos[1], $hPen) ; I used _Iif() from Misc.au3 instead using of _Min() from Math.au3. _GDIPlus_GraphicsDrawRect($hGraphic, _Iif($aMPos[0] < $aMPosNew[0], $aMPos[0], $aMPosNew[0]), _Iif($aMPos[1] < $aMPosNew[1], $aMPos[1], $aMPosNew[1]), Abs($aMPosNew[0] - $aMPos[0]), Abs($aMPosNew[1] - $aMPos[1]), $hPen) _WinAPI_UpdateLayeredWindow($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) Case _IsPressed("04", $dll) Or _IsPressed("11", $dll) ; Middle mouse button 0r Ctrl key <======= Clear screen of rectangles. _GDIPlus_GraphicsClear($hGraphic) _WinAPI_UpdateLayeredWindow($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) EndSelect Sleep(50) Until _IsPressed("1B", $dll); ESC key DllClose($dll) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphicGUI) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_ReleaseDC(0, $hWnd) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hDC) _GDIPlus_Shutdown() EndFunc ;==>Main
    1 point
  7. Beege

    Text-to-Speech UDF

    Here is a small UDF and example for using Microsoft's Text-to-Speech interface. Please leave some feedback. Let me know if you have any problems or don't understand something. Also the example uses all three microsoft voices. If Mike and Mary are not installed they can be downloaded here UDF: ; #FUNCTION# ==================================================================================================================== ; Name...........: _StartTTS ; Description ...: Creates a object to be used with Text-to-Speak Functions. ; Syntax.........: _StartTTS() ; Parameters ....: ; Return values .: Success - Returns a object ; Author ........: bchris01 ; Example .......: Yes ; =============================================================================================================================== Func _StartTTS() Return ObjCreate("SAPI.SpVoice") EndFunc ;==>_StartTTS ; #FUNCTION# ==================================================================================================================== ; Name...........: _SetRate ; Description ...: Sets the rendering rate of the voice. (How fast the voice talks.) ; Syntax.........: _SetRate(ByRef $Object, $iRate) ; Parameters ....: $Object - Object returned from _StartTTS(). ; $iRate - Value specifying the speaking rate of the voice. Supported values range from -10 to 10 ; Return values .: None ; Author ........: bchris01 ; Example .......: Yes ; =============================================================================================================================== Func _SetRate(ByRef $Object, $iRate); Rates can be from -10 to 10 $Object.Rate = $iRate EndFunc ;==>_SetRate ; #FUNCTION# ==================================================================================================================== ; Name...........: _SetVolume ; Description ...: Sets the volume of the voice. ; Syntax.........: _SetVolume(ByRef $Object, $iVolume) ; Parameters ....: $Object - Object returned from _StartTTS(). ; $iVolume - Value specifying the volume of the voice. Supported values range from 0-100. Default = 100 ; Return values .: None ; Author ........: bchris01 ; Example .......: Yes ; =============================================================================================================================== Func _SetVolume(ByRef $Object, $iVolume);Volume $Object.Volume = $iVolume EndFunc ;==>_SetVolume ; #FUNCTION# ==================================================================================================================== ; Name...........: _SetVoice ; Description ...: Sets the identity of the voice used for text synthesis. ; Syntax.........: _SetVoice(ByRef $Object, $sVoiceName) ; Parameters ....: $Object - Object returned from _StartTTS(). ; $sVoiceName - String matching one of the voices installed. ; Return values .: Success - Sets object to voice. ; Failure - Sets @error to 1 ; Author ........: bchris01 ; Example .......: Yes ; =============================================================================================================================== Func _SetVoice(ByRef $Object, $sVoiceName) Local $VoiceNames, $VoiceGroup = $Object.GetVoices For $VoiceNames In $VoiceGroup If $VoiceNames.GetDescription() = $sVoiceName Then $Object.Voice = $VoiceNames Return EndIf Next Return SetError(1) EndFunc ;==>_SetVoice ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetVoices ; Description ...: Retrives the currently installed voice identitys. ; Syntax.........: _GetVoices(ByRef $Object[, $Return = True]) ; Parameters ....: $Object - Object returned from _StartTTS(). ; $bReturn - String of text you want spoken. ; |If $bReturn = True then a 0-based array is returned. ; |If $bReturn = False then a string seperated by delimiter "|" is returned. ; Return values .: Success - Returns an array or string containing installed voice identitys. ; Author ........: bchris01 ; Example .......: Yes ; =============================================================================================================================== Func _GetVoices(ByRef $Object, $bReturn = True) Local $sVoices, $VoiceGroup = $Object.GetVoices For $Voices In $VoiceGroup $sVoices &= $Voices.GetDescription() & '|' Next If $bReturn Then Return StringSplit(StringTrimRight($sVoices, 1), '|', 2) Return StringTrimRight($sVoices, 1) EndFunc ;==>_GetVoices ; #FUNCTION# ==================================================================================================================== ; Name...........: _Speak ; Description ...: Speaks the contents of the text string. ; Syntax.........: _Speak(ByRef $Object, $sText) ; Parameters ....: $Object - Object returned from _StartTTS(). ; $sText - String of text you want spoken. ; Return values .: Success - Speaks the text. ; Author ........: bchris01 ; Example .......: Yes ; =============================================================================================================================== Func _Speak(ByRef $Object, $sText) $Object.Speak($sText) EndFunc ;==>_SpeakTTS.au3 Example: #include <TTS.au3> $Default = _StartTTS() If Not IsObj($Default) Then MsgBox(0, 'Error', 'Failed create object') Exit EndIf _Speak($Default, 'Hello my name is Sam. I am the default voice. Here are the other voices you have to choose from.') MsgBox(0, 'Voices installed', StringReplace(_GetVoices($Default, False), '|', @CRLF)) $aVoiceSelection = _GetVoices($Default) $Mike = _StartTTS() _SetVoice($Mike, 'Microsoft Mike') If @error Then _Speak($Default, 'Mike is Not installed.') $Mike = False EndIf $Mary = _StartTTS() _SetVoice($Mary, $aVoiceSelection[1]) If @error Then _Speak($Default, 'Mary is Not installed.') $Mary = False EndIf If IsObj($Mike) Then _Speak($Mike, 'Hello my name is Mike.') If IsObj($Mary) Then _Speak($Mary, 'Hello my name is Mary.') _SetRate($Default, 5) _Speak($Default, 'This is Sam talking really really fast.') _SetRate($Default, -5) _Speak($Default, 'This is Sam talking slow.')
    1 point
  8. I have code somewhere that provides an example. If I find the link I'll post in this post. Edit: I couldn't find the code I used, but I remembered something called "AnyGUI" from years ago. Anyway, I don't know if it still works, but if you look at the AnyGUI.au3, worse case, you can see how to handle it. This way you won't need to worry about moving the gui/control, it will be embedded in the window itself. http://www.autoitscript.com/forum/index.php?showtopic=9517&view=findpost&p=638738 Edit 2: After looking at it, it certainly could be written much better, but I think it will serve the needs you are wanting as it is.
    1 point
  9. Decided to remove the entire thing as an AdLibRegister since it was slowing down the program. Instead, I made a separate peripheral program to do this for me. Dramatically boosts performance of the main program and improves the performance of the window mover itself. Now I call it from the main program with: ;Run the window watching program Global $watchprog = Run(@ScriptDir & "\Tools\Watch.exe " & $GUITitle & " " & $win & " " & WinGetProcess($GUITitle) & " " & $Triangle[0] & " " & $Triangle[1]) ;Let's keep this here in case some idiot deletes the watcher file If $watchprog = 0 Then AdlibRegister("WatchWindow", 750) And here is the code for Watch.exe: Opt("WinTitleMatchMode", 3) Opt("TrayIconHide", 1) If $CmdLine[0] <= 0 Then Exit Global $GUITitle = $CmdLine[1] Global $ParentTitle = $CmdLine[2] Global $process = $CmdLine[3] Global $T1 = $CmdLine[4] ;this is a x offset Global $T2 = $CmdLine[5] ;this is a y offset Global $ParentHandle GetWindow() While 1 WatchWindow() Sleep(50) WEnd Func GetWindow() $winlist = WinList($ParentTitle) If $winlist[0] > 0 Then For $x = 0 to UBound($winlist) - 1 If StringLen($winlist[$x]) = 3 Then $ParentHandle = WinGetHandle($winlist[$x]) ExitLoop EndIf Next Exit 1 Exit EndFunc Func WatchWindow() $pos = WinGetPos($ParentHandle) If WinActive($ParentHandle) Then ;~ If WinGetState($GUITitle) >= 0 Then WinSetState($GUITitle, "", @SW_SHOW) Sleep(10) ElseIf WinExists($ParentHandle) = 0 Then MsgBox(4096, "Closed", "Parent window has closed and will now quit.", 60) ProcessClose($process) Exit 1 Else If WinActive($GUITitle) Then Return ;~ If WinGetState($ParentTitle) > 2 Then WinSetState($GUITitle, "", @SW_HIDE) EndIf ;Set Z Order ; This is the _WinAPI_SetWindowPos function to put the toolbar just above the NonAutoIt app in the z-order DllCall("user32.dll", "bool", "SetWindowPos", "hwnd", $GUITitle, "hwnd", $ParentHandle, "int", $pos[0] + $T1 - 5, "int", $pos[1] + $T2 + 130, "int", 200, "int", 200, "uint", 0x0010) ; $SWP_NOACTIVATE ;~ Sleep(10) WinMove($GUITitle, "", $pos[0] + $T1 - 5, $pos[1] + $T2 + 130) EndFunc ;==>WatchWindow On a side note, the option WinTitleMatchMode doesn't seem to work with the option 3 (exact match). It will return partial matches (example, I have a window open named Watch, and a window opened named Watcher. WinList("Watch") will return both Watch and Watcher, and WinGetPos("Watch") also has a chance of falsely returning Watcher's position)
    1 point
  10. Affe, Looks pretty close to what I use: Func _GUI_Match() ; If NonAutoItApp minimised, then hide GUI and do nothing If BitAND(WinGetState($hNonAutoItApp_Wnd), 16) = 16 Then GUISetState(@SW_HIDE, $hGUI) $fGUI_Vis = False ; If NonAutoItApp not minimised Else ; Hide GUI when NonAutoItApp not active If BitAND(WinGetState($hNonAutoItApp_Wnd), 8) <> 8 And $fGUI_Vis = True Then GUISetState(@SW_HIDE, $hGUI) $fGUI_Vis = False ; Show GUI when it is ElseIf BitAND(WinGetState($hNonAutoItApp_Wnd), 8) = 8 And $fGUI_Vis = False Then GUISetState(@SW_SHOWNOACTIVATE, $hGUI) $fGUI_Vis = True EndIf ; If visible check GUI position If $fGUI_Vis = True Then ; Move if required Local $aNonAutoItApp_Pos = WinGetPos($hNonAutoItApp_Wnd) If $aNonAutoItApp_Pos[0] <> $iLast_X Or $aNonAutoItApp_Pos[1] <> $iLast_Y Then $iLast_X = $aNonAutoItApp_Pos[0] $iLast_Y = $aNonAutoItApp_Pos[1] Local $aNonAutoItApp_Client_Size = WinGetClientSize($hNonAutoItApp_Wnd) WinMove($hGUI, '', $aNonAutoItApp_Pos[0] + 360, $aNonAutoItApp_Pos[1] + ($aNonAutoItApp_Pos[3] - $aNonAutoItApp_Client_Size[1]) - 5, $iGUI_Width, 18) EndIf EndIf EndIf EndFunc ;==>_GUI_MatchBut then I do not move the app I have attached to very much, so the "choppiness" is not that much of a problem. M23
    1 point
  11. Hello everyone, after searching this forum ower and ower again i couldn't find solution to my problem or i didn't understand hints that were given in some of the threads i found. Let me explain what am i trying to do. I have a program that hangs from time to time for many different reasons. Now what am i trying to do is to write an AutoIt script that will be checking if program is running as it should or if its hanged/crashed/not responding (i dont know if those program states are all the same). After some searching on forum i found a code which is calling a user32.dll function called "IsHungAppWindow" (see code bolow): If _NotResponding("Calculator", "", 1) Then MsgBox(1,"Test","Process hanged") Else MsgBox(1,"Test","Process not hanged") EndIf Func _NotResponding($title, $text, $closeIfHung = 0) $hWnd = WinGetHandle($title, $text) If $hWnd == "0" Then MsgBox(1,"Tets","Window not found") EndIf $retArr = DllCall("user32.dll", "int", "IsHungAppWindow", "hwnd", $hWnd) If @error == 0 Then If $retArr[0] == 1 Then If $closeIfHung Then ProcessClose(WinGetProcess($title, $text)) EndIf Return 1 EndIf Else Return 0 EndIf EndFunc I was using windows Calculator to test this code. So what i did was i downloaded some program from CodeProject which is desigend to Suspend process ... and above posted code does not return correct MSGBox. I am not sure if code doesnt work or the entire logic is wrong? I hope some of you could help me a bit. Thank you for your replays. Best regards.
    1 point
  12. That was in the example I gave above pecloe
    1 point
  13. try this #include <GuiConstants.au3> GuiCreate("",400, 300, -1,-1, BitOr($WS_POPUP,$WS_DLGFRAME), $WS_EX_TOOLWINDOW) GUISetBkColor(0xadd8e6);;; lightblue GuiSetState() While 1 Sleep(1000) WEnd
    1 point
  14. well.. i'll say this.. this was a pain in the ass! it works, but causes problems #Include <Constants.au3> #NoTrayIcon Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. $prefsitem = TrayCreateItem("Preferences") TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $prefsitem Msgbox(64,"Preferences:","OS:" & @OSVersion) Case $msg = $aboutitem Msgbox(64,"About:","AutoIt3-Tray-sample") Case $msg = $exititem ExitLoop EndSelect WEnd Exit while this worked perfectly for me, no problems. #notrayicon Opt("TrayMenuMode",1) Opt("TrayOnEventMode",1) $Preferences_tray = TrayCreateItem("Preferences") TrayItemSetOnEvent($Preferences_tray,"_Preferences") $About_tray = TrayCreateItem("About") TrayItemSetOnEvent($About_tray,"_About") $exit_tray = TrayCreateItem("Exit") TrayItemSetOnEvent($exit_tray,"_Exit") TraySetState() While 1 ;Script sleep (100) WEnd Func _About() Msgbox(64,"About:","AutoIt3-Tray-sample") EndFunc Func _Preferences() Msgbox(64,"Preferences:","OS:" & @OSVersion) EndFunc Func _Exit() exit EndFunc
    1 point
×
×
  • Create New...