Shutdown a prog. and restart it again within the program ?

Shutdown a prog. and restart it again within the program ?

Postby ukoenig » Sat Dec 11, 2010 9:19 am

Hello,

In some Situations, I have to change some basic-settings and need to restart the Program.
The normal way : using the close/exit - button and start/activate the program again from Desktop with new Settings.

A better Solution would be :
to shutdown a program and restart it again within the program, is it possible ?

I got it working like :

====

STATIC cImage1

FUNCTION MAIN()
..
..
// only once at start
// Init Var with a value, because cImage1 = NIL

IF cImage1 = NIL
cImage1 := c_Path + "\bitmaps\Back3.jpg"
ELSE
here maybe possible, to close Window 1 ??? ( 2. call of MAIN() )
ENDIF
...
...
DEFINE IMAGE oTmp FILENAME cImage1
oBrush1 := TBrush():new( ,,,, ResizeBmp( oTmp:hBitmap, 1024, 768 - 145, .T. ) )
DEFINE WINDOW oWndMain FROM 1, 1 TO 20, 70 ;
TITLE "I am the MDI Frame" MDI BRUSH oBrush1
oTmp:End()
..
..
With the Reset Button, cImage1 is getting a new value < Back1.jpg > and isn't NIL anymore.
Calling MAIN again, the old Init-value of cImage1( Back3.jpg ) is not used and the new Background is shown.
It works as a Solution, changing the Background of the Main-window.
The problem, closing the Program, closes only the new / replaced 2. Window and still shows the 1. Window from Start.
The Start-Window must be closed, AFTER the new call of MAIN !!!
...
...
@ 240, 90 BTNBMP oBtn3 OF oWndEdit PIXEL ;
SIZE 150 , 80 PROMPT "Reset" 2007 ;
FONT oFont1 ;
TOP ;
NOBORDER ;
FILENAME c_Path + "\bitmaps\32x32\Reset.bmp" ;
ACTION ( cImage1 := c_Path + "\bitmaps\Back1.jpg", MAIN() )
...
...
ACTIVATE WINDOW oWndMain MAXIMIZED

RETURN NIL

===============

Best Regards
Uwe :lol:
Last edited by ukoenig on Thu Dec 16, 2010 6:03 pm, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Shutdown a prog. and restart it again whitin the program ?

Postby Adolfo » Mon Dec 13, 2010 11:41 am

Uwe

Which are those basic settigns you need to change.. can't they be changed "on line" ?
Do you use Public variables to host them.?

From Chile
Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
User avatar
Adolfo
 
Posts: 860
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Shutdown a prog. and restart it again whitin the program ?

Postby gkuhnert » Mon Dec 13, 2010 11:57 am

Uwe,
Maybe you could create a new small program that calls your original program after a waiting time of one second. This one second would enable your program to be closed before it's being called.
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Shutdown a prog. and restart it again whitin the program ?

Postby ukoenig » Mon Dec 13, 2010 3:15 pm

Thank You very much for the response.

I think I must explain it a better way, what I'm trying to do : changing the Background of the Main-window.
( something like a Desktop-changer defined from User ).

With Child and Dialogs it works fine.

To show a new Main-window-background, my old Solution is :
saving the name of the new Image and restart the Application, because oWnd:Refresh() doesn't work on Wndmain.

I started another Test and called MAIN() again, with a new defined Background-image.

It works, but the old Window is still behind the new created one, showing the new defined Background-Image.
2 Main-windows are created after the new background-selection.
Because of this situation, oWnd:End() doesn't close the Application, it shows the 1. old Window.
I think, I have to save / remember the Handle of the 1. Window.
Using a < change-Desktop-Button >, the 1. ( old ) Window must be closed after the new Window is created ?

Any sample, how it could be done ( Application-desktop-changer ) ?

Image

MDI-frame-Image : select and replace

Image

Best Regards
Uwe :roll:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Shutdown a prog. and restart it again whitin the program ?

Postby Daniel Garcia-Gil » Mon Dec 13, 2010 7:17 pm

Uwe

it a simple C program, Download
to build restart.c
(right click restart tutor02)

Code: Select all  Expand view
bcc32 restart.c


Code: Select all  Expand view
#include <windows.h>
// restart.c
// progname
// windows handle to close
int main(int argc, char** argv)
{
     HWND handle = ( HWND ) atol( argv[ 2 ] );
   PostMessage( handle, WM_QUIT, 0, 0 );
     WinExec( argv[ 1 ], 1 );
     return EXIT_SUCCESS;
}


sample how use (taking tutor02.prg)

Code: Select all  Expand view
// Our first Window in FiveWin !!!

#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd

   DEFINE WINDOW oWnd FROM 3, 6 TO 20, 70 ;
      TITLE "Welcome to " + FWDESCRIPTION COLOR "W/B"

   @ 2, 2 SAY "Hello world!"
   
   ACTIVATE WINDOW oWnd ;
      ON RIGHT CLICK winexec( "restart tutor02.exe " + Str( oWnd:hWnd ) ) ;
      VALID MsgYesNo( "Are you sure?", "Do you want to exit?" )

return nil

//----------------------------------------------------------------------------//
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Shutdown a prog. and restart it again whitin the program ?

Postby ukoenig » Mon Dec 13, 2010 11:45 pm

Daniel,

Thank You very much.
Your C-function works fantastic and does exactly what I need. ( added the file to my Maindirectory ).
I don't have to think about, closing or refreshing the Main-window.

I is included already im my new MDI-sample, with saving and reading the new Vars to / from a INI-file.
As soon it is finished, I will publish a Downloadlink.
It also shows many different Solutions, how to use Your new TSelex-class from inside a Ribbonbar.

The 2. Color-position of theGradient changes with the Thumb-position.
Now it shows the Gradient-result without a extra preview.

Image

Because it can be, the same selection is needed 2 or more times, I added a Zero-position.
After a selection, the Thumb moves to this position, and is possible, to select the same again.
I don't know, if it makes sense,to enable more than one Action from the same position with a double-click.
Changing the Thumb-position, will close the Dialog automatically and opens a new one.

Image

Code: Select all  Expand view

// -------  IMAGE ------------------

ADD GROUP oGroup9 RIBBON oRibbon TO OPTION 9 PROMPT "Image-Selection" WIDTH 750

oGroup9:SetFont( oFont1 )
oGroup9:Refresh()

@ 10, 10 SELEX oSelex13 VAR nOption13 OF oGroup9 PIXEL SIZE 730, 70 ;
GRADIENT OUTTRACK { { 0.5, 16770250, 16312263 }, ;
                       { 0.5, 16312263, 16770250 } };
GRADIENT INTRACK { { 0.5, 14853684, 16312263 }, ;
                      { 0.5, 16312263, 14853684 } };
ITEMS "MDI-&Frame", "MDI-&Child", "MDI-&Button adj.", "MDI-&Button transp.", "???"  ;
COLOR THUMB 8388608 ;
COLORTEXT 128, 32768 ;
THUMBSIZE 30, 25 ROUNDSIZE 5 ;  
FONT oFont1 ;
TITLE "Image" TOP ;
COLORTITLE 0 ;
ACTION ( IIF( lOPEN = .T., ( lOPEN := .F., oDlg1:End() ), NIL ), ;
         IIF( nOption13 = 1, oGroup9:cCaption := "Restart !!! to show the new Background-Selection", NIL ), ;
         IIF( nOption13 = 2, oGroup9:cCaption := "Select Image Child-Background", NIL ), ;
         IIF( nOption13 = 3, oGroup9:cCaption := "Select Image-Button-Background ( resized Image )", NIL ), ;
         IIF( nOption13 = 4, oGroup9:cCaption := "Select Image-Button-Background ( from Screenshot for transparent effect !!! )", NIL ), ;
         IIF( nOption13 = 5, oGroup9:cCaption := "Zero-Reset-Position", NIL ), ;
                 IIF( nOption13 < 5, MAIN_DLG4(oWndMain, oWndEdit, nOption13, oSelex13, cImage2), NIL ) )

oSelex13:Setoption( 5 )
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Shutdown a prog. and restart it again whitin the program ?

Postby cly166 » Wed Dec 15, 2010 6:42 am

Hi Uwe
For your reference, hope it is helpfull.
*--------------------------------------------------------------
#include "FiveWin.ch"
*---------------------------------------------
static oWndMain
*=============================================
function Main()

DEFINE WINDOW oWndMain FROM 1, 1 TO 30, 70 TITLE "Test relaunch" MENU BuildMenu()

ACTIVATE WINDOW oWndMain MAXIMIZED

return nil
*---------------------------------------------
*=============================================
func BuildMenu()
*---------------------------------------------
local oMenu

MENU oMenu
MENUITEM "Relaunch" ACTION Relaunch()
SEPARATOR
MENUITEM "Exit" ACTION oWndMain:End()
ENDMENU

return oMenu
*---------------------------------------------
*===============================================
func Relaunch()
*-----------------------------------------------
local cRelauFle, hFile

oWndMain:End()
SysRefresh()
*---------
cRelauFle := cFilePath(GetModuleFileName( GetInstance() ))+'\Relaunch.Bat'
hFile := FCreate( cRelauFle, 0 ) // 0 Normal/Default,Read/Write
if hFile >= 0
FWrite( hFile, GetModuleFileName( GetInstance() ) +CRLF )
FWrite( hFile, "exit" +CRLF )
FClose( hFile )
SysRefresh()
*--
WinExec( cRelauFle, 0 ) // 0 not show Cmd.exe Window, 1 yes
endif
*-----------------------------------------------
*--------------------------------------------------------------
Regrads
cly166
cly166
 
Posts: 11
Joined: Sat Sep 25, 2010 2:36 pm

Re: Shutdown a prog. and restart it again whitin the program ?

Postby ukoenig » Wed Dec 15, 2010 10:43 am

cly166,

thank You very much, I tested Your solution. It works as well using a BAT-file.
I noticed a difference about the loadingtime using the EXE-file ( C-function from Daniel ) and the BAT-file.
The restart, using the C-function, works much faster.
I added Your Solution to my Tool-collection. It is always profitable, to have different Options.

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Shutdown a prog. and restart it again within the program ?

Postby nageswaragunupudi » Wed Dec 29, 2010 1:45 pm

Mr. Daniel's source of restart.c is excellent.

If I understood the main problem correctly, what is needed is to change the background brush of MDI Frame during runtime. If this is the only reason why the program need to be restarted, I think it is easily possible to change the background brush of MDI Framewindow at anytime during runtime from anywhere in the program. We need to
Code: Select all  Expand view

WndMain():SetBrush( oNewBrush )
WndMain():oWndClient( oNewBrush )
 


Or is there some other problem which I did not understand?

Here is a sample code to change MDI frame's background brush during runtime.
Code: Select all  Expand view
#include "fivewin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBar

   DEFINE WINDOW oWnd MDI TITLE "MDI BackGround Brushes"

   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007
   DEFINE BUTTON OF oBar PROMPT "MDI-Frame Brush" ;
      ACTION SelectBackGround()

   SET MESSAGE OF oWnd TO "" 2007
   ACTIVATE WINDOW oWnd

return nil

//----------------------------------------------------------------------------//

static function SelectBackGround()

   local cFile
   local oBrush

   cFile    := cGetFile( "Image file (bmp,png,jpg)|*.bmp;*.png;*.jpg;*.jpeg|", "Select Image for Back Grund" )
   if ! Empty( cFile )
      DEFINE BRUSH oBrush FILE cFile
      WndMain():SetBrush( oBrush )
      WndMain():oWndClient:SetBrush( oBrush )
   endif

return nil

//----------------------------------------------------------------------------//
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Shutdown a prog. and restart it again within the program ?

Postby ukoenig » Wed Dec 29, 2010 4:18 pm

Mr. Rao,

There was a problem with < Gradient-brush > and I only got it working with a Restart, using Daniel's Function.
Colors, Brushes and Images are working fine at Runtime.

Code: Select all  Expand view

// -------- MDI - Frame -----------------------
// oBrush1 is still open, because used in different Painters -------------

FUNCTION NEW_BRUSH1(nSelect)
LOCAL hDC1

IF nSelect = 1
    oBrush1:End()
    DEFINE BRUSH oBrush1 COLOR nColor1a
    WndMain():SetBrush( oBrush1 )
    WndMain():oWndClient:SetBrush( oBrush1 )
ENDIF
IF nOption1 = 2
    aColors1    := { { nMove1, nColor1a, nColor1b }, { nMove1, nColor1b, nColor1a } }   
    hDC1 = CreateCompatibleDC( WndMain:GetDC() )
    hBmp = CreateCompatibleBitMap( WndMain:hDC, WndMain:nWidth(), WndMain:nHeight() )
    hBmpOld = SelectObject( hDC1, hBmp )
    hDC1 := WndMain:GETDC()
    GradientFill( hDC1, -350, 0, 100, 300, aColors1, lDirect1 )
    DeleteObject( WndMain:oBrush:hBrush )
    WndMain():oBrush:hBitmap = hBmp
    WndMain():oBrush:hBrush = CreatePatternBrush( hBmp )
    SelectObject( hDC1, hBmpOld )
    WndMain:ReleaseDC()
ENDIF
IF nSelect = 3
    oBrush1:End()
    DEFINE BRUSH oBrush1 FILENAME cBrush1
    WndMain():SetBrush( oBrush1 )
    WndMain():oWndClient:SetBrush( oBrush1 )
ENDIF
IF nSelect = 4
    oBrush1:End()
    DEFINE IMAGE oTmp FILENAME cImage1
    oBrush1 := TBrush():new( ,,,, ResizeBmp( oTmp:hBitmap, oWndMain:nWidth(), oWndMain:nHeight(), .T. ) )
    WndMain():SetBrush( oBrush1 )
    WndMain():oWndClient:SetBrush( oBrush1 )
    oTmp:End()
ENDIF   

RETURN NIL
 


Best Regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Shutdown a prog. and restart it again within the program ?

Postby nageswaragunupudi » Sun Jan 02, 2011 3:50 pm

Mr. Uwe

Gradients also can be set and reset during runtime. Please examine the following sample. This sample demonstrates:
1. Switching of MDI backgrouds between Images, Image tiled mode, Image fill mode and Gradients and resizing filled-image and gradient backgrounds while resizing the main window
2. Transparent MDI child, retaining the transparency even while changing and resizing MDI frame backgrounds.
Code: Select all  Expand view
#include "fivewin.ch"

static lFill := .t.

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBar, oBrush

   DEFINE BRUSH oBrush FILE "c:\fwh\bitmaps\olga1.jpg"

   DEFINE WINDOW oWnd MDI BRUSH oBrush

   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007

   DEFINE BUTTON OF oBar PROMPT "ChangeImage" ;
      ACTION SelectBackGround()

   DEFINE BUTTON OF oBar PROMPT "ImageFill" ;
      ACTION ( lFill := .t., oWnd:ReSize(), oBar:AEvalWhen() ) ;
      WHEN ( ValType( oWnd:oBrush:Cargo ) != 'A' .and. !lFill )

   DEFINE BUTTON OF oBar PROMPT "ImageTiled" ;
      ACTION ( lFill := .f., oWnd:Resize(), oBar:AEvalWhen() ) ;
      WHEN ( ValType( oWnd:oBrush:Cargo ) != 'A' .and. lFill )


   DEFINE BUTTON OF oBar PROMPT "Gradient" ;
      ACTION GradientBrush( oWnd )

   DEFINE BUTTON OF oBar PROMPT "Transp-Child" ;
      ACTION TranspChild()

   SET MESSAGE OF oWnd TO "" 2007

   ACTIVATE WINDOW oWnd ; //ON INIT GradientBrush( oWnd ) ;
      ON RESIZE ResizeBrush( oWnd )

return nil

//----------------------------------------------------------------------------//

static function TranspChild()

   local oWnd

   DEFINE WINDOW oWnd MDICHILD OF WndMain()

   ACTIVATE WINDOW oWnd ;
      ON PAINT ChildPaint( hDC, oWnd ) ;
      ON MOVE ( oWnd:Refresh() )

return nil

//----------------------------------------------------------------------------//

static function ChildPaint( hDC, oWnd )

   local aPoint

   aPoint   := ClientToScreen( WndMain():hWnd, { 0, 0 } )
   aPoint   := ScreenToClient( oWnd:hWnd, aPoint )

   SetBrushOrgEx( hDC, aPoint[ 2 ], aPoint[ 1 ] + WndMain():oBar:nHeight - 1 )
   FillRect( hDC, GetClientRect( oWnd:hWnd ), WndMain():oBrush:hBrush )

return nil

//----------------------------------------------------------------------------//

static function ResizeBrush( oWnd )

   local aRect    := GetClientRect( oWnd:oWndClient:hWnd )
   local hBmp

   if IsIconic( oWnd:hWnd )
      return nil
   endif

   if ValType( oWnd:oBrush:Cargo ) == 'A'
      // Present brush is gradiend brush
      GradientBrush( oWnd )
   else
      if lFill

         hBmp           := ResizeBitmap( oWnd:oBrush:hBitmap, aRect[ 4 ], aRect[ 3 ], 2 )
         DeleteObject( oWnd:oBrush:hBrush )
         oWnd:oBrush:hBrush   := CreatePatternBrush( hBmp )
         DeleteObject( hBmp )
         oWnd:oBrush:Cargo    := .t.

         WITH OBJECT oWnd:oWndClient
            :Refresh()
            AEval( :aWnd, { |o| o:Refresh() } )
         END

      elseif oWnd:oBrush:Cargo == .t.

         hBmp           := ResizeBitmap( oWnd:oBrush:hBitmap )
         DeleteObject( oWnd:oBrush:hBrush )
         oWnd:oBrush:hBrush   := CreatePatternBrush( hBmp )
         DeleteObject( hBmp )
         oWnd:oBrush:Cargo    := .f.

         WITH OBJECT oWnd:oWndClient
            :Refresh()
            AEval( :aWnd, { |o| o:Refresh() } )
         END

      endif
   endif

return nil

//----------------------------------------------------------------------------//

static function SelectBackGround()

   local cFile
   local oImage, oBrush

   cFile    := cGetFile( "Image file (bmp,png,jpg)|*.bmp;*.png;*.jpg;*.jpeg|", "Select Image for Back Grund" )
   if ! Empty( cFile )
      DEFINE IMAGE oImage FILE cFile
      //DEFINE BRUSH oBrush FILE cFile
      oBrush   := TBrush():New( ,,,, ResizeBitmap( oImage:hBitmap ) )
      oBrush:Cargo   := lFill
      oImage:End()
      WndMain():SetBrush( oBrush )
      WndMain():oWndClient:SetBrush( oBrush )
      WndMain():ReSize()

   endif

return nil

//----------------------------------------------------------------------------//

static function GradientBrush( oWndMain, aColors , lVert )

   local hDC, hBmp, hBmpOld , nWidth , nHeight, aRect
   local oBrush, oWnd

   default aColors := { { 0.5, CLR_HBLUE, CLR_WHITE }, { 0.5, CLR_WHITE, CLR_HBLUE } }
   default lVert := .t.

   oWnd  := oWndMain:oWndClient

   aRect   = GetClientRect( oWnd:hWnd )
   nHeight = If( lVert, aRect[ 3 ] - aRect[ 1 ], 1 )
   nWidth  = if( lVert, 1, aRect[ 4 ] - aRect[ 2 ] )

   hDC = CreateCompatibleDC( oWnd:GetDC() )
   hBmp = CreateCompatibleBitMap( oWnd:hDC, nWidth, nHeight )
   hBmpOld = SelectObject( hDC, hBmp )
   GradientFill( hDC, 0, 0, nHeight, nWidth, aColors,lVert )

   DeleteObject( oWnd:oBrush:hBrush )

   oBrush         := TBrush():New( ,,,, hBmp )
   oBrush:Cargo   := aColors

   SelectObject( hDC, hBmpOld )


   oWnd:ReleaseDC()
   oWndMain:SetBrush( oBrush )
   oWnd:SetBrush( oBrush )

   AEval( oWnd:aWnd, { |o| o:Refresh() } )

return nil

//------------------------------------------------------------------//
 

May be this would simplify your programs.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests