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?
What about just making the main window invisible?
Wilko
You could also split the project into a Dll (with the exported functionality) and an Exe (with the GUI.
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
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 :)
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 )
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
I've also tried it in FUNCTION MAINFORM_WM_CREATE but that doesn't work either?
thanks
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 :) )
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.
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
... removed .... sorry
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
that works.
Thanks!
Really, y'all are a 1st rate bunch.
I do appreciate it!
:)
Yep, Pete's solution was what I had in mind ;D