PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Shawn Anderson on December 22, 2010, 07:29:40 PM

Title: running a program with no gui
Post by: Shawn Anderson on December 22, 2010, 07:29:40 PM
I want to pass a switch to my program like this:
program.exe /autorun

If no switch is passed, I want the program to run normally.
When the switch is passed, I want to call a function within my program that runs and exits without ever showing a dialog.

How?
Title: Re: running a program with no gui
Post by: Wilko Verweij on December 23, 2010, 05:13:26 AM
What about just making the main window invisible?

Wilko
Title: Re: running a program with no gui
Post by: Rolf Brandt on December 23, 2010, 08:43:19 AM
You could also split the project into a Dll (with the exported functionality) and an Exe (with the GUI.
Title: Re: running a program with no gui
Post by: Shawn Anderson on December 23, 2010, 10:06:53 AM
Interesting....
I was hoping there was an option to not display the GUI at all.
In the PB IDE, this can be done by simply not running the function that creates and displays the main dialog.

If I can't do it that way, how do I make it invisible?

thanks
Title: Re: running a program with no gui
Post by: Eddy Van Esch on December 23, 2010, 10:14:51 AM
Quote from: Shawn Anderson on December 23, 2010, 10:06:53 AM
If I can't do it that way, how do I make it invisible?
Use FF function FF_Control_ShowState with parameters %SW_HIDE or %SW_SHOW ?

[added] The downside of %SW_HIDE is that the form is briefly displayed ....
[added 2] ... but you can get rid of that by displaying the window off screen (with a negative Top coordinate for example) and moving the window onscreen if you want to have it displayed.
But maybe there is a more elegant solution :)

Title: Re: running a program with no gui
Post by: Eddy Van Esch on December 23, 2010, 11:22:21 AM
I knew there had to be a more elegant way!
In the Visual Designer, Form Properties / Window Styles, uncheck the WS_VISIBLE style.
The window will be hidden when created.
Use this to show the window if required:
FF_Control_ShowState( hWndForm, %SW_SHOW )

Title: Re: running a program with no gui
Post by: Shawn Anderson on December 23, 2010, 12:28:41 PM
What I've done is turned off visibility for the main form then looked for the command line switch in ff_winmain.
Then if the switch is not found, show the form, but it doesn't work.
Should I put it somewhere else?


FUNCTION FF_WINMAIN( ByVal hInstance     As Dword, _
                     ByVal hPrevInstance As Dword, _
                     ByVal lpCmdLine     As Asciiz Ptr, _
                     ByVal iCmdShow      As Long ) As Long


   ' If this function returns TRUE (non-zero) then the actual WinMain will exit   
   ' thus ending the program. You can do program initialization in this function.


    If LCase$(Command$)="/autorun" Then
        bType=%autoBack
        doBackup(%doAll)
    Else
        bType=%gui
        FF_Control_ShowState( HWND_MAINFORM, %SW_SHOW )
    End If     

       
   FUNCTION = %FALSE    'return %TRUE if you want the program to end.

End FUNCTION

Title: Re: running a program with no gui
Post by: Shawn Anderson on December 23, 2010, 12:29:54 PM
I've also tried it in FUNCTION MAINFORM_WM_CREATE but that doesn't work either?
thanks
Title: Re: running a program with no gui
Post by: Eddy Van Esch on December 23, 2010, 12:40:42 PM
That's because in WinMain your form is not created yet.
Use PostMessage in WM_CREATE.
I'll post code later this evening (if someone else doesn't beat me to it  :) )

Title: Re: running a program with no gui
Post by: Shawn Anderson on December 23, 2010, 12:50:52 PM
one other thing:

When the program is running in "hidden" mode, I want it to run a function and then quit.
I'm trying to do it like this:


    If bType=%autoBack Then
        doBackup(%doAll)   
        MAINFORM_WM_DESTROY(hWndForm)
    Else
        FF_Control_ShowState( HWND_MAINFORM, %SW_SHOW )   
    End If   


It runs the doBackup function, but doesn't quit.

Thanks for your help.
Title: Re: running a program with no gui
Post by: Pete Totushek on December 23, 2010, 01:00:46 PM
Hi Shawn,

This is the way that I do what you're trying to do...


%WM_FORM_CREATE_COMPLETE = %WM_USER + 1000

Function MainFORM_WM_CREATE ( _
                         hWndForm As Dword, _      ' handle of Form
                         ByVal UserData As Long _  ' optional user defined Long value
                         ) As Long

   
   'Program Startup Code here
   
   PostMessage hWndForm, %WM_FORM_CREATE_COMPLETE, 0, 0     'Signal that we are done with our startup routine
   
End Function
   
Function MainLST_CUSTOM ( _
                      hWndForm      As Dword, _  ' handle of Form
                      wMsg          As Long,  _  ' type of message
                      wParam        As Dword, _  ' first message parameter
                      lParam        As Long   _  ' second message parameter
                      ) As Long
   
   
   Select Case wMSG
   
   Case %WM_FORM_CREATE_COMPLETE     'Is startup routine finished?
      If LCase$(Command$)="/autorun" Then
         bType=%autoBack
         doBackup(%doAll)
         'Your /autorun Code here
         FF_CloseForm HWND_MAINFORM
      Else
         bType=%gui
         FF_Control_ShowState( HWND_MAINFORM, %SW_SHOW )
      End If     
   End Select
   
End Function
Title: Re: running a program with no gui
Post by: Shawn Anderson on December 23, 2010, 01:34:20 PM
... removed .... sorry
Title: Re: running a program with no gui
Post by: Paul Squires on December 23, 2010, 01:43:01 PM
Nice to see so many other FF users providing helpful hints!  :)

I think that I would follow Pete's approach. Turn off the WS_VISIBLE style for the main startup form and then PostMessage within the WM_CREATE handler.

Shawn, if you are getting an undefined equate error then make sure that you entered the first line of code that Pete has in his post:

%WM_FORM_CREATE_COMPLETE = %WM_USER + 1000

Title: Re: running a program with no gui
Post by: Shawn Anderson on December 23, 2010, 01:44:29 PM
that works.

Thanks!
Title: Re: running a program with no gui
Post by: Shawn Anderson on December 23, 2010, 03:05:54 PM
Really, y'all are a 1st rate bunch.
I do appreciate it!
:)
Title: Re: running a program with no gui
Post by: Eddy Van Esch on December 23, 2010, 05:03:59 PM
Yep, Pete's solution was what I had in mind   ;D