Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Real Media Analyzer GUI Shell

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Real Media Analyzer GUI Shell

    Code:
    ' RMAShell.bas : Runs RMA.EXE on files dragged-and-dropped onto application,
    ' for each command line parameter specified.
    '
    ' RMA.EXE (Real Media Analyzer)is a console app that analyzes/repairs RealMedia files
    '
    '  Author: David Gwillim
    '    Date: 11 February 2005
    ' Version: 1.0.3
    '
    ' History: v1.0.0 Initial release
    '          v1.0.1 Added progress display in main text box showing file name being processed
    '          v1.0.2 Added Ctrl-A accelerator to Result textbox for selecting all the text
    '          v1.0.3 Fix to ERASE RMFiles() array after processing, to prevent accidental repeat
    '                 Added version number to title bar
    '
    ' Copyright (c) 2005 by David Gwillim. Released to the Public Domain for use by others.
    '
    ' Console Child Process spawning code was based on the Microsoft article:
    '   "Spawn Console Processes with Redirected Standard Handles"
    '   ID: Q190351
    ' Also inspired by some C++ coding by Ted Ferenc in his RunConsoleApp freeware program
    ' See his website: [url="http://www.ndrw.co.uk/free/runconsoleapp/"]http://www.ndrw.co.uk/free/runconsoleapp/[/url] 
    '
    ' More useful info from Nick Adams at the code project:
    ' See: [url="http://www.codeproject.com/threads/redir.asp"]http://www.codeproject.com/threads/redir.asp[/url] 
    '
    ' Thanks also to Semen Matusovski who's posting on the PowerBasic forums prompted me
    ' to get this code running.
    '
    ' Many thanks to Alexey Pavluchenko for writing RMA.EXE. You can obtain a copy of this
    ' freeware from: [url="http://www.anime.com.ua/misc/alexey/rma.htm"]http://www.anime.com.ua/misc/alexey/rma.htm[/url] 
    '
    
    #COMPILE EXE
    #DIM ALL
    #REGISTER NONE
    #INCLUDE "Win32Api.Inc"
    
    $VERSION = "1.0.3"
    
    %TXT_RESULT = 100
    %TXT_OPTS   = 101
    %BTN_RUN    = 102
    %BTN_EXIT   = 103
    
    $DO_THIS    = "Drag-and-drop RealMedia files to here from Windows Explorer ..."
    
    GLOBAL Result AS STRING
    GLOBAL Opts() AS STRING
    GLOBAL RMFiles() AS STRING
    
    FUNCTION ShellConsoleApp (CmdLine AS STRING, _
                              StartDirectory AS ASCIIZ, _
                              Result AS STRING, _
                              BYVAL dwMillisecondsWait AS DWORD _
                             ) AS LONG
    
      ' Set security attributes
      LOCAL sa AS SECURITY_ATTRIBUTES
      sa.nLength = SIZEOF(SECURITY_ATTRIBUTES)
      sa.lpSecurityDescriptor = 0&
      sa.bInheritHandle = 1 ' TRUE
    
      ' Create a new anonymous pipe
      LOCAL hReadPipeTmp AS DWORD, hReadPipe AS DWORD, hWritePipe AS DWORD, hWritePipeErr AS DWORD
      IF CreatePipe(hReadPipeTmp, hWritePipe, sa, BYVAL 0) = 0 THEN _
      FUNCTION = -4: EXIT FUNCTION
    
      LOCAL dwCP AS DWORD
      dwCP = GetCurrentProcess()
    
      ' Create a duplicate of the output write handle for the std error
      ' write handle. This is necessary in case the child application
      ' closes one of its std output handles.
      IF DuplicateHandle(dwCP,hWritePipe,GetCurrentProcess(),hWritePipeErr, _
                         0,1, _ ' has to be inheritable
                         %DUPLICATE_SAME_ACCESS)=0 THEN FUNCTION = -5 : EXIT FUNCTION
    
      ' Create new pipe read handle
      ' Set the inheritance properties to FALSE. Otherwise, the child
      ' inherits these handles; resulting in non-closeable
      ' handles to the pipes being created.
      IF DuplicateHandle(dwCP,hReadPipeTmp,dwCP,hReadPipe, _
                         0&, 0&, _          ' make it uninheritable.
                         %DUPLICATE_SAME_ACCESS) = 0 THEN FUNCTION = -5 : EXIT FUNCTION
    
      ' we no longer need the original (inheritable) handle
      CloseHandle(hReadPipeTmp)
    
      ' Spawn the child process
      LOCAL SI AS STARTUPINFO, pi AS PROCESS_INFORMATION, ExitCode AS LONG
      SI.cb           = SIZEOF(STARTUPINFO)
      SI.dwFlags      = %STARTF_USESTDHANDLES OR %STARTF_USESHOWWINDOW
      SI.wShowWindow  = %SW_HIDE '%SW_SHOWDEFAULT
      SI.hStdOutput   = hWritePipe
      SI.hStdError    = hWritePipeErr
    
      IF CreateProcess (BYVAL 0&, _                ' name of executable module
                        BYVAL STRPTR(CmdLine), _   ' command line string
                        BYVAL 0&, _                ' process security attributes
                        BYVAL 0&, _                ' thread security attributes
                        1, _                       ' handle inheritance flag
                        %CREATE_NEW_CONSOLE OR %IDLE_PRIORITY_CLASS, _     ' creation flags
                        BYVAL 0&, _                ' new environment block
                        StartDirectory, _          ' process initial drive and directory
                        si, _                      ' appearance of process main window
                        pi _                       ' structure that receives identification information about the new process
                       ) = 0 THEN FUNCTION = -1: EXIT FUNCTION
    
      ' the child process is launched so we can close handles we no longer need
      CloseHandle hWritePipe
      CloseHandle hWritePipeErr
    
      ' read from the pipe attached to the child process
      LOCAL chBuf AS ASCIIZ * 1024,BytesRead AS LONG
    
      DO
        IF ReadFile(hReadPipe, chBuf, SIZEOF(chBuf), BytesRead, BYVAL 0) = 0 THEN EXIT DO
        IF BytesRead = 0 THEN EXIT DO
        Result = Result + LEFT$(chBuf, BytesRead)
      LOOP
    
      ' make sure process gets terminated
      WaitForSingleObject PI.hProcess, dwMillisecondsWait
      GetExitCodeProcess PI.hProcess, ExitCode
    
      ' report the exit code of the child process
      Result = Result & $CRLF & "[Child Process Exit Code = " & FORMAT$(ExitCode,"") & "]" & $CRLF & $CRLF
    
      IF ExitCode = %STILL_ACTIVE THEN TerminateProcess pi.hProcess, 0: FUNCTION = -3 ELSE FUNCTION = ExitCode
    
      IF LEN(Result) THEN OemToCharBuff BYVAL STRPTR(Result), BYVAL STRPTR(Result), LEN(Result)
    
      ' Close the rest of the process and pipe handles
      CloseHandle hReadPipe
      CloseHandle pi.hThread
      CloseHandle pi.hProcess
    END FUNCTION
    
    FUNCTION GetAppPath() AS STRING
       ' get the folder where this EXE was launched from
       LOCAL appFilename  AS ASCIIZ * 255
       LOCAL PathPos      AS LONG
       '
       GetModuleFileName GetModuleHandle(""), appFilename, 255
       PathPos = INSTR(-1,appFilename,"\")
       FUNCTION = LEFT$(appFilename,PathPos)
    END FUNCTION
    
    SUB RunRMA(hDlg AS DWORD)
      LOCAL CmdLine AS STRING, ExitCode AS LONG, i AS LONG, j AS LONG
      LOCAL AppPath AS ASCIIZ * %MAX_PATH, AppShortPath AS ASCIIZ * %MAX_PATH
      LOCAL Msg AS STRING
    
      IF ARRAYATTR(RMFiles(),0) = 0 THEN  ' make sure we dropped some files to process
        BEEP
        Result = $DO_THIS
        EXIT SUB
      END IF
    
      ' find out what folder we were launched from as that is where we expect to find RMA.EXE
      AppPath = GetAppPath()
    
      ' obviate any problems with CreateProcess on earlier Windows versions
      GetShortPathName AppPath, AppShortPath, SIZEOF(AppShortPath)
    
      ' just for the record ...
      Result = "[Number Of Files Processed By RMA = " & FORMAT$(ARRAYATTR(RMFiles(),4),"") & "]" & $CRLF & $CRLF
    
      ' process all the dropped files, running RMA.EXE on each one
      ' for each of the specified command line options
      FOR i = LBOUND(RMFiles) TO UBOUND(RMFiles)
        Msg = "Processing file #" & FORMAT$(i,"") & ":" & $CRLF & RMFiles(i)
        CONTROL SET TEXT hDlg,%TXT_RESULT,Msg
        FOR j = LBOUND(Opts) TO UBOUND(Opts)
          ' run the console app with various options on the passed file name
          CmdLine = AppShortPath & "RMA.EXE " & Opts(j) & " " & $DQ & RMFiles(i) & $DQ
    
          ' launch the RMA.EXE child process
          ExitCode = ShellConsoleApp (CmdLine , AppPath, Result, 15000) ' wait a maximum of 15 secs
    
          ' process  any error codes
          SELECT CASE ExitCode
            CASE -1: MSGBOX "Can't start the program",, CmdLine
            CASE -2: MSGBOX "Can't read the console Output",, CmdLine
            CASE -3: MSGBOX "Execution canceled (time out)",, CmdLine
            CASE -4: MSGBOX "CreatePipe() failed",, CmdLine
            CASE -5: MSGBOX "DuplicateHandle() failed",, CmdLine
          END SELECT
        NEXT
      NEXT
    
      'Clean up any lines just ending in CRs in Result
      REPLACE $CRLF WITH CHR$(255) IN Result
      REPLACE $CR WITH $CRLF IN Result
      REPLACE CHR$(255) WITH $CRLF IN Result
    
      ' deallocate the file name array
      ERASE RMFiles()
    END SUB
    
    CALLBACK FUNCTION CB_Exit() AS LONG
      DIALOG END CBHNDL
    END FUNCTION
    
    CALLBACK FUNCTION CB_Run() AS LONG
      LOCAL DragFileName AS STRING
      LOCAL DragFileCount AS LONG
      LOCAL OptsStr AS STRING
      LOCAL i AS LONG
    
      ' clear the result variable
      Result = ""
    
      ' get the command line options (separated by the ";" character)
      CONTROL GET TEXT CBHNDL,%TXT_OPTS TO OptsStr
      REDIM Opts(1 TO PARSECOUNT(OptsStr,";"))
      PARSE OptsStr,Opts(),";"
    
      DragFileCount = ARRAYATTR(RMFiles(),4)
      IF DragFileCount > 0 THEN
        CONTROL SET TEXT CBHNDL,%TXT_RESULT,"Processing " & FORMAT$(DragFileCount,"") & " files using Real Media Analyzer ..."
      END IF
    
      ' run RMA on the files for each of the options
      RunRMA(CBHNDL)
      CONTROL SET TEXT CBHNDL,%TXT_RESULT,Result
    END FUNCTION
    
    CALLBACK FUNCTION CB_Main() AS LONG
      LOCAL hDrop AS DWORD
      LOCAL DragFileName AS ASCIIZ * %MAX_PATH
      LOCAL DragFileCount AS LONG
      LOCAL i AS LONG, hCtl AS DWORD
    
      SELECT CASE AS LONG CBMSG
        CASE %WM_COMMAND
          IF CBCTLMSG = 1 THEN  ' Accelerator
            IF CBCTL = %TXT_RESULT THEN
              CONTROL HANDLE CBHNDL,%TXT_RESULT TO hCtl
              SendMessage(hCtl,%EM_SETSEL,0,-1)
            END IF
          END IF
        CASE %WM_DROPFILES
          hDrop = CBWPARAM
          DragFileCount = DragQueryFile(hDrop, -1, DragFileName, SIZEOF(DragFileName))
          IF DragFileCount = 0 THEN EXIT FUNCTION
          REDIM RMFiles(1 TO DragFileCount)
          Result = "Number Of Files To Process = " & FORMAT$(DragFileCount,"") & $CRLF & $CRLF
          FOR i = 1 TO DragFileCount
            DragQueryFile(hDrop, i-1, DragFileName, SIZEOF(DragFileName))
            RMFiles(i) = DragFileName
            Result = Result & DragFileName & $CRLF
          NEXT
          DragFinish(hDrop)
          CONTROL SET TEXT CBHNDL,%TXT_RESULT,Result
      END SELECT
    END FUNCTION
    
    FUNCTION PBMAIN
      LOCAL hDlg AS DWORD
      DIM AccelTbl(1 TO 1) AS ACCELAPI
      LOCAL hAccel AS DWORD
    
      ' create and launch the GUI
      DIALOG NEW 0,"Real Media Analyzer (GUI Shell) v" & $VERSION,,,400,200, _
                 %WS_SYSMENU OR %WS_CAPTION, _
                 %WS_EX_WINDOWEDGE OR %WS_EX_ACCEPTFILES _ ' allow drag-and-drop
                 TO hDlg
    
      AccelTbl(1).FVIRT = 0
      AccelTbl(1).KEY = 1 ' ASCII for Ctrl-A
      AccelTbl(1).CMD = %TXT_RESULT
      ACCEL ATTACH hDlg, AccelTbl() TO hAccel
    
      'MSGBOX "hAccel = " & FORMAT$(hAccel,"")
    
      'add the controls
      CONTROL ADD TEXTBOX,hDlg,%TXT_RESULT,$DO_THIS,5,5,390,165, _
      %ES_READONLY OR %ES_MULTILINE OR %WS_VSCROLL OR %ES_WANTRETURN OR _
      %ES_AUTOVSCROLL OR %ES_NOHIDESEL, %WS_EX_CLIENTEDGE
      CONTROL ADD LABEL, hDlg,-1, _
                         "RMA Command Line Options (multiple options must be separated with ';' characters)", _
                         9,174,300,8
      CONTROL ADD TEXTBOX, hDlg,%TXT_OPTS,"-d;-cv",9,182,300,12
      CONTROL ADD BUTTON, hDlg,%BTN_RUN,"Run",320,176,30,18 CALL CB_Run()
      CONTROL ADD BUTTON, hDlg,%BTN_EXIT,"Exit",360,176,30,18 CALL CB_Exit()
      CONTROL SET FOCUS hDlg,%BTN_RUN
    
      ' wait for user interaction
      DIALOG SHOW MODAL hDlg CALL CB_Main
    END FUNCTION
    [This message has been edited by David Gwillim (edited February 12, 2005).]
    David Gwillim
    Noesis Corporation, NY

    noesisdgatverizondotnet

    GAIA - the Mother of us all
    Isaac Asimov's Gaia

  • #2
    Code:
    ' RMAShell.bas : Runs RMA.EXE on files dragged-and-dropped onto application,
    ' for each command line parameter specified.
    '
    ' RMA.EXE (Real Media Analyzer)is a console app that analyzes/repairs RealMedia files
    '
    '  Author: David Gwillim
    '    Date: 12 February 2005
    ' Version: 1.0.4
    '
    ' History: 2005-02-11 v1.0.0 Initial release
    '          2005-02-11 v1.0.1 Added progress display in main text box showing file name being processed
    '          2005-02-11 v1.0.2 Added Ctrl-A accelerator to Result textbox for selecting all the text
    '          2005-02-11 v1.0.3 Fix to ERASE RMFiles() array after processing, to prevent accidental repeat
    '                            Added version number to title bar
    '          2005-02-12 v1.0.4 Removed MsgBox statements for errors and replaced with output to %TXT_RESULT
    '                            Converted RunRMA to a thread function so the RMAShell interface is still
    '                            active during the loop spawning the child console app RMA.EXE multiple times
    '                            Added separator for each file's results to make output more readable
    '
    ' Copyright (c) 2005 by David Gwillim. Released to the Public Domain for use by others.
    '
    ' Console Child Process spawning code was based on the Microsoft article:
    '   "Spawn Console Processes with Redirected Standard Handles"
    '   ID: Q190351
    ' Also inspired by some C++ coding by Ted Ferenc in his RunConsoleApp freeware program
    ' See his website: [url="http://www.ndrw.co.uk/free/runconsoleapp/"]http://www.ndrw.co.uk/free/runconsoleapp/[/url] 
    '
    ' More useful info from Nick Adams at the code project:
    ' See: [url="http://www.codeproject.com/threads/redir.asp"]http://www.codeproject.com/threads/redir.asp[/url] 
    '
    ' Thanks also to Semen Matusovski who's posting on the PowerBasic forums prompted me
    ' to get this code running.
    '
    ' Many thanks to Alexey Pavluchenko for writing RMA.EXE. You can obtain a copy of this
    ' freeware from: [url="http://www.anime.com.ua/misc/alexey/rma.htm"]http://www.anime.com.ua/misc/alexey/rma.htm[/url] 
    '
    
    #COMPILE EXE
    #DIM ALL
    #REGISTER NONE
    #INCLUDE "Win32Api.Inc"
    
    $VERSION = "1.0.4"
    
    %TXT_RESULT = 100
    %TXT_OPTS   = 101
    %BTN_RUN    = 102
    %BTN_EXIT   = 103
    
    $DO_THIS    = "Drag-and-drop RealMedia files to here from Windows Explorer ..."
    
    GLOBAL Result AS STRING
    GLOBAL Opts() AS STRING
    GLOBAL RMFiles() AS STRING
    GLOBAL hThread AS DWORD
    
    FUNCTION ShellConsoleApp (CmdLine AS STRING, _
                              StartDirectory AS ASCIIZ, _
                              Result AS STRING, _
                              BYVAL dwMillisecondsWait AS DWORD _
                             ) AS LONG
    
      ' Set security attributes
      LOCAL sa AS SECURITY_ATTRIBUTES
      sa.nLength = SIZEOF(SECURITY_ATTRIBUTES)
      sa.lpSecurityDescriptor = 0&
      sa.bInheritHandle = 1 ' TRUE
    
      ' Create a new anonymous pipe
      LOCAL hReadPipeTmp AS DWORD, hReadPipe AS DWORD, hWritePipe AS DWORD, hWritePipeErr AS DWORD
      IF CreatePipe(hReadPipeTmp, hWritePipe, sa, BYVAL 0) = 0 THEN _
      FUNCTION = -4: EXIT FUNCTION
    
      LOCAL dwCP AS DWORD
      dwCP = GetCurrentProcess()
    
      ' Create a duplicate of the output write handle for the std error
      ' write handle. This is necessary in case the child application
      ' closes one of its std output handles.
      IF DuplicateHandle(dwCP,hWritePipe,GetCurrentProcess(),hWritePipeErr, _
                         0,1, _ ' has to be inheritable
                         %DUPLICATE_SAME_ACCESS)=0 THEN FUNCTION = -5 : EXIT FUNCTION
    
      ' Create new pipe read handle
      ' Set the inheritance properties to FALSE. Otherwise, the child
      ' inherits these handles; resulting in non-closeable
      ' handles to the pipes being created.
      IF DuplicateHandle(dwCP,hReadPipeTmp,dwCP,hReadPipe, _
                         0&, 0&, _          ' make it uninheritable.
                         %DUPLICATE_SAME_ACCESS) = 0 THEN FUNCTION = -5 : EXIT FUNCTION
    
      ' we no longer need the original (inheritable) handle
      CloseHandle(hReadPipeTmp)
    
      ' Spawn the child process
      LOCAL SI AS STARTUPINFO, pi AS PROCESS_INFORMATION, ExitCode AS LONG
      SI.cb           = SIZEOF(STARTUPINFO)
      SI.dwFlags      = %STARTF_USESTDHANDLES OR %STARTF_USESHOWWINDOW
      SI.wShowWindow  = %SW_HIDE '%SW_SHOWDEFAULT
      SI.hStdOutput   = hWritePipe
      SI.hStdError    = hWritePipeErr
    
      IF CreateProcess (BYVAL 0&, _                ' name of executable module
                        BYVAL STRPTR(CmdLine), _   ' command line string
                        BYVAL 0&, _                ' process security attributes
                        BYVAL 0&, _                ' thread security attributes
                        1, _                       ' handle inheritance flag
                        %CREATE_NEW_CONSOLE, _ 'OR %IDLE_PRIORITY_CLASS, _     ' creation flags
                        BYVAL 0&, _                ' new environment block
                        StartDirectory, _          ' process initial drive and directory
                        si, _                      ' appearance of process main window
                        pi _                       ' structure that receives identification information about the new process
                       ) = 0 THEN FUNCTION = -1: EXIT FUNCTION
    
      ' the child process is launched so we can close handles we no longer need
      CloseHandle hWritePipe
      CloseHandle hWritePipeErr
    
      ' read from the pipe attached to the child process
      LOCAL chBuf AS ASCIIZ * 1024,BytesRead AS LONG
    
      DO
        IF ReadFile(hReadPipe, chBuf, SIZEOF(chBuf), BytesRead, BYVAL 0) = 0 THEN EXIT DO
        IF BytesRead = 0 THEN EXIT DO
        Result = Result + LEFT$(chBuf, BytesRead)
      LOOP
    
      ' make sure process gets terminated
      WaitForSingleObject PI.hProcess, dwMillisecondsWait
      GetExitCodeProcess PI.hProcess, ExitCode
    
      ' report the exit code of the child process
      Result = Result & $CRLF & "[Child Process Exit Code = " & FORMAT$(ExitCode,"") & "]" & $CRLF & $CRLF
    
      IF ExitCode = %STILL_ACTIVE THEN TerminateProcess pi.hProcess, 0: FUNCTION = -3 ELSE FUNCTION = ExitCode
    
      IF LEN(Result) THEN OemToCharBuff BYVAL STRPTR(Result), BYVAL STRPTR(Result), LEN(Result)
    
      ' Close the rest of the process and pipe handles
      CloseHandle hReadPipe
      CloseHandle pi.hThread
      CloseHandle pi.hProcess
    END FUNCTION
    
    FUNCTION GetAppPath() AS STRING
       ' get the folder where this EXE was launched from
       LOCAL appFilename  AS ASCIIZ * 255
       LOCAL PathPos      AS LONG
       '
       GetModuleFileName GetModuleHandle(""), appFilename, 255
       PathPos = INSTR(-1,appFilename,"\")
       FUNCTION = LEFT$(appFilename,PathPos)
    END FUNCTION
    
    FUNCTION RunRMA(BYVAL hDlg AS DWORD) AS LONG   ' this function is run as a thread
      LOCAL CmdLine AS STRING, ExitCode AS LONG, i AS LONG, j AS LONG
      LOCAL AppPath AS ASCIIZ * %MAX_PATH, AppShortPath AS ASCIIZ * %MAX_PATH
      LOCAL Msg AS STRING
    
      FUNCTION = 0
    
      IF ARRAYATTR(RMFiles(),0) = 0 THEN  ' make sure we dropped some files to process
        BEEP
        Result = $DO_THIS
        EXIT FUNCTION
      END IF
    
      ' find out what folder we were launched from as that is where we expect to find RMA.EXE
      AppPath = GetAppPath()
    
      ' obviate any problems with CreateProcess on earlier Windows versions
      GetShortPathName AppPath, AppShortPath, SIZEOF(AppShortPath)
    
      ' just for the record ...
      Result = "[Number Of Files Processed By RMA = " & FORMAT$(ARRAYATTR(RMFiles(),4),"") & "]" & $CRLF & $CRLF & _
               REPEAT$(20,"====") & $CRLF & $CRLF
    
      ' process all the dropped files, running RMA.EXE on each one
      ' for each of the specified command line options
      FOR i = LBOUND(RMFiles) TO UBOUND(RMFiles)
        Msg = "Processing file #" & FORMAT$(i,"") & ":" & $CRLF & RMFiles(i)
        CONTROL SET TEXT hDlg,%TXT_RESULT,Msg
        FOR j = LBOUND(Opts) TO UBOUND(Opts)
          ' run the console app with various options on the passed file name
          CmdLine = AppShortPath & "RMA.EXE " & Opts(j) & " " & $DQ & RMFiles(i) & $DQ
    
          ' launch the RMA.EXE child process
          ExitCode = ShellConsoleApp (CmdLine , AppPath, Result, 15000) ' wait a maximum of 15 secs
    
          ' process  any error codes
          Msg = ""
          SELECT CASE ExitCode
            CASE -1: Msg = "Can't start the program"
            CASE -2: Msg = "Can't read the console Output"
            CASE -3: Msg = "Execution canceled (time out)"
            CASE -4: Msg = "CreatePipe() failed"
            CASE -5: Msg = "DuplicateHandle() failed"
          END SELECT
          IF Msg <> "" THEN Msg = Msg & $CRLF & CmdLine & $CRLF : CONTROL SET TEXT hDlg,%TXT_RESULT,Msg
          ' release time slice
          SLEEP 0&
        NEXT
        Result = Result & REPEAT$(20,"====") & $CRLF & $CRLF
      NEXT
    
      'Clean up any lines just ending in CRs in Result
      REPLACE $CRLF WITH CHR$(255) IN Result
      REPLACE $CR WITH $CRLF IN Result
      REPLACE CHR$(255) WITH $CRLF IN Result
    
      ' deallocate the file name array
      ERASE RMFiles()
    END FUNCTION
    
    CALLBACK FUNCTION CB_Exit() AS LONG
      DIALOG END CBHNDL
    END FUNCTION
    
    CALLBACK FUNCTION CB_Run() AS LONG
      LOCAL DragFileName AS STRING
      LOCAL DragFileCount AS LONG
      LOCAL OptsStr AS STRING
      LOCAL i AS LONG
    
      ' clear the result variable
      Result = ""
    
      ' get the command line options (separated by the ";" character)
      CONTROL GET TEXT CBHNDL,%TXT_OPTS TO OptsStr
      REDIM Opts(1 TO PARSECOUNT(OptsStr,";"))
      PARSE OptsStr,Opts(),";"
    
      DragFileCount = ARRAYATTR(RMFiles(),4)
      IF DragFileCount > 0 THEN
        CONTROL SET TEXT CBHNDL,%TXT_RESULT,"Processing " & FORMAT$(DragFileCount,"") & " files using Real Media Analyzer ..."
        CONTROL DISABLE CBHNDL,%BTN_RUN
        ' run a thread with RMA on the files for each of the options
        THREAD CREATE RunRMA(CBHNDL) TO hThread
        SetTimer CBHNDL,1,500,BYVAL 0&
      END IF
    END FUNCTION
    
    CALLBACK FUNCTION CB_Main() AS LONG
      LOCAL hDrop AS DWORD
      LOCAL DragFileName AS ASCIIZ * %MAX_PATH
      LOCAL DragFileCount AS LONG
      LOCAL i AS LONG, hCtl AS DWORD
      LOCAL ThreadStatus AS LONG
    
      SELECT CASE AS LONG CBMSG
        CASE %WM_COMMAND
          IF CBCTLMSG = 1 THEN  ' Accelerator
            IF CBCTL = %TXT_RESULT THEN
              CONTROL HANDLE CBHNDL,%TXT_RESULT TO hCtl
              SendMessage(hCtl,%EM_SETSEL,0,-1)
            END IF
          END IF
        CASE %WM_DROPFILES
          hDrop = CBWPARAM
          DragFileCount = DragQueryFile(hDrop, -1, DragFileName, SIZEOF(DragFileName))
          IF DragFileCount = 0 THEN EXIT FUNCTION
          REDIM RMFiles(1 TO DragFileCount)
          Result = "Number Of Files To Process = " & FORMAT$(DragFileCount,"") & $CRLF & $CRLF
          FOR i = 1 TO DragFileCount
            DragQueryFile(hDrop, i-1, DragFileName, SIZEOF(DragFileName))
            RMFiles(i) = DragFileName
            Result = Result & DragFileName & $CRLF
          NEXT
          DragFinish(hDrop)
          CONTROL SET TEXT CBHNDL,%TXT_RESULT,Result
        CASE %WM_TIMER
          IF CBWPARAM = 1 THEN
            THREAD STATUS hThread TO ThreadStatus
            IF ThreadStatus = 0 THEN  ' thread completed
              KillTimer CBHNDL,1
              CONTROL SET TEXT CBHNDL,%TXT_RESULT,Result
              CONTROL ENABLE CBHNDL,%BTN_RUN
              THREAD CLOSE hThread TO ThreadStatus
            END IF
          END IF
      END SELECT
    END FUNCTION
    
    FUNCTION PBMAIN
      LOCAL hDlg AS DWORD
      DIM AccelTbl(1 TO 1) AS ACCELAPI
      LOCAL hAccel AS DWORD
    
      ' create and launch the GUI
      DIALOG NEW 0,"Real Media Analyzer (GUI Shell) v" & $VERSION,,,400,200, _
                 %WS_SYSMENU OR %WS_CAPTION, _
                 %WS_EX_WINDOWEDGE OR %WS_EX_ACCEPTFILES _ ' allow drag-and-drop
                 TO hDlg
    
      AccelTbl(1).FVIRT = 0
      AccelTbl(1).KEY = 1 ' ASCII for Ctrl-A
      AccelTbl(1).CMD = %TXT_RESULT
      ACCEL ATTACH hDlg, AccelTbl() TO hAccel
    
      'MSGBOX "hAccel = " & FORMAT$(hAccel,"")
    
      'add the controls
      CONTROL ADD TEXTBOX,hDlg,%TXT_RESULT,$DO_THIS,5,5,390,165, _
      %ES_READONLY OR %ES_MULTILINE OR %WS_VSCROLL OR %ES_WANTRETURN OR _
      %ES_AUTOVSCROLL OR %ES_NOHIDESEL, %WS_EX_CLIENTEDGE
      CONTROL ADD LABEL, hDlg,-1, _
                         "RMA Command Line Options (multiple options must be separated with ';' characters)", _
                         9,174,300,8
      CONTROL ADD TEXTBOX, hDlg,%TXT_OPTS,"-d;-cv",9,182,300,12
      CONTROL ADD BUTTON, hDlg,%BTN_RUN,"Run",320,176,30,18 CALL CB_Run()
      CONTROL ADD BUTTON, hDlg,%BTN_EXIT,"Exit",360,176,30,18 CALL CB_Exit()
      CONTROL SET FOCUS hDlg,%BTN_RUN
    
      ' wait for user interaction
      DIALOG SHOW MODAL hDlg CALL CB_Main
    END FUNCTION
    ------------------
    David Gwillim
    Noesis Corporation, NY

    noesisdgatoptonlinedotnet

    There are 10 kinds of people.
    Those who understand binary arithmetic
    and those who do not.
    David Gwillim
    Noesis Corporation, NY

    noesisdgatverizondotnet

    GAIA - the Mother of us all
    Isaac Asimov's Gaia

    Comment


    • #3
      Code:
      ' RMAShell.bas : Runs RMA.EXE on files dragged-and-dropped onto application,
      ' for each command line parameter specified.
      '
      ' RMA.EXE (Real Media Analyzer)is a console app that analyzes/repairs RealMedia files
      '
      '  Author: David Gwillim
      '    Date: 17 February 2005
      ' Version: 1.0.9
      '
      ' History: 2005-02-11 v1.0.0 Initial release
      '          2005-02-11 v1.0.1 Added progress display in main text box showing file name being processed
      '          2005-02-11 v1.0.2 Added Ctrl-A accelerator to Result textbox for selecting all the text
      '          2005-02-11 v1.0.3 Fix to ERASE RMFiles() array after processing, to prevent accidental repeat
      '                            Added version number to title bar
      '          2005-02-12 v1.0.4 Removed MsgBox statements for errors and replaced with output to %TXT_RESULT
      '                            Converted RunRMA to a thread function so the RMAShell interface is still
      '                            active during the loop spawning the child console app RMA.EXE multiple times
      '                            Added separator for each file's results to make output more readable
      '          2005-02-12 v1.0.5 Profiled the child process speed with different values in the CreateProcess()
      '                            parameters. Found it runs a whole lot faster if the process and thread security
      '                            attributes are set with the same sa structure used to create the pipe handles.
      '          2005-02-17 v1.0.6 Made dialog resizable and added minimize and maximize boxes to sysmenu in title bar
      '          2005-02-17 v1.0.7 Added drawing in of resize icon in bottom right corner
      '                            Added saving and reloading last options used
      '                            Add a few more comments to the code
      '          2005-02-17 v1.0.8 Fixed the resize icon drawing that wasn't working when dialog was hidden
      '                             and shown again. Moved code into a SUB and then call it from %WM_PAINT
      '                            Ran IncLean (v1.27) on source to generate RMAShell.inc containing all Window's
      '                             API constant and function/sub declares to "freeze" the source independent of
      '                             PowerBASIC's Win2aAPI.inc version
      '                            Added Help button that runs RMA -? and loads it into the Results text box
      '          2005-02-17 v1.0.9 Fixed Help display. Result buffer wasn't being cleared before running RMA.EXE -?
      '                            Changed the "Run" button to be disabled until files are dropped
      '
      '
      ' To Do: Replace text box with combo box for options, and expand to multiple options save and reload
      '
      '
      ' Copyright (c) 2005 by David Gwillim. Released to the Public Domain for use by others.
      '
      ' Console Child Process spawning code was based on the Microsoft article:
      '   "Spawn Console Processes with Redirected Standard Handles"
      '   ID: Q190351
      ' Also inspired by some C++ coding by Ted Ferenc in his RunConsoleApp freeware program
      ' See his website: [url="http://www.ndrw.co.uk/free/runconsoleapp/"]http://www.ndrw.co.uk/free/runconsoleapp/[/url] 
      '
      ' More useful info from Nick Adams at the code project:
      ' See: [url="http://www.codeproject.com/threads/redir.asp"]http://www.codeproject.com/threads/redir.asp[/url] 
      '
      ' Thanks also to Semen Matusovski who's posting on the PowerBasic forums prompted me
      ' to get this code running.
      '
      ' Many thanks to Alexey Pavluchenko for writing RMA.EXE. You can obtain a copy of this
      ' freeware from: [url="http://www.anime.com.ua/misc/alexey/rma.htm"]http://www.anime.com.ua/misc/alexey/rma.htm[/url] 
      '
      
      #COMPILE EXE
      #DIM ALL
      #REGISTER NONE
      #INCLUDE "Win32Api.Inc"
      '#INCLUDE "RMAShell.inc"
      $VERSION = "1.0.9"
      
      %TXT_RESULT = 100
      %TXT_OPTS   = 101
      %BTN_RUN    = 102
      %BTN_EXIT   = 103
      %BTN_HELP   = 104
      %LBL_OPTS   = 105
      
      $DO_THIS    = "Drag-and-drop RealMedia files to here from Windows Explorer ..."
      
      GLOBAL Result AS STRING
      GLOBAL Opts() AS STRING
      GLOBAL RMFiles() AS STRING
      GLOBAL hThread AS DWORD
      
      FUNCTION ShellConsoleApp (CmdLine AS STRING, _
                                StartDirectory AS ASCIIZ, _
                                Result AS STRING, _
                                BYVAL dwMillisecondsWait AS DWORD _
                               ) AS LONG
      
        ' Set security attributes
        LOCAL sa AS SECURITY_ATTRIBUTES
        sa.nLength = SIZEOF(SECURITY_ATTRIBUTES)
        sa.lpSecurityDescriptor = 0&
        sa.bInheritHandle = 1 ' TRUE
      
        ' Create a new anonymous pipe
        LOCAL hReadPipeTmp AS DWORD, hReadPipe AS DWORD, hWritePipe AS DWORD, hWritePipeErr AS DWORD
        IF CreatePipe(hReadPipeTmp, hWritePipe, sa, 128) = 0 THEN _
        FUNCTION = -4: EXIT FUNCTION
      
        LOCAL dwCP AS DWORD
        dwCP = GetCurrentProcess()
      
        ' Create a duplicate of the output write handle for the std error
        ' write handle. This is necessary in case the child application
        ' closes one of its std output handles.
        IF DuplicateHandle(dwCP,hWritePipe,GetCurrentProcess(),hWritePipeErr, _
                           0,1, _ ' has to be inheritable
                           %DUPLICATE_SAME_ACCESS)=0 THEN FUNCTION = -5 : EXIT FUNCTION
      
        ' Create new pipe read handle
        ' Set the inheritance properties to FALSE. Otherwise, the child
        ' inherits these handles; resulting in non-closeable
        ' handles to the pipes being created.
        IF DuplicateHandle(dwCP,hReadPipeTmp,dwCP,hReadPipe, _
                           0&, 0&, _          ' make it uninheritable.
                           %DUPLICATE_SAME_ACCESS) = 0 THEN FUNCTION = -5 : EXIT FUNCTION
      
        ' we no longer need the original (inheritable) handle
        CloseHandle(hReadPipeTmp)
      
        ' Spawn the child process
        LOCAL SI AS STARTUPINFO, pi AS PROCESS_INFORMATION, ExitCode AS LONG
        SI.cb           = SIZEOF(STARTUPINFO)
        SI.dwFlags      = %STARTF_USESTDHANDLES OR %STARTF_USESHOWWINDOW
        SI.wShowWindow  = %SW_HIDE '%SW_SHOWDEFAULT
        SI.hStdOutput   = hWritePipe
        SI.hStdError    = hWritePipeErr
      
        IF CreateProcess (BYVAL 0&, _                ' name of executable module
                          BYVAL STRPTR(CmdLine), _   ' command line string
                          sa, _                      ' process security attributes
                          sa, _                      ' thread security attributes
                          1, _                       ' handle inheritance flag
                          %HIGH_PRIORITY_CLASS OR %CREATE_NEW_CONSOLE, _  ' creation flags
                          BYVAL 0&, _                ' new environment block
                          StartDirectory, _          ' process initial drive and directory
                          si, _                      ' appearance of process main window
                          pi _                       ' structure that receives identification information about the new process
                         ) = 0 THEN FUNCTION = -1: EXIT FUNCTION
      
        ' the child process is launched so we can close handles we no longer need
        CloseHandle hWritePipe
        CloseHandle hWritePipeErr
      
        ' read from the pipe attached to the child process
        LOCAL chBuf AS ASCIIZ * 1025,BytesRead AS LONG
      
        DO
          IF ReadFile(hReadPipe, chBuf, SIZEOF(chBuf)-1, BytesRead, BYVAL 0) = 0 THEN EXIT DO
          IF BytesRead = 0 THEN EXIT DO
          Result = Result + LEFT$(chBuf, BytesRead)
        LOOP
      
        ' make sure process gets terminated
        WaitForSingleObject PI.hProcess, dwMillisecondsWait
        GetExitCodeProcess PI.hProcess, ExitCode
      
        ' report the exit code of the child process
        Result = Result & $CRLF & "[RMA Exit Code = " & FORMAT$(ExitCode,"") & "]" & $CRLF & $CRLF
      
        IF ExitCode = %STILL_ACTIVE THEN TerminateProcess pi.hProcess, 0: FUNCTION = -3 ELSE FUNCTION = ExitCode
      
        IF LEN(Result) THEN OemToCharBuff BYVAL STRPTR(Result), BYVAL STRPTR(Result), LEN(Result)
      
        ' Close the rest of the process and pipe handles
        CloseHandle hReadPipe
        CloseHandle pi.hThread
        CloseHandle pi.hProcess
      END FUNCTION
      
      FUNCTION GetAppPath(BYVAL Delim AS STRING) AS STRING
         ' get the root name of this EXE: Delim = "."
         ' get the folder where this EXE was launched from: Delim = "\"
         LOCAL appFilename  AS ASCIIZ * 255
         LOCAL PathPos      AS LONG
         '
         GetModuleFileName GetModuleHandle(""), appFilename, 255
         PathPos = INSTR(-1,appFilename,Delim)
         FUNCTION = LEFT$(appFilename,PathPos)
      END FUNCTION
      
      
      SUB LoadLastRMA_Options(hDlg AS DWORD)
        LOCAL fn AS LONG
        LOCAL fName AS STRING
        LOCAL OptsStr AS STRING
      
        ' make sure ERR is 0
        fn = ERRCLEAR
        ' default options if .INI is not found
        OptsStr = "-d;-cv"
        ' open RMAShell.ini
        fName = GetAppPath(".") & "ini"
        fn = FREEFILE
        OPEN fName FOR INPUT AS #fn
        IF ERR = 0 THEN
          LINE INPUT #fn,OptsStr
          CLOSE fn
        END IF
        ' set the options in the UI
        CONTROL SET TEXT hDlg,%TXT_OPTS,OptsStr
      END SUB
      
      SUB SaveCurrentRMA_Options(hDlg AS DWORD)
        LOCAL fn AS LONG
        LOCAL fName AS STRING
        LOCAL OptsStr AS STRING
      
        ' get the current options from the UI
        CONTROL GET TEXT hDlg,%TXT_OPTS TO OptsStr
      
        ' write them out to RMAShell.ini
        fName = GetAppPath(".") & "ini"
        fn = FREEFILE
        OPEN fName FOR OUTPUT AS #fn
        PRINT #fn,OptsStr
        CLOSE fn
      END SUB
      
      FUNCTION RunRMA(BYVAL hDlg AS DWORD) AS LONG   ' this function is run as a thread
        LOCAL CmdLine AS STRING, ExitCode AS LONG, i AS LONG, j AS LONG
        LOCAL AppPath AS ASCIIZ * %MAX_PATH, AppShortPath AS ASCIIZ * %MAX_PATH
        LOCAL Msg AS STRING,FileCount AS LONG
      
        FUNCTION = 0
      
        IF ARRAYATTR(RMFiles(),0) = 0 THEN  ' make sure we dropped some files to process
          BEEP
          Result = $DO_THIS
          EXIT FUNCTION
        END IF
      
        ' find out what folder we were launched from as that is where we expect to find RMA.EXE
        AppPath = GetAppPath("\")
      
        ' obviate any problems with CreateProcess on earlier Windows versions
        GetShortPathName AppPath, AppShortPath, SIZEOF(AppShortPath)
      
        ' just for the record ...
        FileCount = ARRAYATTR(RMFiles(),4)
        Result = "[Number Of Files Processed By RMA = " & FORMAT$(FileCount,"") & "]" & $CRLF & $CRLF & _
                 REPEAT$(20,"====") & $CRLF & $CRLF
      
        ' process all the dropped files, running RMA.EXE on each one
        ' for each of the specified command line options
        FOR i = LBOUND(RMFiles) TO UBOUND(RMFiles)
          Msg = "Processing file #" & FORMAT$(i,"") & " of " & FORMAT$(FileCount,"") & ":" & $CRLF & RMFiles(i)
          CONTROL SET TEXT hDlg,%TXT_RESULT,Msg
          FOR j = LBOUND(Opts) TO UBOUND(Opts)
            ' run the console app with various options on the passed file name
            CmdLine = AppShortPath & "RMA.EXE " & Opts(j) & " " & $DQ & RMFiles(i) & $DQ
      
            ' launch the RMA.EXE child process
            ExitCode = ShellConsoleApp (CmdLine , AppPath, Result, 60000) ' wait a maximum of 60 secs
      
            ' process  any error codes
            Msg = ""
            SELECT CASE ExitCode
              CASE -1: Msg = "Can't start the program"
              CASE -2: Msg = "Can't read the console Output"
              CASE -3: Msg = "Execution canceled (time out)"
              CASE -4: Msg = "CreatePipe() failed"
              CASE -5: Msg = "DuplicateHandle() failed"
            END SELECT
            IF Msg <> "" THEN Msg = Msg & $CRLF & CmdLine & $CRLF : CONTROL SET TEXT hDlg,%TXT_RESULT,Msg
            ' release time slice
            SLEEP 0&
          NEXT
          Result = Result & REPEAT$(20,"====") & $CRLF & $CRLF
        NEXT
      
        'Clean up any lines just ending in CRs in Result
        REPLACE $CRLF WITH CHR$(255) IN Result
        REPLACE $CR WITH $CRLF IN Result
        REPLACE CHR$(255) WITH $CRLF IN Result
      
        ' deallocate the file name array
        ERASE RMFiles()
      END FUNCTION
      
      CALLBACK FUNCTION CB_Exit() AS LONG
        ' save last options used before we exit
        SaveCurrentRMA_Options(CBHNDL)
        ' shut down the program
        DIALOG END CBHNDL
      END FUNCTION
      
      CALLBACK FUNCTION CB_Help() AS LONG
        LOCAL ExitCode AS LONG
        LOCAL CmdLine AS STRING
        LOCAL AppPath AS ASCIIZ * %MAX_PATH
        LOCAL AppShortPath AS ASCIIZ * %MAX_PATH
      
        Result = ""
        AppPath = GetAppPath("\")
        GetShortPathName AppPath, AppShortPath, SIZEOF(AppShortPath)
        CmdLine = AppShortPath & "RMA.EXE -?"
      
        ExitCode = ShellConsoleApp (CmdLine , AppPath, Result, 60000) ' wait a maximum of 60 secs
      
        CONTROL SET TEXT CBHNDL,%TXT_RESULT,Result
      END FUNCTION
      
      CALLBACK FUNCTION CB_Run() AS LONG
        LOCAL DragFileName AS STRING
        LOCAL DragFileCount AS LONG
        LOCAL OptsStr AS STRING
        LOCAL i AS LONG
      
        ' clear the result variable
        Result = ""
      
        ' get the command line options (separated by the ";" character)
        CONTROL GET TEXT CBHNDL,%TXT_OPTS TO OptsStr
        REDIM Opts(1 TO PARSECOUNT(OptsStr,";"))
        PARSE OptsStr,Opts(),";"
      
        DragFileCount = ARRAYATTR(RMFiles(),4)
        IF DragFileCount > 0 THEN
          CONTROL SET TEXT CBHNDL,%TXT_RESULT,"Processing " & FORMAT$(DragFileCount,"") & " files using Real Media Analyzer ..."
          CONTROL DISABLE CBHNDL,%BTN_RUN
          ' run a thread with RMA on the files for each of the options
          THREAD CREATE RunRMA(CBHNDL) TO hThread
          SetTimer CBHNDL,1,100,BYVAL 0&
        END IF
      END FUNCTION
      
      SUB DrawResizeIcon(hDlg AS DWORD)
        LOCAL hBitMap AS DWORD
        LOCAL hDC AS DWORD
        LOCAL hMemDC AS DWORD
        LOCAL x AS LONG, y AS LONG
        LOCAL rc AS RECT
      
        ' draw in the resize corner icon on the dialog bottom right
      
        ' load the resizing corner bitmap
        hBitMap = LoadBitmap(BYVAL 0&,BYVAL %OBM_SIZE)
      
        GetClientRect(hDlg,rc)
        x = rc.nRight - rc.nLeft
        y = rc.nBottom - rc.nTop
      
        hDC = GetDC(hDlg)
        hMemDC = CreateCompatibleDC(hDC)
      
        SelectObject(hMemDC, hBitmap)
        BitBlt(hDC,x-13,y-13,13,13,hMemDC,0,0,%SRCCOPY)
      
        DeleteDC(hMemDC)
        ReleaseDC(hDlg,hDC)
        DeleteObject(hBitmap)
      END SUB
      
      CALLBACK FUNCTION CB_Main() AS LONG
        LOCAL hDrop AS DWORD
        LOCAL DragFileName AS ASCIIZ * %MAX_PATH
        LOCAL DragFileCount AS LONG
        LOCAL i AS LONG, hCtl AS DWORD
        LOCAL ThreadStatus AS LONG
        LOCAL x AS LONG, y AS LONG
        LOCAL rc AS RECT, pRc AS RECT PTR
        STATIC minx AS LONG
        STATIC miny AS LONG
        LOCAL ps AS PAINTSTRUCT
      
        SELECT CASE AS LONG CBMSG
          CASE %WM_INITDIALOG
            ' disable contrl until files are dropped
            CONTROL DISABLE CBHNDL,%BTN_RUN
            ' reload the last options used
            LoadLastRMA_Options(CBHNDL)
            ' set the small size limit for the dialog
            DIALOG GET SIZE CBHNDL TO x, y
            DIALOG UNITS CBHNDL, x, y TO PIXELS x, y
            minx = x * 72/100
            miny = y * 40/100
      
          CASE %WM_DESTROY
      
          CASE %WM_COMMAND
            ' process the Ctrl-A accelerator key
            IF CBCTLMSG = 1 THEN  ' Accelerator
              IF CBCTL = %TXT_RESULT THEN
                ' select all the text in the %TXT_RESULT textbox
                CONTROL HANDLE CBHNDL,%TXT_RESULT TO hCtl
                SendMessage(hCtl,%EM_SETSEL,0,-1)
              END IF
            END IF
      
          CASE %WM_DROPFILES
            ' handle the drag-and-dropping of files
            hDrop = CBWPARAM
            DragFileCount = DragQueryFile(hDrop, -1, DragFileName, SIZEOF(DragFileName))
            IF DragFileCount = 0 THEN EXIT FUNCTION
            REDIM RMFiles(1 TO DragFileCount)
            Result = "Number Of Files To Process = " & FORMAT$(DragFileCount,"") & $CRLF & $CRLF
            FOR i = 1 TO DragFileCount
              DragQueryFile(hDrop, i-1, DragFileName, SIZEOF(DragFileName))
              RMFiles(i) = DragFileName
              Result = Result & DragFileName & $CRLF
            NEXT
            DragFinish(hDrop)
            IF DragFileCount > 0 THEN CONTROL ENABLE CBHNDL,%BTN_RUN
            CONTROL SET TEXT CBHNDL,%TXT_RESULT,Result
      
          CASE %WM_SIZING
            ' limit how small the dialog box can be made during resizing
            pRC = CBLPARAM
            GetWindowRect CBHNDL, rc  ' current coordinates on screen,
            SELECT CASE LONG CBWPARAM
              CASE %WMSZ_TOP
                @pRC.nTop = rc.nBottom - MAX%(@pRC.nBottom - @pRC.nTop,miny)
              CASE %WMSZ_LEFT
                @pRc.nLeft  = rc.nRight - MAX%(@pRC.nRight - @pRC.nLeft,minx)
              CASE %WMSZ_BOTTOM
                @pRC.nBottom = rc.nTop + MAX%(@pRC.nBottom - @pRC.nTop,miny)
              CASE %WMSZ_RIGHT
                @pRc.nRight  = rc.nLeft + MAX%(@pRC.nRight - @pRC.nLeft,minx)
              CASE %WMSZ_TOPRIGHT
                @pRC.nTop = rc.nBottom - MAX%(@pRC.nBottom - @pRC.nTop,miny)
                @pRc.nRight  = rc.nLeft + MAX%(@pRC.nRight - @pRC.nLeft,minx)
              CASE %WMSZ_BOTTOMLEFT
                @pRC.nBottom = rc.nTop + MAX%(@pRC.nBottom - @pRC.nTop,miny)
                @pRc.nLeft  = rc.nRight - MAX%(@pRC.nRight - @pRC.nLeft,minx)
              CASE %WMSZ_TOPLEFT
                @pRc.nLeft  = rc.nRight - MAX%(@pRC.nRight - @pRC.nLeft,minx)
                @pRC.nTop = rc.nBottom - MAX%(@pRC.nBottom - @pRC.nTop,miny)
              CASE %WMSZ_BOTTOMRIGHT
                @pRc.nRight  = rc.nLeft + MAX%(@pRC.nRight - @pRC.nLeft,minx)
                @pRC.nBottom = rc.nTop + MAX%(@pRC.nBottom - @pRC.nTop,miny)
            END SELECT
            FUNCTION = 1
      
          CASE %WM_PAINT
            BeginPaint(CBHNDL,ps)
            DrawResizeIcon(CBHNDL)
            EndPaint(CBHNDL,ps)
      
          CASE %WM_SIZE
            ' resize and relocate the controls to fit the new dialog box size
            DIALOG GET CLIENT CBHNDL TO x,y
            CONTROL SET SIZE CBHNDL,%TXT_RESULT,x-10,y-40
            CONTROL SET SIZE CBHNDL,%TXT_OPTS,x-100,12
            CONTROL SET LOC CBHNDL,%TXT_OPTS,9,y-23
            CONTROL SET LOC CBHNDL,%LBL_OPTS,9,y-32
            CONTROL SET LOC CBHNDL,%BTN_HELP,x-90,y-23
            CONTROL SET LOC CBHNDL,%BTN_RUN,x-75,y-24
            CONTROL SET LOC CBHNDL,%BTN_EXIT,x-40,y-24
      
            DIALOG REDRAW CBHNDL
      
            FUNCTION = 0
            EXIT FUNCTION
      
          CASE %WM_TIMER
            ' check for RunRMA() thread completion
            IF CBWPARAM = 1 THEN
              THREAD STATUS hThread TO ThreadStatus
              IF ThreadStatus = 0 THEN  ' thread completed
                KillTimer CBHNDL,1
                CONTROL SET TEXT CBHNDL,%TXT_RESULT,Result
                THREAD CLOSE hThread TO ThreadStatus
              END IF
            END IF
        END SELECT
      END FUNCTION
      
      FUNCTION PBMAIN
        LOCAL hDlg AS DWORD
        DIM AccelTbl(1 TO 1) AS ACCELAPI
        LOCAL hAccel AS DWORD
      
        ' create the GUI dialog box
        DIALOG NEW 0,"Real Media Analyzer (GUI Shell) v" & $VERSION,,,400,200, _
                   %WS_SYSMENU OR %WS_CAPTION OR %WS_THICKFRAME OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX, _
                   %WS_EX_WINDOWEDGE OR %WS_EX_ACCEPTFILES _ ' allow drag-and-drop
                   TO hDlg
      
        ' add an accelerator key of Ctrl-A that selects all the text in textbox %TXT_RESULT
        AccelTbl(1).FVIRT = 0
        AccelTbl(1).KEY = 1 ' ASCII for Ctrl-A
        AccelTbl(1).CMD = %TXT_RESULT
        ACCEL ATTACH hDlg, AccelTbl() TO hAccel
      
        'add the controls
        CONTROL ADD TEXTBOX,hDlg,%TXT_RESULT,$DO_THIS,5,5,390,165, _
        %ES_READONLY OR %ES_MULTILINE OR %WS_VSCROLL OR %ES_WANTRETURN OR _
        %ES_AUTOVSCROLL OR %ES_NOHIDESEL, %WS_EX_CLIENTEDGE
        CONTROL ADD LABEL, hDlg,%LBL_OPTS, _
                           "RMA Command Line Options (multiple options must be separated with ';' characters)", _
                           9,174,300,8
        CONTROL ADD TEXTBOX, hDlg,%TXT_OPTS,"-d;-cv",9,182,300,12
        CONTROL ADD BUTTON, hDlg,%BTN_HELP,"?",320,176,10,12 CALL CB_Help()
        CONTROL ADD BUTTON, hDlg,%BTN_RUN,"Run",325,176,30,18 CALL CB_Run()
        CONTROL ADD BUTTON, hDlg,%BTN_EXIT,"Exit",360,176,30,18 CALL CB_Exit()
        CONTROL SET FOCUS hDlg,%BTN_RUN
      
        ' wait for user interaction
        DIALOG SHOW MODAL hDlg CALL CB_Main
      END FUNCTION
      ------------------
      David Gwillim
      Noesis Corporation, NY

      noesisdgatoptonlinedotnet

      There are 10 kinds of people.
      Those who understand binary arithmetic
      and those who do not.



      [This message has been edited by David Gwillim (edited February 17, 2005).]
      David Gwillim
      Noesis Corporation, NY

      noesisdgatverizondotnet

      GAIA - the Mother of us all
      Isaac Asimov's Gaia

      Comment

      Working...
      X