Announcement

Collapse
No announcement yet.

automatically run process in ddt

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

  • Shawn Anderson
    replied
    Curious what the link above has to do with splash screens.
    Well it's a long story but if you want to know....

    At a customer location, every time a user logs into the domain, their computer checks a location on a server for newer versions of files to copy to their computer. What we found was since this was done via windows scheduler, it didn't show anything happening; it ran in the background. This is a problem because they don't want the user running program x until all the new files are copied. Sometimes this could take 2 or 3 minutes so they wanted to give the user a splash while this was happening so the user would know not to run the program. I found that if I shelled out from a PBCC program, it showed the copy process from the scheduled task. I simply wanted to give a little "copying files" notification and have the files copying underneath. I was going to use a VIEW statement but alas, PB doesn't have that. Then I thought that I could perhaps use PBWIN to create a splash then run the xcopy in a console window (this thread) but that was proving too time consuming for me on this stupid little nothing project (though I did learn from everybody's posts). I ended up using a console window (the other thread). I'd also like to mention that I think this process of copying files around is kludgy, but it wasn't my idea. I was just turd-polishing an existing situation.

    whew!

    Leave a comment:


  • Mike Doty
    replied
    Curious what the link above has to do with splash screens.
    I just came up with another (that I was using) and just
    applied it to splash up stuff on a console when somebody
    hits certain things on web pages.
    Code:
    REM It works like this:
    REM User entered user name and password into buffer$
    REM 
    IF found THEN
      play "\home\root\www\mysound.wav"
      x = SHELL ("c:\home\root\splash.exe 30000,USER IS DOWNLOADING,"+ buffer)
    END IF

    Example: SPLASH 10000,MY TITLE HERE, MY CAPTION HERE

    Code:
    '-------------------------------------------------------------------------------
    '
    '   HELLOWIN.BAS for PB/DLL
    '   Copyright (c) 1997,8 by PowerBASIC, Inc.
    '
    '   Translation of HELLOWIN.C from Charles Petzold's book:
    '
    '     "Programming Windows 95" published by Microsoft Press.
    '     ISBN 1-55615-676-6
    '
    '   Note: The original code does not contain the "gradient" effect.
    '
    '-------------------------------------------------------------------------------
    '6.1 has a type WndClass. Use Local WinClass was WndClassEx
    $COMPILE EXE
    $INCLUDE "WIN32API.INC"
    '$RESOURCE "HELLOWIN.PBR"        'put this back
    '------------------------------------------------------------------------------
    FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                      BYVAL hPrevInstance AS LONG, _
                      BYVAL lpCmdLine     AS LONG, _
                      BYVAL iCmdShow      AS LONG) AS LONG
      GLOBAL zSplashMessage AS ASCIIZ * 200
      GLOBAL zWindowCaption AS ASCIIZ * 80
      GLOBAL SleepInMilliseconds AS LONG
      IF LEN(COMMAND$) = 0 THEN   'if nothing passed on command line use these defaults
         SleepInMilliseconds = 2000
        zWindowCaption  = "My Default Title"
        zSplashMessage$ = "My Default Caption"
      ELSE                      'read 3 parameters passed in shell   TIMEOUT,TITLE,CAPTION
        SleepInMilliseconds = VAL(PARSE$(COMMAND$,1))
        zWindowCaption      = PARSE$(COMMAND$,2)
        zSplashMessage      = PARSE$(COMMAND$,3)
      END IF
      LOCAL Msg         AS tagMsg
      LOCAL Winclass    AS WndClassEx
      LOCAL szAppName   AS ASCIIZ * 80
      LOCAL hWnd        AS LONG
      szAppName              = "SPLASHBOX"
      WinClass.cbSize        = SIZEOF(WinClass)
      WinClass.style         = %CS_HREDRAW OR %CS_VREDRAW
      ' CODEPTR is used to pass the address of the function which will
      ' receive all messages sent to any window created with this class
      WinClass.lpfnWndProc   = CODEPTR( WndProc )
      WinClass.cbClsExtra    = 0
      WinClass.cbWndExtra    = 0
      WinClass.hInstance     = hInstance
      WinClass.hIcon         = LoadIcon( hInstance, "HELLOWIN" )
      WinClass.hCursor       = LoadCursor( %NULL, BYVAL %IDC_ARROW )
      WinClass.hbrBackground = GetStockObject( %WHITE_BRUSH )
      WinClass.lpszMenuName  = %NULL
      WinClass.lpszClassName = VARPTR( szAppName )
      WinClass.hIconSm       = LoadIcon( hInstance, BYVAL %IDI_APPLICATION )
      RegisterClassEx WinClass
      ' Create a window using the registered class
      hWnd = CreateWindow(szAppName, _               ' window class name
                          zWindowCaption, _          ' window caption
                          %WS_OVERLAPPEDWINDOW, _    ' window style
                          %CW_USEDEFAULT, _          ' initial x position
                          %CW_USEDEFAULT, _          ' initial y position
                          %CW_USEDEFAULT, _          ' initial x size
                          %CW_USEDEFAULT, _          ' initial y size
                          %NULL, _                   ' parent window handle
                          %NULL, _                   ' window menu handle
                          hInstance, _               ' program instance handle
                          BYVAL %NULL)               ' creation parameters
    
          ShowWindow hWnd, iCmdShow
          UpdateWindow hWnd
      ' Main message loop:
      ' Messages sent to HELLOWIN while it has the focus are received by
      ' GetMessage().  This loop translates each message and dispatches it
      ' to the appropriate handler.  When PostQuitMessage() is called, the
      ' loop terminates which ends the application.
      WHILE GetMessage(Msg, %NULL, 0, 0)
        TranslateMessage Msg
        DispatchMessage Msg
      WEND
      FUNCTION = msg.wParam
    END FUNCTION  ' WinMain
    '------------------------------------------------------------------------------
    SUB DrawGradient(BYVAL hWnd AS LONG)
      LOCAL hDC AS LONG
      LOCAL rectFill AS RECT
      LOCAL rectClient AS RECT
      LOCAL fStep AS SINGLE
      LOCAL hBrush AS LONG
      LOCAL iOnBand AS INTEGER
      hDC = GetDC(hWnd)
      GetClientRect hWnd, rectClient
      fStep = rectClient.nbottom / 200
      FOR iOnBand = 0 TO 199
        SetRect rectFill, 0, iOnBand * fStep, rectClient.nright+1, (iOnBand+1) * fStep
        hBrush = CreateSolidBrush(RGB(0,0,(255-iOnBand)))
        Fillrect hDC, rectFill, hBrush
        DeleteObject hBrush
      NEXT
      ReleaseDC hWnd, hDC
    END SUB
    '------------------------------------------------------------------------------
    ' WndProc is the message handler for all windows creating using the HelloWin
    ' class name.  A single WndProc procedure can handle multiple windows by
    ' testing the hWnd variable passed to it.
    FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                      BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
      LOCAL hDC       AS LONG
      LOCAL LpPaint   AS PaintStruct
      LOCAL tRect     AS Rect
      ' The SELECT CASE is used to catch only those messages which the message
      ' handler needs to process.  All other messages are passed through the
      ' tests to the default handler.
      SELECT CASE wMsg
        CASE %WM_CREATE
        CASE %WM_PAINT
          hDC = BeginPaint(hWnd, LpPaint)
          GetClientRect hWnd, tRect
          SetBkMode hDC, %TRANSPARENT
          SetTextColor hDC, %WHITE
          DrawText hDC, zSplashMessage, -1, tRect, %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
          EndPaint hWnd, LpPaint
          SLEEP SleepInMilliseconds:PostQuitMessage 0    'added 10/2/01
          FUNCTION = 0
          EXIT FUNCTION
        CASE %WM_ERASEBKGND
          DrawGradient hWnd
          FUNCTION = 1
          EXIT FUNCTION
        CASE %WM_DESTROY
          PostQuitMessage 0
          FUNCTION = 0
          EXIT FUNCTION
      END SELECT
      ' Any message which is not handled in the above SELECT CASE reaches this
      ' point and is process by Windows default message handler.
      FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
    END FUNCTION
    Last edited by Mike Doty; 10 Oct 2009, 07:28 AM.

    Leave a comment:


  • Shawn Anderson
    replied
    Thanks everybody. This is a learning process so all your information is good to learn and have here for digestion.
    I did end up going a different way on what I thought would be a simple task.

    http://www.powerbasic.com/support/pb...947#post324947

    Leave a comment:


  • Jeff Blakeney
    replied
    I did this years ago while working with my brother. I created a DDT dialog and used DIALOG SHOW MODAL to display it. In the %WM_INITDIALOG section of the dialog procedure I created a tray icon and then a thread called WindowTimer (although thinking about it now there are probably better ways to handle this) that looked like this:

    Code:
    FUNCTION WindowTimer(BYVAL hDlg AS LONG) AS LONG
    
        SLEEP 10000
        IF IsWindowVisible(hDlg) = %TRUE THEN
            PostMessage hDlg, %WM_SYSCOMMAND, %SC_CLOSE, 0
        END IF
    
    END FUNCTION
    The PostMessage can be replaced with DIALOG POST if desired. The WindowTimer routine allowed the window to show for about 10 seconds before hiding it leaving only the tray icon to indicate that the program was running.

    The catch here is that I added this extra code to my dialog procedure:

    Code:
            CASE %WM_SYSCOMMAND
                SELECT CASE LOWRD(CBWPARAM)
                    CASE %SC_MINIMIZE, %SC_CLOSE
                        IF CBWPARAM = %SC_CLOSE AND ghEndFlag <> 0 THEN
                            ' End program
                            DIALOG END CBHNDL
                        ELSE
                            ' Hide the window so it doesn't appear in the task bar
                            DIALOG SHOW STATE CBHNDL, %SW_HIDE
                        END IF
                        FUNCTION = 1
                END SELECT
    This will hide the window unless we are actually end the program. ghEndFlag gets set only when the user selects the Exit option from the pop up menu.

    Leave a comment:


  • Michael Mattias
    replied
    >Dang. Programming is hard

    That's why programmers get the big bucks. Well, good programmers do, anyway.

    Leave a comment:


  • Mike Doty
    replied
    Based upon Michael's thread suggestion.
    Use POST not SEND

    Code:
    #PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    #COMPILE EXE
    #DIM ALL
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #INCLUDE "PBForms.INC"
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1 =  101
    %IDC_LABEL1  = 1001
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
            CASE %WM_COMMAND
                ' Process control notifications
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt  AS LONG
        LOCAL hThread AS LONG
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
        LOCAL hDlg   AS DWORD
        LOCAL hFont1 AS DWORD
        DIALOG NEW hParent, "Pargon update", 286, 232, 201, 40, %WS_POPUP OR _
            %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR _
            %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
            %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
            %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "updating files.....", 10, 10, 170, _
            15
        hFont1 = PBFormsMakeFont("MS Sans Serif", 14, 400, %FALSE, %FALSE, _
            %FALSE, %ANSI_CHARSET)
        CONTROL SEND hDlg, %IDC_LABEL1, %WM_SETFONT, hFont1, 0
    #PBFORMS END DIALOG
        THREAD CREATE MyThread(hDlg) TO hThread
        SLEEP 50
        THREAD CLOSE hThread TO hThread
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
        DeleteObject hFont1
    #PBFORMS END CLEANUP
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    THREAD FUNCTION MyThread(BYVAL hDlg AS DWORD) AS LONG
      LOCAL x AS LONG
      FOR x = 1 TO 3:BEEP: SLEEP 500: NEXT
      DIALOG POST hDlg, %WM_SYSCOMMAND, %SC_CLOSE, 0  'do not use SEND
    END FUNCTION

    Leave a comment:


  • Shawn Anderson
    replied
    Dang. Programming is hard.

    Thanks, I'll take a look.

    Leave a comment:


  • Michael Mattias
    replied
    Or... perhaps easier still... run the splash screen in a separate thread of execution

    See this demo:
    Progress Bar Dialog for PB/CC programs October 24, 2002
    (Ignore the "PB/CC" in the thread title. This will work in a GUI program exactly the same way).

    Instead of RegisterClass/CreateWindowEx/Standard message loop, do your DIALOG NEW, DIALOG SHOW MODELESS and DDT message loop in the thread function.

    Now your program is ...
    Code:
      THREAD CREATE SplashScreenProc (param) to hThread 
       
      RunMyFunction
      Post WM_CLOSE to hDLG of splash screen proc 
      WaitForSingleObject hThread, %INFINITE   ' wait for splash screen proc to end 
      THREAD CLOSE hThread to uselessVar
       .... rest of code
    MCM

    Leave a comment:


  • Mike Doty
    replied
    Agreed.
    The MSGBOX statement probably worked like a message pump.

    Leave a comment:


  • Michael Mattias
    replied
    Code:
    DIALOG SHOW MODELESS hDlg, CALL ShowDIALOG1Proc TO lRslt
    ? "Call your function here"
    DIALOG END hDlg
    ????

    Um, I think that is missing a message loop and the splash screen will not repaint itself if it is dragged around or covered/uncovered by another window.

    Better I think to call your function from the splash screen window procedure with a message loop running... and of course, run it in a separate thread of execution if it takes more than one-tenth second.

    MCM

    Leave a comment:


  • Shawn Anderson
    replied
    modeless! what will they think of next.

    yes that works great, thanks

    Leave a comment:


  • Mike Doty
    replied
    It appears you are using DDT for more than just a splash screen.
    How about this?
    Code:
    DIALOG SHOW MODELESS hDlg, CALL ShowDIALOG1Proc TO lRslt
    ? "Call your function here"
    DIALOG END hDlg
    Chris was posting the solution at the same time.
    Last edited by Mike Doty; 3 Oct 2009, 02:24 PM.

    Leave a comment:


  • Chris Holbrook
    replied
    Have you considered starting a modeless dialog from which to run your function? On completion, the modeless one can send a "user message" to the main dialog, on receipt of which the main dialog can terminate or do something else. Or the main can sit around occasionaly checking to see if the modeless one is still there.
    Last edited by Chris Holbrook; 3 Oct 2009, 02:16 PM.

    Leave a comment:


  • Shawn Anderson
    started a topic automatically run process in ddt

    automatically run process in ddt

    I have a ddt program that I'm only using the gui for a "splash" screen while the process runs.

    My question:
    where/how to I start my program and have it automatically call a function or whatever and close when the function completes?
    I assume I need to put something in ShowDIALOG1Proc()...

    Code:
    #PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #INCLUDE "PBForms.INC"
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1 =  101
    %IDC_LABEL1  = 1001
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        SELECT CASE AS LONG CBMSG
            
            CASE %WM_INITDIALOG
                ' Initialization handler
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
    
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt  AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
        LOCAL hDlg   AS DWORD
        LOCAL hFont1 AS DWORD
    
        DIALOG NEW hParent, "Pargon update", 286, 232, 201, 40, %WS_POPUP OR _
            %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR _
            %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
            %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
            %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "updating files.....", 10, 10, 170, _
            15
    
        hFont1 = PBFormsMakeFont("MS Sans Serif", 14, 400, %FALSE, %FALSE, _
            %FALSE, %ANSI_CHARSET)
    
        CONTROL SEND hDlg, %IDC_LABEL1, %WM_SETFONT, hFont1, 0
    #PBFORMS END DIALOG
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                                                             
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
        DeleteObject hFont1
    #PBFORMS END CLEANUP
    
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
Working...
X