Startup

Started by Tyrone Lee, January 13, 2008, 02:01:35 PM

Previous topic - Next topic

Tyrone Lee

I have a small problem with the startup of my app. Its a standard windows .EXE that uses a WinMAIN() functions.

    LOCAL OK            AS LONG

    CALL SetEngineVariables
    ClassName = "eMotion Sprite Engine for Explorations"
    IF DOSFileExists(Program_Path$ + "engine.ini") THEN
        OK = Engine_Execute(LoadScript(Program_Path$ + "engine.ini"), %True)
    END IF

    IF CheckRequirements() = %False THEN EXIT FUNCTION
    CALL SetSystemVariables
    CALL InitializeEngine

    'Setup Engine Draw Window
    glbhInstance = hInstance
    glbhWnd = CreateEngineDialog(hInstance)

    'Main Loop Sequence
    CALL Engine_Loop()

    'Exit eMotions Engine & CleanUp
    CALL ShutDownEngine()
    CALL CleanUpEngine()

    'Destroy the timer
    CALL KILLTIMER(glbhWnd, 0)   
   
    FUNCTION = 0


The CreateEngine() function uses a the CreateWindow() API to make the OpenGL form and start the engine. FireFly is telling me I have a duplicate WinMAIN function. If I use a console EXE it makes a DOS window before my app starts. A standard .EXE, forces me to use a FireFly form. How can I control this so the app starts cleanly?

I don't see where WinMAIN() can be edited, or over-ride the settings to use my personal WinMAIN. Help please..

Tye

TechSupport

Hi Tyrone,

WinMain can be edited to some extent in FireFly (in FireFly 3 there is more flexibility, but that doesn't help you now). :)

You should be able to put your startup code in the FF_WinMain function. FireFly's WinMain calls the FF_WinMain function during startup.

However, I wonder if the fact that FireFly will create/show the main form after the FF_WinMain executes will still screw up your program. Not sure. Maybe if you minimize the main form or uncheck its WS_VISIBLE window property.

I have never dealt with a hybrid type of program like you are writing. Whenever I use FireFly to write an application, it is all FireFly. Not half FireFly and half OpenGL, etc....

Please let me know if you run into further trouble.


TechSupport

Oh, the FF_WinMain function can be found from the Project Explorer under the "Special Functions" branch of the treeview. (FireFly Workspace form).



Tyrone Lee

Not really a hybrid project... I'm just controlling the first form being displayed in code, for an OpenGL window. (I don't need the default one if I create my own.)

In anycase, good idea... I'll try setting the visible or minimize the default form. ;)

Thanx

Tye

Tyrone Lee

I still have a problem.

I can't edit the WinMAIN because your compile will rebuild it and change it back to the original settings. Here is a question for you..

When I compile my app in Firefly (as a CONSOLE app) it will create a dos style window and then my app will launch. How can I control this console to "hide" or minimize it?

If I save all the CODE GENERATED, and load the CODEGEN_DRIVER20_MAIN.BAS into the original PowerBASIC compiler it compiles perfectly but the .EXE will *NOT* create the console window. Why?

Basically, I like your IDE but it appears the startup is limitted/(being controlled). If I want to make an .EXE that is totally invisible, its very simple in PowerBASIC. But it appears that Firefly is forcing the visual component to your app.

Any help on this?

Tye

Tyrone Lee

#5
EDIT:

Ok.. I think I discovered the problem.

1. I set the Project to standard .EXE. It requires me to create a Form. (I did and saved it.)
2. From within the Project Settings it says Form1 will be my startup form, but when the code is executed it simply runs my FF_WinMain() and my app runs as I intended.
3. The Form1 never runs..

This startup setting should be like VB. It should give and option for FF_Main or Form1 (list all your forms). I assumed that because the FF_Main wasn't listed as an option that it would simply pop up Form1. (It never pops up Form1.)

So the bug seems to be there.. The startup setting should have the option between forms & code. And if a form is selected it should startup the form automatically. Hope this clarifies what is happening.

Tye

EDIT: Upon further inspection. If you don't put ANY code in the FF_WinMain. And allow it to pass through with a FALSE return Form1 will appear. It seems to work, but should be made a little more clear/ straight forward in the IDE.

So your startup is always FF_WinMAIN, and you can overide internal forms with a True return from this FF_WinMain function. (Nice, but not clear in the IDE.)

Sorry for the headache on this..
:)

TechSupport

Hi Tye,

I was testing scenarios in FireFly the same time that you must have been composing your post. You have hit on exactly the correct answers. I could not have explained it any better. Oh, and you are correct that it could certainly be documented much better. I can't remember off the top of my head why the requirement was there to have a Form exist for all GUI projects.... I do remember that VB allowed just the Sub Main to execute. I will have to make sure that this little mess is straightened out for the next FireFly.

So, essentially you are handling the main form creation and message loop with your own code located in FF_WinMain.  When your main loop ends you return TRUE from FF_WinMain and then the program terminates. The only indication, documentation wise, of this behaviour is in the comments to the FF_WinMain function itself:


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.

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

End Function