Jump to content

Recommended Posts

I'm not entirely sure what you want to do, but maybe this will give you some clues.

#include <MsgBoxConstants.au3> ; external library of constants (could also contain user-defined functions)

Main() ; run this function

Func Main()
    ; you can call hundreds of functions here
    FirstOfMany()
    ; you can call hundreds of functions here too
EndFunc

Func FirstOfMany() ; bespoke function
    MsgBox($MB_OK, "Title", "Hello Visitor") ; native function
EndFunc

Edit: I thought this was posted in General Help and Support. Unfortunately I don't have time to read the whole thread right now. It was a general question you asked.

Edited by czardas
Link to post
Share on other sites

I am newbie. I have a huge script. I do not understand how the function body can contain other functions, so it does not work. So I do not know how to run my code in the service. Here is a small part of my script:

Func _winapi_getlasterror($curerr = @error, $curext = @extended)
    Local $aresult = DllCall("kernel32.dll", "dword", "GetLastError")
    Return SetError($curerr, $curext, $aresult[0])
EndFunc

Func _winapi_setlasterror($ierrcode, $curerr = @error, $curext = @extended)
    DllCall("kernel32.dll", "none", "SetLastError", "dword", $ierrcode)
    Return SetError($curerr, $curext)
EndFunc

Func _choosecolor($ireturntype = 0, $icolorref = 0, $ireftype = 0, $hwndownder = 0)
    Local $custcolors = "dword[16]"
    Local $tchoose = DllStructCreate($tagchoosecolor)
    Local $tcc = DllStructCreate($custcolors)
    If $ireftype = 1 Then
        $icolorref = Int($icolorref)
    ElseIf $ireftype = 2 Then
        $icolorref = Hex(String($icolorref), 6)
        $icolorref = "0x" & StringMid($icolorref, 5, 2) & StringMid($icolorref, 3, 2) & StringMid($icolorref, 1, 2)
    EndIf
    DllStructSetData($tchoose, "Size", DllStructGetSize($tchoose))
    DllStructSetData($tchoose, "hWndOwnder", $hwndownder)
    DllStructSetData($tchoose, "rgbResult", $icolorref)
    DllStructSetData($tchoose, "CustColors", DllStructGetPtr($tcc))
    DllStructSetData($tchoose, "Flags", BitOR($__miscconstant_cc_anycolor, $__miscconstant_cc_fullopen, $__miscconstant_cc_rgbinit))
    Local $aresult = DllCall("comdlg32.dll", "bool", "ChooseColor", "ptr", DllStructGetPtr($tchoose))
    If @error Then Return SetError(@error, @extended, -1)
    If $aresult[0] = 0 Then Return SetError(-3, -3, -1)
    Local $color_picked = DllStructGetData($tchoose, "rgbResult")
    If $ireturntype = 1 Then
        Return "0x" & Hex(String($color_picked), 6)
    ElseIf $ireturntype = 2 Then
        $color_picked = Hex(String($color_picked), 6)
        Return "0x" & StringMid($color_picked, 5, 2) & StringMid($color_picked, 3, 2) & StringMid($color_picked, 1, 2)
    ElseIf $ireturntype = 0 Then
        Return $color_picked
    Else
        Return SetError(-4, -4, -1)
    EndIf
EndFunc

Func _choosefont($sfontname = "Courier New", $ipointsize = 10, $icolorref = 0, $ifontweight = 0, $iitalic = False, $iunderline = False, $istrikethru = False, $hwndowner = 0)
    Local $italic = 0, $underline = 0, $strikeout = 0
    Local $lngdc = __misc_getdc(0)
    Local $lfheight = Round(($ipointsize * __misc_getdevicecaps($lngdc, $logpixelsx)) / 72, 0)
    __misc_releasedc(0, $lngdc)
    Local $tchoosefont = DllStructCreate($tagchoosefont)
    Local $tlogfont = DllStructCreate($taglogfont)
    DllStructSetData($tchoosefont, "Size", DllStructGetSize($tchoosefont))
    DllStructSetData($tchoosefont, "hWndOwner", $hwndowner)
    DllStructSetData($tchoosefont, "LogFont", DllStructGetPtr($tlogfont))
    DllStructSetData($tchoosefont, "PointSize", $ipointsize)
    DllStructSetData($tchoosefont, "Flags", BitOR($cf_screenfonts, $cf_printerfonts, $cf_effects, $cf_inittologfontstruct, $cf_noscriptsel))
    DllStructSetData($tchoosefont, "rgbColors", $icolorref)
    DllStructSetData($tchoosefont, "FontType", 0)
    DllStructSetData($tlogfont, "Height", $lfheight)
    DllStructSetData($tlogfont, "Weight", $ifontweight)
    DllStructSetData($tlogfont, "Italic", $iitalic)
    DllStructSetData($tlogfont, "Underline", $iunderline)
    DllStructSetData($tlogfont, "Strikeout", $istrikethru)
    DllStructSetData($tlogfont, "FaceName", $sfontname)
    Local $aresult = DllCall("comdlg32.dll", "bool", "ChooseFontW", "ptr", DllStructGetPtr($tchoosefont))
    If @error Then Return SetError(@error, @extended, -1)
    If $aresult[0] = 0 Then Return SetError(-3, -3, -1)
    Local $fontname = DllStructGetData($tlogfont, "FaceName")
    If StringLen($fontname) = 0 AND StringLen($sfontname) > 0 Then $fontname = $sfontname
    If DllStructGetData($tlogfont, "Italic") Then $italic = 2
    If DllStructGetData($tlogfont, "Underline") Then $underline = 4
    If DllStructGetData($tlogfont, "Strikeout") Then $strikeout = 8
    Local $attributes = BitOR($italic, $underline, $strikeout)
    Local $size = DllStructGetData($tchoosefont, "PointSize") / 10
    Local $colorref = DllStructGetData($tchoosefont, "rgbColors")
    Local $weight = DllStructGetData($tlogfont, "Weight")
    Local $color_picked = Hex(String($colorref), 6)
    Return StringSplit($attributes & "," & $fontname & "," & $size & "," & $weight & "," & $colorref & "," & "0x" & $color_picked & "," & "0x" & StringMid($color_picked, 5, 2) & StringMid($color_picked, 3, 2) & StringMid($color_picked, 1, 2), ",")
EndFunc

 

Link to post
Share on other sites

If I put my functions in the body of Main (), then an error occurs.  Did something like this:

Func _main($iArg, $sArgs)
While $bServiceRunning 
#region --> insert your running code here
Func _winapi_getlasterror($curerr = @error, $curext = @extended)
    Local $aresult = DllCall("kernel32.dll", "dword", "GetLastError")
    Return SetError($curerr, $curext, $aresult[0])
EndFunc

Func _winapi_setlasterror($ierrcode, $curerr = @error, $curext = @extended)
    DllCall("kernel32.dll", "none", "SetLastError", "dword", $ierrcode)
    Return SetError($curerr, $curext)
EndFunc
#endregion  --> insert your running code here
WEnd
EndFunc   ;==>main

 

Link to post
Share on other sites

@musicstashall If you had posted your question in "General Help and Support", I'm sure you would have had a better response. I suggest you ask a moderator to move the relevant posts to that section of the forum.

Regarding your code - do not place function declarations inside other functions or inside loops. You can only call them from within a function. Some of the functions you are using are part of the AutoIt UDF libraries. You should look these functions up in the help file to see which libraries need to be included. When you include a library (as I did at the start of my example), you only need to call the function - not write out the full code. Once again I advise you check the helpfile and look at the keyword "Func". Use the SciTE4AutoIt editor to run your code, because it will show you on which lines errors occur. Do some basic tutorials and get a feel for AutoIt before embarking on more complicated projects.

BTW: You don't need to use a function called main().

Edited by czardas
Link to post
Share on other sites
6 minutes ago, argumentum said:

I may be wrong ( I'm usually not ), but this is not your script,

Yes, not mine, this is what I found before, there with WinIP ... I'm very sorry. But yesterday I found what I needed. Actually, here, with what and should begin. The code below should be run as a service. Tried it in different ways - it does not work. Can this even work as a service? The script recolors the CMD window in Aero Glass.

#include <Misc.au3>
#include <Process.au3>
#Include <WinAPI.au3>
;Opt("TrayMenuMode",1) 

Global Const $HSHELL_WINDOWCREATED = 1
Global Const $HSHELL_WINDOWACTIVATED = 4;
Global Const $HWND_MESSAGE  = -3
Global $bHook = 1

$hGui = GUICreate("", 10, 10, -1, 0,-1,-1,$HWND_MESSAGE)
GUIRegisterMsg(_WinAPI_RegisterWindowMessage("SHELLHOOK"), "HookProc")
ShellHookWindow($hGui, $bHook)
ClearMemory()
$About = TrayCreateItem("About")
TrayCreateItem("")
$Exit = TrayCreateItem("Exit")

While 1
    Switch TrayGetMsg()
        Case $About
            MsgBox("","","Glass CMD for Windows Vista")
        Case $Exit
            Exit
    EndSwitch
WEnd

Func HookProc($hWnd, $Msg, $wParam, $lParam)
    Switch $wParam 
        Case $HSHELL_WINDOWCREATED
        If _ProcessGetName(WinGetProcess($lParam)) = "cmd.exe" Then 
            EnableBlurBehind($lParam)
            If @error Then MsgBox(16, "Glass CMD", "You are not running Vista!")
            ClearMemory()
        EndIf
    Case $HSHELL_WINDOWACTIVATED
        ClearMemory()
    EndSwitch
EndFunc

Func ShellHookWindow($hWnd, $bFlag)
    Local $sFunc = 'DeregisterShellHookWindow'
    If $bFlag Then $sFunc = 'RegisterShellHookWindow'
    Local $aRet = DllCall('user32.dll', 'int', $sFunc, 'hwnd', $hWnd)
    Return $aRet[0]
EndFunc

Func EnableBlurBehind($hWnd)
    Const $DWM_BB_ENABLE = 0x00000001
    $Struct = DllStructCreate("dword;int;ptr;int")
    DllStructSetData($Struct,1,$DWM_BB_ENABLE)
    DllStructSetData($Struct,2,"1")
    DllStructSetData($Struct,4,"1")
    DllCall("dwmapi.dll","int","DwmEnableBlurBehindWindow","hwnd",$hWnd,"ptr",DllStructGetPtr($Struct))
EndFunc

Func ClearMemory()
    Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

Func OnAutoItExit()
    If $hGui Then
        ShellHookWindow($hGui, 0)
    EndIf
EndFunc  ;==>OnAutoItExit

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By AutoJohn
      Hi,
      Part of my standard template for a new project is including the lines:
          #AutoIt3Wrapper_Run_Au3Stripper=y ;Run Au3Stripper before compilation (Default=n)
          #Au3Stripper_Parameters=/mo ;     Use the parameters as listed above
      I extensively use bookmarks to jump back and forth between sections of code while debugging and I am experiencing an annoyance that I'm hoping someone could steer me towards a "better" solution.
      The problem is when I go to compile code, all of my bookmarks get deleted.
      I have determined that if I comment out the line    #AutoIt3Wrapper_Run_Au3Stripper then the issue no longer happens and my bookmarks remain.
      Are there some other properties I could be setting somewhere to keep the line in place yet not destroy my bookmarks on every compile?
      Thanks
      SciTE Version 3.7.3     Feb 16 2017 21:41:17
      AutoIT 3.3.14.5
    • By DonChunior
      Introduction 
      In the course of my research for a project involving, among other things, the transfer of large amounts of data, I came across the BITS service and from that the idea for this UDF was born.
      For a brief overview, I'll quote from Microsoft's BITS website (https://docs.microsoft.com/en-us/windows/win32/bits/background-intelligent-transfer-service-portal).
      Availability 🛒
      The BITS UDF can be downloaded from my GitHub repository:
      🔗 https://github.com/DonChunior/BITS-UDF
      Comments 💬
      Currently, only an alpha version of the UDF is available.
      This contains by and large the full functionality of the object interfaces, but still completely lacks error checking and handling.
      I will implement this in the upcoming beta version.
      Therefore I ask you to use the UDF only for testing purposes but not in productive code!
      Acknowledgment 🤝
      Many thanks to @Nine and @Danyfirex.
      You helped me very well in solving some tricky problems.
    • By SgtHugoStiglitz
      HI people,
                        I got a questions, I maintain code in autoIT and every time I compile a new version or modification, Scite generate 2 folders. One folder is finish by released and the other is tentative. I try to make some google search, but never find answer would satisfied myself. The dev who was maintain it before were using AutoIt3Wrapper_GUI, and I don't know if it's related. I look both folder, but they seem pretty identical, but I would like to know what it's the difference between those to folder. Anyone have a clue?
    • By Rhidlor
      I don't have any experience compiling AutoIt scripts or know of any best practices regarding said scripts so I was wondering, what are some of the options for passing data to complied scripts? Here's an example of what I mean by "option": Writing data to a text file, then running a script which reads the data from that text file.
      Thanks!
      I apologize if this topic is a little lackluster
    • By Skeletor
      Hey All,
      Yes, this is an odd request. 
      But is there a way to bulk up the size of the compiled program? 
      I know many want to reduce it's size, but I want to increase it.
      What methods do you suggest?
×
×
  • Create New...