Jump to content

PortableMenu


C45Y
 Share

Recommended Posts

A standalone Portable Application Menu

Posted Image

The code is pretty messy, im not one to clean things :)

The transparency function needs alot of work but uni is pretty hectic atm.

Trasnparency looks quite nice now, has a pretty slider and real time demonstration of transparency ;)

Unfortunately at this point in time the program MUST be run from the root of the drive. [perfect for usb's - not so good for dev/testing]

IT RUNS FROM ANYWHERE! o:)

There will be an inital wait while the program searches for applications, i need to figure a way to make a progressbar or something to that extent without knowing the termination time for it...any help would be appreciated! :P [using a tooltip to simply show activity atm]

It now shows a marque progressbar! used only to indicate activity but works well enough.

Positive and Negative feedback are welcome

a compiled version can be found at link

thanks

-Stephen

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=PortableMenu.ico
#AutoIt3Wrapper_Outfile=PortableMenu.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Fileversion=1.0.0.3
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p
#AutoIt3Wrapper_Res_Language=1033
://////=__=
://////=__==C45Y)
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <File.au3>
#include <Array.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#include <String.au3>
#include <Process.au3>
#include <Misc.au3>
#include <ScrollBarConstants.au3>
#include <GUIScrollBars.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <SliderConstants.au3>

#NoTrayIcon

#cs ----------------------------------------------------------------------------
    
    Project Name: PortableMenu
    Description: Portable Application Menu (SA)
    AutoIt Version: 3.3.0.0
    Author: Stephen McGregor (C45Y)
    Email: tehborris@gmail.com
    Company: Team Stooge
    Creation Date: 01-Jun-10
    
#ce ----------------------------------------------------------------------------
Opt("TrayMenuMode", 3)
If _Singleton("PortableMenu", 1) = 0 Then
    MsgBox(0, "Warning", "PortableMenu is already running")
    Exit
EndIf
#Region ; GUI
$gui = GUICreate("PortableMenu", 230, 300, @DesktopWidth - 245, @DesktopHeight - 390, $WS_DLGFRAME)
$listview = GUICtrlCreateListView("", 0, 0, 230, 280, $LVS_NOCOLUMNHEADER)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetColor(-1, 0x0080ff)
_GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_FLATSB, $LVS_EX_FULLROWSELECT))
Global $NewStyle = False
#EndRegion 

#Region ; Tray Menu
Global Const $MIM_APPLYTOSUBMENUS = 0x80000000
Global Const $MIM_BACKGROUND = 0x00000002
$drive = TrayCreateItem("Explore")
$show = TrayCreateItem("Show Menu")
$OptionsMenu = TrayCreateMenu("Options")
$trans = TrayCreateItem("Set transperancy", $OptionsMenu)
$style = TrayCreateItem("Set Topmost", $OptionsMenu)
$aboutitem = TrayCreateItem("About")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
SetMenuColor(0, 0x6A7B59) ; BGR color value, '0' means the tray context menu handle itself
SetMenuColor($OptionsMenu, 0xD3C5BE); BGR color value
TraySetClick(9)
TraySetState()
TraySetToolTip("PortableMenu")
#EndRegion 

#Region ; Main
$hImage = _GUIImageList_Create(16, 16)
_GUICtrlListView_SetImageList($listview, $hImage, 1)
_GUICtrlListView_AddColumn($listview, "PortableMenu", 207, 0)
Dim $FolderName = @ScriptDir & "\PortableApps"
$FolderName = StringReplace($FolderName, "\\", "\")
Dim $FileCount = 0 ;no of .exe's found
Global $var[1] ; location of exe's
$Form1 = GUICreate("Progress", 267, 65, -1, -1, $WS_POPUP,$WS_EX_TOOLWINDOW )
$Progress1 = GUICtrlCreateProgress(8, 32, 249, 25,0x00000008 + 0x00000001 )
$Label1 = GUICtrlCreateLabel("Finding Programs..", 88, 8, 99, 17)
GUISetState(@SW_SHOW)
$j = 0
AdlibRegister("_showactivity")
ScanFolder($FolderName) ; scan through folders (2 deep) and locate all .exe's and add to an array called $var
AdlibUnRegister("_showactivity")
GUISetState(@SW_SHOW,$gui)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$counter = 100 / $FileCount
GUICtrlSetData($Label1, "Adding Programs.." )
GUICtrlSetData($Progress1,0)
GUICtrlSetStyle($Progress1, 0x00000001)
For $i = 1 To $FileCount Step 1
    _additem($var[$i], $i - 1)
    GUICtrlSetData($Progress1, $counter * $i)
Next
GUIDelete($Form1)
While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            MsgBox(0, "Help", _
                    "Project Name: PortableMenu" & @CRLF & _
                    "Description: Portable Application Menu (SA)" & @CRLF & _
                    "AutoIt Version: 3.3.0.0" & @CRLF & _
                    "Author: Stephen McGregor (C45Y)" & @CRLF & _
                    "Email: tehborris@gmail.com" & @CRLF & _
                    "Company: Team Stooge" & @CRLF & _
                    "Creation Date: 01-Jun-10" & @CRLF)
        Case $msg = $exititem
            ExitLoop
        Case $msg = $drive
            Run("explorer.exe " & @WorkingDir)
        Case $msg = $trans
            trans()
        Case $msg = $style
            _settop()
        Case $msg = $show
            WinActivate("PortableMenu")
    EndSelect
WEnd
GUIDelete()
Exit
#EndRegion

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iCode
        Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
            $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
            $workdir = $var[(DllStructGetData($tInfo, "Index") + 1)]
            $workdir = StringReplace($workdir, "\\", "\")
            $workdir = stringTrimright($workdir,StringLen ( $workdir ) - StringInStr($workdir,"\",1,-1))
            Run($var[(DllStructGetData($tInfo, "Index") + 1)],$workdir)
    EndSwitch
    $tNMHDR = 0
EndFunc   ;==>WM_NOTIFY

Func _settop()
    If Not $NewStyle Then
        WinSetOnTop("PortableMenu", "", 1)
        $NewStyle = True
        TrayItemSetText($style,"Set Normal")
    Else
        WinSetOnTop("PortableMenu", "", 0)
        $NewStyle = False
        TrayItemSetText($style,"Set Topmost")
    EndIf
EndFunc   ;==>_settop

Func trans()
WinSetTrans("PortableMenu","",_slider())
EndFunc   ;==>trans

Func _additem($im, $i) ;$im is the full path to the .exe | $i is the count from the for loop
    $title = StringTrimLeft($im,StringInStr($im,"\",1,-1))
    _GUICtrlListView_AddItem($listview, StringTrimRight($title, 4), $i)
    _GUIImageList_AddIcon($hImage, $im, 0, false) ;true for large icon
EndFunc   ;==>_additem

Func ScanFolder($SourceFolder)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath
    
    $Search = FileFindFirstFile($SourceFolder & "\*")
    While 1
        $j = $j + 1
        If $Search = -1 Then
            ExitLoop
        EndIf
        ;see if there's a next file to get
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        ;append the file path
        $FullFilePath = $SourceFolder & "\" & $File
        $FileAttributes = FileGetAttrib($FullFilePath)
        ;check if its a directory
        If StringInStr($FileAttributes, "D") Then
            ScanFolder($FullFilePath)
        Else
            $FullFilePath = "\" & StringTrimLeft($FullFilePath,StringLen(@ScriptDir))
            $FullFilePath = StringReplace($FullFilePath, "\\", "\")
            If StringInStr($FullFilePath, "\", 1, 4) = 0 Then
                If StringRight($FullFilePath, 3) = "exe" Then
                    _ArrayAdd($var,@ScriptDir &  $FullFilePath)
                    $FileCount += 1
                EndIf
            EndIf
        EndIf

    WEnd
    FileClose($Search)
EndFunc   ;==>ScanFolder

; Apply the color to the menu
Func SetMenuColor($nMenuID, $nColor)
    $hMenu = TrayItemGetHandle($nMenuID) ; Get the internal menu handle
    
    $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
    $hBrush = $hBrush[0]
    
    Local $stMenuInfo = DllStructCreate("dword;dword;dword;uint;dword;dword;ptr")
    DllStructSetData($stMenuInfo, 1, DllStructGetSize($stMenuInfo))
    DllStructSetData($stMenuInfo, 2, BitOR($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND))
    DllStructSetData($stMenuInfo, 5, $hBrush)
    
    DllCall("user32.dll", "int", "SetMenuInfo", "hwnd", $hMenu, "ptr", DllStructGetPtr($stMenuInfo))
EndFunc   ;==>SetMenuColor

Func _showactivity()
    GUICtrlSetData($Progress1, $j)
    $j = $j + 20
    if $j = 100 Then $j = 0
    $nMsg = GUIGetMsg()
EndFunc

Func _slider()
$slidergui = GUICreate("Slider", 200, 50, -1, -1, $Ws_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$Slider1 = GUICtrlCreateSlider(0, 0, 200, 30)
GUICtrlSetLimit(-1, 255, 35)
GUICtrlSetData(-1, 255)
$Label1 = GUICtrlCreateLabel("0", 0, 32, 10, 17)
$Label2 = GUICtrlCreateLabel("255", 180, 32, 22, 17)
$Button1 = GUICtrlCreateButton("Done", 56, 32, 89, 17, 0)
GUISetState()
While 1
    WinSetTrans("Slider","",GUICtrlRead($Slider1))
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
            ExitLoop
    EndSwitch
WEnd
$sliderstate = GUICtrlRead($Slider1)
guidelete($slidergui)
return $sliderstate
EndFunc

EDIT: Source changes and general errors ;)

Edited by C45Y
http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

I'm getting a black gui !

What must i do ?

ok...

ive updated the info in the main post, hopefully makes it clear.

PortableMenu NEEDS to be placed in the root folder of whatever drive it resides upon.

there also needs to be a "PortableApps" folder found at the root too. then is simply a matter of populating the "PortableApps" folder with exe's [up to two folders deep!]

hopefully that sorts things out...it all seemed so simple when this started

Edited by C45Y
http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

Seems interesting =)

But, I'm getting an error:

C:\PortableMenu.au3 (152) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

_GUICtrlListView_AddItem($listview, StringTrimRight($title[4], 4), $i)

_GUICtrlListView_AddItem($listview, StringTrimRight(^ ERROR

(I've tested with the script and compiled 'PortableMenu'. Placed both at C:\ and created a folder C:\PortableApps with a random .exe inside) Edited by SeF
Link to comment
Share on other sites

Seems interesting =)

But, I'm getting an error:

(I've tested with the script and compiled 'PortableMenu'. Placed both at C:\ and created a folder C:\PortableApps with a random .exe inside)

aah yepp found it. thats what happens when there's no directory structure within portable apps.

say for example

C:\portableapps\run.exe will throw an error, but

C:\portableapps\run\run.exe wont.

its because im using

$listview, StringTrimRight($title[4], 4), $i)
so when its not in a subdirectory then it cant find the right ammount of "\"'s ;)

hmm.....but how to fix that...

*some time later*

I HAVE IT!!!!

$title = StringTrimLeft($im,StringInStr($im,"\",1,-1))
    _GUICtrlListView_AddItem($listview, StringTrimRight($title, 4), $i)

ok so now rather than relying on the slashes it finds the last "\"...then removes the rest of the string leaving only the exe name.

Shows up the same as before but files can be anywhere in the "portableapps" folder as well as 1st subfolder..

thanks alot SeF!

i probably never would have noticed that.

#First post changed to reflect source change#

http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

Personally, I would use this search function : #702862

Instead of looking for all the exe, I would look rather for exe in the format: Portablexxx.exe

And that, for all subdirectory of the scriptfile. ;)

hmm interesting...i like the function, definitely better than the one im using, although i do not wish to search more than 2 folders deep from the main program's location as this seems to do, but with some modifying im sure it could be workable...

I just dont really want to create such a strict structure (the exact reason i dont use PortableApps Menu)

Having to rename .exe's, while only a small inconvenience, is not something i want.

Just to simply copy an .exe into the folder and thats all, is what im aiming for.

i will look into it though. thanks Tlem

http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

You may want to make a file where you can keep a list of settings. For example, I use a loader program to work on PCs. I use an INI file to point to the correct locations for each app I want to use.

Take a look at this:

http://www.autoitscript.com/forum/index.php?showtopic=105093&view=findpost&p=743104

It should give you some direction on how to solve certain issues you are having.

Link to comment
Share on other sites

>>PortableMenu NEEDS to be placed in the root folder of whatever drive it resides upon.

hi, I changed some code here

$FullFilePathDeep = StringSplit($FullFilePath, "\")

$ScriptDirDeep = StringSplit(@ScriptDir, "\")

;If StringInStr($FullFilePath, "\", 1, 4) = 0 Then

If $FullFilePathDeep[0]-$ScriptDirDeep[0]<=3 Then

Link to comment
Share on other sites

>>PortableMenu NEEDS to be placed in the root folder of whatever drive it resides upon.

hi, I changed some code here

$FullFilePathDeep = StringSplit($FullFilePath, "\")

$ScriptDirDeep = StringSplit(@ScriptDir, "\")

;If StringInStr($FullFilePath, "\", 1, 4) = 0 Then

If $FullFilePathDeep[0]-$ScriptDirDeep[0]<=3 Then

looking at your code im a bit confused. are you taking away the scriptdir from the fullfilepath?

if so very nicely done! that would solve the problem of being placed in root, using relative paths...very nice, never even occurred to me.

thanks jasonc2000

EDIT

taken jasonc2000's idea into effect. main post has been changed to reflect. can now run from anywhere! ;)

Edited by C45Y
http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

PortableMenu UPDATED!!!

Added a marque progress bar that will show while the application searches for programs

Got my inspiration from the coolprogress.au3 thats floating around here somewhere

thanks to the author of that :)

I've tryed last version and appeared the following errors:

C:\Documents and Settings\User\Desktop\PortableMenu.au3(92,28) : ERROR: AdlibEnable(): undefined function.

AdlibEnable("_showactivity")

~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\User\Desktop\PortableMenu.au3(94,14) : ERROR: AdlibDisable(): undefined function.

AdlibDisable()

~~~~~~~~~~~~~^

C:\Documents and Settings\User\Desktop\PortableMenu.au3 - 2 error(s), 0 warning(s)

!>09:09:20 AU3Check ended.rc:2

EDIT:

Fixed by changing:

- AdlibEnable to AdlibRegister

- AdlibDisable to AdlibUnRegister

It's working fine now.

But, there is no button to close PortableMenu? ;)

Edited by SeF
Link to comment
Share on other sites

I've tryed last version and appeared the following errors:

EDIT:

Fixed by changing:

- AdlibEnable to AdlibRegister

- AdlibDisable to AdlibUnRegister

It's working fine now.

But, there is no button to close PortableMenu? ;)

What version of AutoIT do you use?? i may be in need of an update

and yes there is no nice red X...didnt want one, instead there's a tray menu option to exit

http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

What version of AutoIT do you use?? i may be in need of an update

and yes there is no nice red X...didnt want one, instead there's a tray menu option to exit

I'm using last version (3.3.6.1).

Adlib's functions names changes = 3.3.2.0 ;)

I didn't see the tray menu hahah :) Very nice!

Suggestion:

Use Opt("TrayMenuMode", 3) instead of Opt("TrayMenuMode", 1)

It's kinda strange to see an 'About' item checked after you click for the first time. ;)

Link to comment
Share on other sites

I'm using last version (3.3.6.1).

Adlib's functions names changes = 3.3.2.0 ;)

Yepp i'll update that when i get home, source updated now [love portable AutoIT :) ]

Use Opt("TrayMenuMode", 3) instead of Opt("TrayMenuMode", 1)

It's kinda strange to see an 'About' item checked after you click for the first time. :)

Aah thanks! i was wondering why i had ticks on items, been screwing with me for a while now lol
http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

PortableMenu UPDATED!!!

Fixed the transparenty - Looks a whole lot better now and doesn't crash when it's not changed

Changed running of programs, they are now run in their working directory, was calling them from the portablemenu.exe's directory and having lots of problems with applications crashing because they were calling things that weren't where they thought they were...anyways ;)

And just general cleaning/commenting...trying to get everything into methods...just taking a while

Also loads programs quicker than before...not something ive changed so no idea why :)

http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...