running a program with no gui

Started by Shawn Anderson, December 22, 2010, 07:29:40 PM

Previous topic - Next topic

Shawn Anderson

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?

Wilko Verweij

What about just making the main window invisible?

Wilko

Rolf Brandt

You could also split the project into a Dll (with the exported functionality) and an Exe (with the GUI.
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Shawn Anderson

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

Eddy Van Esch

#4
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 :)

Eddy

Eddy Van Esch

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 )

Eddy

Shawn Anderson

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


Shawn Anderson

I've also tried it in FUNCTION MAINFORM_WM_CREATE but that doesn't work either?
thanks

Eddy Van Esch

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  :) )

Eddy

Shawn Anderson

#9
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.

Pete Totushek

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
-Pete
www.totusoft.com -- Home of LAN Speed Test

Shawn Anderson

#11
... removed .... sorry

Paul Squires

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

Paul Squires
PlanetSquires Software

Shawn Anderson


Shawn Anderson

Really, y'all are a 1st rate bunch.
I do appreciate it!
:)