Jump to content
Sign in to follow this  
criticalmass

Make a button a drop down menu

Recommended Posts

criticalmass

So all I can say is I am learning a lot from these forums. I been posting less and less. My program that I have been working on I have been given a task to make one of the buttons a drop down menu. So I looked on the forums and I found out how to do it. But I am running into a ton of problems with it because its already in a GUI and my program is in a GUI so i am getting a ton of errors.

This is what I got so far

; Create Form
GUICreate($WINTITLE, 400, 400, 0, 0, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
; 1. Screen Capture
$okshot = GUICtrlCreateButton("Screen Capture", 5, 10, 95, 26)
; 2.Error Rerport
$okbutton = GUICtrlCreateButton("Error Report", 105, 10, 85, 26)
; 3. TOOLS
$oktools = GUICtrlCreateButton("Tools", 195, 10, 80, 26)
;. 4. Wiki Support
$okwiki = GUICtrlCreateButton("Wiki Support", 285, 10, 80, 26)

; Create Labels
CreateLabels()

; Create Inputs
CreateInputs()

The button "Tools" I wanting that button to have a drop down so under it I can add the following

Restart Services

- Restart Apache

- Restart SQL Server

Stop Services

- SQL

- Netlib

- Coss Batch

Task Manger

- Open Task Manager

Remove Netlib

- Del C:\WINNT\Netlib

- Del C:\Windows\Netlib

Remove Registry Keys

- MSSQL

- COSS

- Other

Any help would be great

Share this post


Link to post
Share on other sites
Melba23

criticalmass,

A button with the $BS_SPLITBUTTON style can have a menu attached quite easily - this thread shows how to code it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
criticalmass

amazing thank you

Share this post


Link to post
Share on other sites
criticalmass

yea i tried that and the button disappeared i was like wtf but i guess that would work if i can figure it out on xp.

; Create Form
GUICreate($WINTITLE, 400, 400, 0, 0, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
; 1. Screen Capture
$okshot = GUICtrlCreateButton("Screen Capture", 5, 10, 95, 26)
; 2.Error Rerport
$okbutton = GUICtrlCreateButton("Error Report", 105, 10, 85, 26)
; 3. TOOLS
$oktools = _GUICtrlButton_Create("Split Button", 195, 10, 120, 30, $BS_SPLITBUTTON)
     _GUICtrlButton_SetStyle($oktools, $WS_VISIBLE)
    _GUICtrlButton_SetSplitInfo($oktools)
    $restartapache = _GUICtrlButton_Create("Split Button 2", 195, 50, 120, 30, $BS_SPLITBUTTON)
     _GUICtrlButton_SetStyle($restartapache, $WS_VISIBLE)

For whatever reason "Split Button" says good bye and does not show up i have no idea wtf i am doing wrong. BTW i am on Win XP. This is a company computer so I cant upgrade

Edited by criticalmass

Share this post


Link to post
Share on other sites
taietel

criticalmass, look in the help file for the function GUICtrlCreateContextMenu. Example 2 is what you need.

[edit] If you really need an arrow next to the button, you can just create another button with an arrow on it:

GUICtrlCreateButton("6", $left, $top, $width, $height)
GUICtrlSetFont(-1, 12, 800, 0, "Webdings")
Edited by taietel

Share this post


Link to post
Share on other sites
guinness

Its Vista+ Only. This is what you're looking for Windows XP >>

Edit: Or in the Help File :)

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
criticalmass

awesome got it figured out i think if i need some help in a bit i may ask

Share this post


Link to post
Share on other sites
taietel

An example based from the one in the help file:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Example", 623, 449, 192, 114)
$hBtnClick = GUICtrlCreateButton("Click", 64, 80, 75, 25)
$hBtnArrow = GUICtrlCreateButton("6", 136, 80, 19, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Webdings")
$hBtnArrowContext = GUICtrlCreateContextMenu($hBtnArrow)
$MenuItem4 = GUICtrlCreateMenuItem("Open your mind", $hBtnArrowContext)
$MenuItem3 = GUICtrlCreateMenuItem("Close your eyes", $hBtnArrowContext)
$MenuItem2 = GUICtrlCreateMenuItem("", $hBtnArrowContext)
$MenuItem1 = GUICtrlCreateMenuItem("Get out of here!", $hBtnArrowContext)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $MenuItem1
            Exit
        Case $hBtnClick, $hBtnArrow
            ShowMenu($hGUI, $nMsg, $hBtnArrowContext)
        Case $MenuItem4
            MsgBox(0,"","For what?")
        Case $MenuItem3
            MsgBox(0,"","Now count to three!")
    EndSwitch
WEnd

Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($nContextID)

    $arPos = ControlGetPos($hWnd, "", $CtrlID)

    $x = $arPos[0]
    $y = $arPos[1] + $arPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")

    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))

    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 0
EndFunc   ;==>ClientToScreen


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

Share this post


Link to post
Share on other sites
criticalmass

If i Post my code can you show me what to do. i am just now lost and getting fused with it

Share this post


Link to post
Share on other sites
criticalmass

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Includes
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <CompInfo.au3>
#include <ScreenCapture.au3>
#include <Zip.au3>

; Constants
Const $WINTITLE = "Passport System Requirements"
Const $OUTPUTROOT = "C:\PASSPORT_ERRORLOG"
Const $RED = "0xFF3333"
Const $GREEN = "0x66FF66"
Const $ZIPFILEPATH = "C:\PassportSystemRequirements.zip"

; Globals
Global $aMemoryInfo
Global $aProcessorInfo
Global $objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Global $colMemory = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
Global $okbutton
Global $okshot
Global $CurrentUserName
Global $OperatingSystem
Global $ProcessorType ; x86 or 64bit
Global $ServicePack
Global $CPUName
Global $CPUSpeed
Global $RAM
Global $TotalHDSpace
Global $FreeHDSpace
Global $DesktopSize
Global $DateTime
Global $IPAddress
Global $Programfilesloc
Global $okwiki
Global $oktools

#Region Functions

Func GetSystemRequirements()
    ; Current Username
    $CurrentUserName = @UserName

    ; OS
    $OperatingSystem = @OSVersion

    ; CPU Name
    $ProcessorType = @OSArch

    ; SP
    $ServicePack = @OSServicePack

    ; CPU Name
    $CPUName = $aProcessorInfo[1][0]

    ; CPU Speed
    $CPUSpeed = $aProcessorInfo[1][23] / 1000 & " GHz"

    ; RAM
    For $object in $colMemory
        $RAM = String(Int(Number($object.TotalPhysicalMemory) / (1024 * 1024))) & " MB"
    Next

    ; Total Drive Size
    $TotalHDSpace = Int(DriveSpaceTotal("C:\") / 1024) & " GB"

    ; Free Space
    $FreeHDSpace = Int(DriveSpaceFree("C:\") / 1024) & " GB"

    ; Resolution
    $DesktopSize = @DesktopWidth & " x "  & @DesktopHeight

    ;IP
    $IPAddress = @IPAddress1

    ; Program Files
    $Programfilesloc = @ProgramFilesDir

    ; Date and Time
    $DateTime = @MON & "-" & @MDAY & "-" & @YEAR & "   " & @HOUR & ":" & @MIN & ":" & @SEC
EndFunc

Func CreateLabels()
        Dim $pixelLeft = 10, $pixelTop = 40, $pixelWidth = 150, $pixelHeight = 20, $jump = 26
    GUICtrlCreateLabel("Current User Name", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Operating System", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("32 = x86 or 64 = x64 Bit ", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Service Pack", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Proc Info", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("CPU Speed", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("RAM", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("C: Total Space", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("C: Free Space", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Ip Address", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Program File Directory", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Desktop Size (Pixels)", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Date and Time", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
EndFunc



Func CreateInputs()

    Dim $pixelLeft = 170, $pixelTop = 40, $pixelWidth = 200, $pixelHeight = 20, $jump = 26

    ; Current User Name
    GUICtrlCreateInput($CurrentUserName, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Operating System
    GUICtrlCreateInput($OperatingSystem, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; X86 or x64
    GUICtrlCreateInput($ProcessorType, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Service Pack Number
    GUICtrlCreateInput($ServicePack, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Proc Name
    GUICtrlCreateInput($CPUName, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Proc Speed
    GUICtrlCreateInput($CPUSpeed, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; RAM
    Dim $RAMinput, $requiredTotalRAM = 2048
    If StringInStr($OperatingSystem, "XP") > 1 Then $requiredTotalRAM = 1024
    $RAMinput = GUICtrlCreateInput($RAM, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    If GuiCtrlRead ($RAMinput) < $requiredTotalRAM Then ; Change on Per OS basis
        GUICtrlSetBkColor ($RAMinput , $RED)
    Else
        GUICtrlSetBkColor ($RAMinput , $GREEN)
    EndIf
    $pixelTop = $pixelTop + $jump

    ; Hard Drive Size
    Dim $HD
    $HD = GUICtrlCreateInput($TotalHDSpace, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    If GuiCtrlRead ($HD) < 10 Then
        GUICtrlSetColor($HD, $RED)
    Else
        GUICtrlSetBkColor($HD, $GREEN)
    EndIf
    $pixelTop = $pixelTop + $jump

    ; Free Space
    $HD = GUICtrlCreateInput($FreeHDSpace, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    If GuiCtrlRead ($HD) < 10 Then
        GUICtrlSetColor($HD, $RED)
    Else
        GUICtrlSetBkColor($HD, $GREEN)
    EndIf
    $pixelTop = $pixelTop + $jump

    ; IP ADDY
    GUICtrlCreateInput($IPAddress, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Location of Program Files
    GUICtrlCreateInput($Programfilesloc, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Resolution of Screen
    GUICtrlCreateInput($DesktopSize, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Time and Date
    GUICtrlCreateInput($DateTime, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
EndFunc

;------------ lulz ------------
Func _RickRoll()
    ShellExecute("http://xxxxxxx/wiki/index.php/Main_Page")
EndFunc
;-----------------end lulz ---------------
Func CreateRequirementsLog()
    ; Another sample which automatically creates the directory structure
    Dim $hWnd = FileOpen($OUTPUTROOT & "\SystemRequirements.log", 10) ; 10 = 8 (create directory) + 2 (write)
    If $hWnd = -1 Then
        MsgBox(0, "Error", "Unable to create SystemRequirements.log file. Exiting Application...")
        Exit( 1 )
    EndIf

    ; Current User Name
    FileWriteLine($hWnd, "Current Username: " & $CurrentUserName)

    ; OS
    FileWriteLine($hWnd, "Operating System: " & $OperatingSystem)

    ; CPU Name
    FileWriteLine($hWnd, "Processor Type: " & $ProcessorType)

    ; SP
    FileWriteLine($hWnd, "Service Pack: " & $ServicePack)

    ; CPU Name
    FileWriteLine($hWnd, "CPU Name: " & $CPUName)

    ; CPU Speed
    FileWriteLine($hWnd, "CPU Speed: " & $CPUSpeed)

    ; RAM
    FileWriteLine($hWnd, "RAM: " & $RAM)

    ; Total Drive Size
    FileWriteLine($hWnd, "Total Hard Drive Size: " & $TotalHDSpace)

    ; Free Space
    FileWriteLine($hWnd, "Free Hard Drive Space: " & $FreeHDSpace)

    ; Resolution
    FileWriteLine($hWnd, "Desktop Resolution: " & $DesktopSize)

    ;IP
    FileWriteLine($hWnd, "IP Address: " & $IPAddress)

    ; Program Files
    FileWriteLine($hWnd, "Program Files Path: " & $Programfilesloc)

    ; Date and Time
    FileWriteLine($hWnd, "Date and Time: " & $DateTime)

    ; Close File
    FileClose($hWnd)
EndFunc

Func ScreenShotAndLogs()
    ; Take Screen Shot In Error Log
    Local $hBmp
    $hBmp = _ScreenCapture_Capture ("")
    _ScreenCapture_SaveImage ($OUTPUTROOT & "\Error_Screenshot.jpg", $hBmp)

    ;Copy important customer Log files to C:\ERRORLOG for data Mining
    FileCopy("C:\CossWebInstallation.log", $OUTPUTROOT)
    FileCopy("C:\CossInstallErrors.log", $OUTPUTROOT)
    FileCopy("C:\COSS\CossEnterpriseSuite\Exes\FileUpdates_InternetUpdate.log", $OUTPUTROOT)
    FileCopy("C:\COSS\CossEnterpriseSuite\Exes\InternetUpdate.log ", $OUTPUTROOT)
    FileCopy("C:\COSS\CossEnterpriseSuite\Exes\INSTALL.log", $OUTPUTROOT)
    FileCopy("C:\COSS\CossEnterpriseSuite\Exes\AppLaunch.log", $OUTPUTROOT)

;------------------- Opens C:\ to find Passport zip
    ShellExecute( "explorer.exe", "C:\", $OUTPUTROOT )

    ; Wire requirements log
    CreateRequirementsLog()
EndFunc

;--------- Alex FUN
func ScreenShot()
    ; Get correct number for screen shot file name
    Dim $i = 1
    while True
        If FileExists($OUTPUTROOT & "\ScreenShot" & $i & ".jpg") Then
            $i = $i + 1
        Else
            ExitLoop
        EndIf
    WEnd


    ; Take Screen Shot In Error Log
    Local $hBmp
    $hBmp = _ScreenCapture_Capture ("")
    _ScreenCapture_SaveImage ($OUTPUTROOT & "\ScreenShot" & $i & ".jpg", $hBmp)
EndFunc

Func DeleteOriginals()
    ; Delete Artifacts
    RunWait( @ComSpec & " /c del /s /q *.*", $OUTPUTROOT, @SW_HIDE )
    ; Delete Output Root
    DirRemove($OUTPUTROOT)


EndFunc
#EndRegion



; // START //

;Create Folder in C;/
iF FILEEXISTS ($OUTPUTROOT) Then FileDelete($OUTPUTROOT )
DirCreate($OUTPUTROOT)
;send ("F5")


; Get System Requirements
_ComputerGetMemory($aMemoryInfo)
_ComputerGetProcessors($aProcessorInfo)
GetSystemRequirements()



; Create Form
GUICreate($WINTITLE, 400, 400, 0, 0, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
; 1. Screen Capture
$okshot = GUICtrlCreateButton("Screen Capture", 5, 10, 95, 26)
; 2.Error Rerport
$okbutton = GUICtrlCreateButton("Error Report", 105, 10, 85, 26)
; 3. Tools - Drop Down Menu
$oktools = GUICtrlCreateButton("Tools", 195, 10, 85, 26)
;. 3. Wiki Support
$okwiki = GUICtrlCreateButton("Wiki Support", 285, 10, 80, 26)


; Create Labels
CreateLabels()

; Create Inputs
CreateInputs()

; Main Loop - Wait for User Input for Option 2.
Dim $msg
GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $okbutton
                ; Minimize Current Window
                WinSetState( $WINTITLE, "", @SW_MINIMIZE)
                While Not BitAND(WinGetState($WINTITLE, ""), 16)
                    sleep( 250 )
                WEnd

                ; Take Screen Shots and Logs
                ScreenShotAndLogs()

                ; Compress Artifacts
                If FileExists( $ZIPFILEPATH ) Then FileDelete( $ZIPFILEPATH )
                _Zip_Create( $ZIPFILEPATH )
                _Zip_AddFolderContents( $ZIPFILEPATH, $OUTPUTROOT )
                DeleteOriginals()

                ; Restore main window
                WinSetState( $WINTITLE, "", @SW_RESTORE)
            ;------------ Screen Shot
            Case $msg = $okshot
                ; Minimize Current Window
                WinSetState( $WINTITLE, "", @SW_MINIMIZE)
                While Not BitAND(WinGetState($WINTITLE, ""), 16)
                    sleep( 250 )
                WEnd

                ScreenShot()

                ; Restore main window
                WinSetState( $WINTITLE, "", @SW_RESTORE)
                ;----------------------------------
            Case $msg = $okwiki
            _RickRoll()
            Case Default
                ; Do Nothing
        EndSelect
    WEnd
Exit( 0 )

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

I am not sure where to add it. I have only been coding in AutoIT for like 2 weeks. thats why i am getting confused. If you can show me that would be amazing

Edited by criticalmass

Share this post


Link to post
Share on other sites
taietel

I don't have some of the includes, but here is a "blind" version:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Includes
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <CompInfo.au3>
#include <ScreenCapture.au3>
#include <Zip.au3>

; Constants
Const $WINTITLE = "Passport System Requirements"
Const $OUTPUTROOT = "C:\PASSPORT_ERRORLOG"
Const $RED = "0xFF3333"
Const $GREEN = "0x66FF66"
Const $ZIPFILEPATH = "C:\PassportSystemRequirements.zip"

; Globals
Global $aMemoryInfo
Global $aProcessorInfo
Global $objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Global $colMemory = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
Global $okbutton
Global $okshot
Global $CurrentUserName
Global $OperatingSystem
Global $ProcessorType ; x86 or 64bit
Global $ServicePack
Global $CPUName
Global $CPUSpeed
Global $RAM
Global $TotalHDSpace
Global $FreeHDSpace
Global $DesktopSize
Global $DateTime
Global $IPAddress
Global $Programfilesloc
Global $okwiki
Global $oktools
Global $hGUI
#Region Functions

Func GetSystemRequirements()
    ; Current Username
    $CurrentUserName = @UserName

    ; OS
    $OperatingSystem = @OSVersion

    ; CPU Name
    $ProcessorType = @OSArch

    ; SP
    $ServicePack = @OSServicePack

    ; CPU Name
    $CPUName = $aProcessorInfo[1][0]

    ; CPU Speed
    $CPUSpeed = $aProcessorInfo[1][23] / 1000 & " GHz"

    ; RAM
    For $object in $colMemory
        $RAM = String(Int(Number($object.TotalPhysicalMemory) / (1024 * 1024))) & " MB"
    Next

    ; Total Drive Size
    $TotalHDSpace = Int(DriveSpaceTotal("C:\") / 1024) & " GB"

    ; Free Space
    $FreeHDSpace = Int(DriveSpaceFree("C:\") / 1024) & " GB"

    ; Resolution
    $DesktopSize = @DesktopWidth & " x "  & @DesktopHeight

    ;IP
    $IPAddress = @IPAddress1

    ; Program Files
    $Programfilesloc = @ProgramFilesDir

    ; Date and Time
    $DateTime = @MON & "-" & @MDAY & "-" & @YEAR & "   " & @HOUR & ":" & @MIN & ":" & @SEC
EndFunc

Func CreateLabels()
        Dim $pixelLeft = 10, $pixelTop = 40, $pixelWidth = 150, $pixelHeight = 20, $jump = 26
    GUICtrlCreateLabel("Current User Name", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Operating System", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("32 = x86 or 64 = x64 Bit ", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Service Pack", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Proc Info", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("CPU Speed", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("RAM", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("C: Total Space", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("C: Free Space", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Ip Address", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Program File Directory", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Desktop Size (Pixels)", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump
    GUICtrlCreateLabel("Date and Time", $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
EndFunc



Func CreateInputs()

    Dim $pixelLeft = 170, $pixelTop = 40, $pixelWidth = 200, $pixelHeight = 20, $jump = 26

    ; Current User Name
    GUICtrlCreateInput($CurrentUserName, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Operating System
    GUICtrlCreateInput($OperatingSystem, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; X86 or x64
    GUICtrlCreateInput($ProcessorType, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Service Pack Number
    GUICtrlCreateInput($ServicePack, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Proc Name
    GUICtrlCreateInput($CPUName, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Proc Speed
    GUICtrlCreateInput($CPUSpeed, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; RAM
    Dim $RAMinput, $requiredTotalRAM = 2048
    If StringInStr($OperatingSystem, "XP") > 1 Then $requiredTotalRAM = 1024
    $RAMinput = GUICtrlCreateInput($RAM, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    If GuiCtrlRead ($RAMinput) < $requiredTotalRAM Then ; Change on Per OS basis
        GUICtrlSetBkColor ($RAMinput , $RED)
    Else
        GUICtrlSetBkColor ($RAMinput , $GREEN)
    EndIf
    $pixelTop = $pixelTop + $jump

    ; Hard Drive Size
    Dim $HD
    $HD = GUICtrlCreateInput($TotalHDSpace, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    If GuiCtrlRead ($HD) < 10 Then
        GUICtrlSetColor($HD, $RED)
    Else
        GUICtrlSetBkColor($HD, $GREEN)
    EndIf
    $pixelTop = $pixelTop + $jump

    ; Free Space
    $HD = GUICtrlCreateInput($FreeHDSpace, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    If GuiCtrlRead ($HD) < 10 Then
        GUICtrlSetColor($HD, $RED)
    Else
        GUICtrlSetBkColor($HD, $GREEN)
    EndIf
    $pixelTop = $pixelTop + $jump

    ; IP ADDY
    GUICtrlCreateInput($IPAddress, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Location of Program Files
    GUICtrlCreateInput($Programfilesloc, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Resolution of Screen
    GUICtrlCreateInput($DesktopSize, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
    $pixelTop = $pixelTop + $jump

    ; Time and Date
    GUICtrlCreateInput($DateTime, $pixelLeft, $pixelTop, $pixelWidth, $pixelHeight)
EndFunc

;------------ lulz ------------
Func _RickRoll()
    ShellExecute("http://xxxxxxx/wiki/index.php/Main_Page")
EndFunc
;-----------------end lulz ---------------
Func CreateRequirementsLog()
    ; Another sample which automatically creates the directory structure
    Dim $hWnd = FileOpen($OUTPUTROOT & "\SystemRequirements.log", 10) ; 10 = 8 (create directory) + 2 (write)
    If $hWnd = -1 Then
        MsgBox(0, "Error", "Unable to create SystemRequirements.log file. Exiting Application...")
        Exit( 1 )
    EndIf

    ; Current User Name
    FileWriteLine($hWnd, "Current Username: " & $CurrentUserName)

    ; OS
    FileWriteLine($hWnd, "Operating System: " & $OperatingSystem)

    ; CPU Name
    FileWriteLine($hWnd, "Processor Type: " & $ProcessorType)

    ; SP
    FileWriteLine($hWnd, "Service Pack: " & $ServicePack)

    ; CPU Name
    FileWriteLine($hWnd, "CPU Name: " & $CPUName)

    ; CPU Speed
    FileWriteLine($hWnd, "CPU Speed: " & $CPUSpeed)

    ; RAM
    FileWriteLine($hWnd, "RAM: " & $RAM)

    ; Total Drive Size
    FileWriteLine($hWnd, "Total Hard Drive Size: " & $TotalHDSpace)

    ; Free Space
    FileWriteLine($hWnd, "Free Hard Drive Space: " & $FreeHDSpace)

    ; Resolution
    FileWriteLine($hWnd, "Desktop Resolution: " & $DesktopSize)

    ;IP
    FileWriteLine($hWnd, "IP Address: " & $IPAddress)

    ; Program Files
    FileWriteLine($hWnd, "Program Files Path: " & $Programfilesloc)

    ; Date and Time
    FileWriteLine($hWnd, "Date and Time: " & $DateTime)

    ; Close File
    FileClose($hWnd)
EndFunc

Func ScreenShotAndLogs()
    ; Take Screen Shot In Error Log
    Local $hBmp
    $hBmp = _ScreenCapture_Capture ("")
    _ScreenCapture_SaveImage ($OUTPUTROOT & "\Error_Screenshot.jpg", $hBmp)

    ;Copy important customer Log files to C:\ERRORLOG for data Mining
    FileCopy("C:\CossWebInstallation.log", $OUTPUTROOT)
    FileCopy("C:\CossInstallErrors.log", $OUTPUTROOT)
    FileCopy("C:\COSS\CossEnterpriseSuite\Exes\FileUpdates_InternetUpdate.log", $OUTPUTROOT)
    FileCopy("C:\COSS\CossEnterpriseSuite\Exes\InternetUpdate.log ", $OUTPUTROOT)
    FileCopy("C:\COSS\CossEnterpriseSuite\Exes\INSTALL.log", $OUTPUTROOT)
    FileCopy("C:\COSS\CossEnterpriseSuite\Exes\AppLaunch.log", $OUTPUTROOT)

;------------------- Opens C:\ to find Passport zip
    ShellExecute( "explorer.exe", "C:\", $OUTPUTROOT )

    ; Wire requirements log
    CreateRequirementsLog()
EndFunc

;--------- Alex FUN
func ScreenShot()
    ; Get correct number for screen shot file name
    Dim $i = 1
    while True
        If FileExists($OUTPUTROOT & "\ScreenShot" & $i & ".jpg") Then
            $i = $i + 1
        Else
            ExitLoop
        EndIf
    WEnd


    ; Take Screen Shot In Error Log
    Local $hBmp
    $hBmp = _ScreenCapture_Capture ("")
    _ScreenCapture_SaveImage ($OUTPUTROOT & "\ScreenShot" & $i & ".jpg", $hBmp)
EndFunc

Func DeleteOriginals()
    ; Delete Artifacts
    RunWait( @ComSpec & " /c del /s /q *.*", $OUTPUTROOT, @SW_HIDE )
    ; Delete Output Root
    DirRemove($OUTPUTROOT)


EndFunc
#EndRegion



; // START //

;Create Folder in C;/
iF FILEEXISTS ($OUTPUTROOT) Then FileDelete($OUTPUTROOT )
DirCreate($OUTPUTROOT)
;send ("F5")


; Get System Requirements
_ComputerGetMemory($aMemoryInfo)
_ComputerGetProcessors($aProcessorInfo)
GetSystemRequirements()



; Create Form
$hGUI = GUICreate($WINTITLE, 400, 400, 0, 0, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$hBtnClick = GUICtrlCreateButton("Click", 64, 10, 75, 25)
$hBtnArrow = GUICtrlCreateButton("6", 137, 10, 19, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Webdings")
$hBtnArrowContext = GUICtrlCreateContextMenu($hBtnArrow)
$okshot = GUICtrlCreateMenuItem("Screen Capture", $hBtnArrowContext)
$okbutton = GUICtrlCreateMenuItem("Error Report", $hBtnArrowContext)
$oktools = GUICtrlCreateMenuItem("Tools", $hBtnArrowContext)
$okwiki = GUICtrlCreateMenuItem("Wiki Support", $hBtnArrowContext)
#cs
; 1. Screen Capture
$okshot = GUICtrlCreateButton("Screen Capture", 5, 10, 95, 26)
; 2.Error Rerport
$okbutton = GUICtrlCreateButton("Error Report", 105, 10, 85, 26)
; 3. Tools - Drop Down Menu
$oktools = GUICtrlCreateButton("Tools", 195, 10, 85, 26)
;. 3. Wiki Support
$okwiki = GUICtrlCreateButton("Wiki Support", 285, 10, 80, 26)
#ce

; Create Labels
CreateLabels()

; Create Inputs
CreateInputs()

; Main Loop - Wait for User Input for Option 2.
Dim $msg
GUISetState()
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hBtnArrow, $hBtnClick
                ShowMenu($hGUI, $msg, $hBtnArrowContext)
            Case $okbutton
                ; Minimize Current Window
                WinSetState( $WINTITLE, "", @SW_MINIMIZE)
                While Not BitAND(WinGetState($WINTITLE, ""), 16)
                    sleep( 250 )
                WEnd

                ; Take Screen Shots and Logs
                ScreenShotAndLogs()

                ; Compress Artifacts
                If FileExists( $ZIPFILEPATH ) Then FileDelete( $ZIPFILEPATH )
                _Zip_Create( $ZIPFILEPATH )
                _Zip_AddFolderContents( $ZIPFILEPATH, $OUTPUTROOT )
                DeleteOriginals()

                ; Restore main window
                WinSetState( $WINTITLE, "", @SW_RESTORE)
            ;------------ Screen Shot
            Case $okshot
                ; Minimize Current Window
                WinSetState( $WINTITLE, "", @SW_MINIMIZE)
                While Not BitAND(WinGetState($WINTITLE, ""), 16)
                    sleep( 250 )
                WEnd

                ScreenShot()

                ; Restore main window
                WinSetState( $WINTITLE, "", @SW_RESTORE)
                ;----------------------------------
            Case $okwiki
            _RickRoll()
            Case Default
                ; Do Nothing
        EndSwitch
    WEnd
Exit( 0 )

Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($nContextID)

    $arPos = ControlGetPos($hWnd, "", $CtrlID)

    $x = $arPos[0]
    $y = $arPos[1] + $arPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")

    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))

    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 0
EndFunc   ;==>ClientToScreen


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu
;--------------------

[edit] forgot EndSwitch

Edited by taietel

Share this post


Link to post
Share on other sites
criticalmass

Thank you i got it from here. :) If i could hug you i would

Edited by criticalmass

Share this post


Link to post
Share on other sites
Jefferson

hello, I wonder if it is possible to extract the serial number of hard disk, have tried every possible script but it still fails, I would like help from the already thank you, thank you

Share this post


Link to post
Share on other sites
Andreik

^^Did you tried DriveGetSerial()?


When the words fail... music speaks

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  

×