Jump to content
Sign in to follow this  

Menu Item Function Call

Recommended Posts

Hi everyone, I'm writting a program that incorporates a few different elements (ps3netsrv and webman) and I've got most of it knocked out but I can't seem to get the menu item I added to the default system menu to call anything. Here's the script I've got so far (I'm not nearly done but the rest I can probably do once I get this menu thing fixed).

#include <GUIConstants.au3>
#include <Constants.au3>
#include <IE.au3>
#include <WinAPI.au3>
#include <GUIStatusBar.au3>
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
#include <timers.au3>

$IE_Base = ""
dim $sStatusPrev, $sStatus, $sConsole, $sConsolePrev, $tTimer, $mnuCheck

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$mainWindow = GUICreate("WebManNetSrv", 680, 615, 10, 10)
$edtConsole = GUICtrlCreateEdit("",-1,381,683,215,BitOR($ES_WANTRETURN,$WS_VSCROLL,$ES_READONLY))

$pid = run(@ScriptDir & "\ps3netsrv.exe L:\ 38008 192.168.1.*","",@SW_SHOW)
ProcessWait ($pid)
; get the handle of the cmd window as i cannot be certain that there will be only one instance of the cmd running with the same window title or class
$cmdHandle = _ProcessGetHWnd($pid, 2)
Local $hWndChild = $cmdHandle[1][1]
WinSetState($hWndChild, '', @SW_HIDE)
WinMove($hWndChild,"",@DesktopWidth + 120,@DesktopHeight/2)

$oIE = IECreatePseudoEmbedded(0,0,680,380,$mainWindow)

$bStatus = _GUICtrlStatusBar_Create($mainWindow)

$hMenu = _GUICtrlMenu_GetSystemMenu($mainWindow)
$mnuCheck = _GUICtrlMenu_InsertMenuItem($hMenu, 6, "Check Now")

;~ $sConsole = _ConsoleCopyText($hWndChild)
$tTimer = _Timer_Init()

While 1
    if TimerDiff($tTimer) >= 30000 Then
        $sConsole = _ConsoleCopyText($hWndChild)
        $tTimer = _Timer_Init()
    If $sConsole <> $sConsolePrev Then
        $sConsolePrev = $sConsole

    If $sStatus <> $sStatusPrev Then
        $sStatusPrev = $sStatus

    if Ping($IE_Base) = 0 Then
        _GUICtrlStatusBar_SetText($bStatus,"System shutdown detected. Waiting for reboot...")
        $sStatus = "Client Offline"
        $sStatus = "Client Online"
; end of event loop

Func CLOSEClicked()

Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
;~     Sleep(100)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc  ;==>WM_PAINT

Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000)
    Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()

    While 1

    ; Get list of windows
        $aWin = WinList($sTitle)

    ; Searches thru all windows
        For $i = 1 To $aWin[0][0]

        ; Found a window owned by the given PID
            If $iPid = WinGetProcess($aWin[$i][1]) Then

            ; Option 0 or 1 used
                If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
                    Return $aWin[$i][1]

            ; Option 2 is used
                ElseIf $iOption = 2 Then
                    ReDim $aReturn[UBound($aReturn) + 1][2]
                    $aReturn[0][0] += 1
                    $aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
                    $aReturn[$aReturn[0][0]][1] = $aWin[$i][1]

    ; If option 2 is used and there was matches then the list is returned
        If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn

    ; If timed out then give up
        If TimerDiff($hTimer) > $iTimeout Then ExitLoop

    ; Waits before new attempt

; No matches
    Return 0
EndFunc  ;==>_ProcessGetHWnd

Func IECreatePseudoEmbedded($i_Left, $i_Top, $i_Width, $i_Height, $h_Parent)

Local $o_IE, $h_HWND

$o_IE = ObjCreate("InternetExplorer.Application")
$o_IE.theatermode = True
$o_IE.fullscreen = True
$o_IE.statusbar = False

$h_HWND = _IEPropertyGet($o_IE, "hwnd")
_WinAPI_SetParent($h_HWND, $h_Parent)
_WinAPI_MoveWindow($h_HWND, $i_Left, $i_Top, $i_Width, $i_Height, False)

Return $o_IE

EndFunc ;==>IECreatePseudoEmbedded

Func _ConsoleCopyText($hWin = $hWndChild)
    $hCurrent = WinActive("")
    $sConsole = ClipGet()

    Return $sConsole

By the way, before anyone asks, yes I've tried using STDOUT_Read for the "console" and have tried joining the windows as well. STDOUT_Read doesn't return anything until the program closes and joining the windows doesn't give me the control over the console I want/need (sending messages to display on the screen) so this is what I'm left with.

Edited by dbzfanatic

Share this post

Link to post
Share on other sites

Everything I've read about ps3netsrv and webman has to do with streaming of games. As you've obviously been around for a while, and I am sure you are familiar with the forum rules, can you please explain a bit more about what you're trying to accomplish (and how it doesn't violate those rules)?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites

ps3netsrv is mainly used to stream games but it also allows the streaming of dvds and bluerays over a network just like a media center except a bit easier (just type in your folder and go) and it will show on your network, no dedicated media streaming server or anything and it's really low overhead so it's almost like XMBC. What I'm trying to do is keep track of which media is mounted/streamed and which ps3(s) are connected as well as the status of each. Instead of running back and forth between programs (granted it's not terribly difficult just tedious) I can look at one window and get all the info I need as well as all management options for mounting or changing the stream, restarting the ps3 if it freezes, whatever. Automation of media streaming apps isn't against the rules last time I checked and I think it'd be a lot easier to stream an ISO of my DVDs and Bluerays than getting up and changing discs every time a movie ends (my daughter is 2 and is in the "ooooo shiney" stage so this option is a real help). Yes I know there are options like vudu and I do have several movies on vudu but my net connection sucks so I want to have this second option to have some family movie time. I can't code this thing to prevent piracy the author of ps3netsrv and/or webman would have to do that but I can make the streaming easier for whatever media is chosen.

Specifically with the function I've hijacked the system menu and added a "Check Now" option to it. I need to call _ConsoleCopyText($hWndChild) when that menu item is clicked. This wouldn't be an issue if it was a menu I created myself but as I've hijacked the already existing system menu it's a bit more complicated.

Edited by dbzfanatic

Share this post

Link to post
Share on other sites



I hope moderators reviewed it

They have now - and the thread can stay open. ;)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


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

Thanks Zedna that's just what I needed! Melba thanks for saying it's fine. I'll test this out in a bit and as long as it works properly I'll mark Zedna's answer as what I needed.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...