Page 1 of 1

Mixed-Mode: Continue console after gui-window is released

Posted: Tue Dec 23, 2008 11:05 am
by raumi75
Hello,

right now, I am trying to improve some very old clipper-code. The program runs as a console-Application and I plan to rewrite it into using HMG step by step. I am very excited, about all the new possibilities we have with hmg!

Now to my problem: From within my old console-application, I can launch a window, but when it is released, the program does not continue.

Here is a sample to demonstrate:

Code: Select all

#include <minigui.ch>

procedure main
   ? "Hello world"
   gui_function()
   ? "Welcome back!"
   wait(10)
return

function gui_function()
   Load Window window1 as main
   Main.Center
   main.activate
return
I would expect the program to continue running, after the Main-Window is closed and released. Instead it aborts and the Line

Code: Select all

? "Welcome back!"
never gets executed.

What am I doing wrong?

Thanks for helping an eager hmg newbee.

Jan

Re: Mixed-Mode: Continue console after gui-window is released

Posted: Tue Dec 23, 2008 12:00 pm
by mol
In my opinion, closing window, which is activated as main terminates program.
Try to define other main window and keep it hidden and then load your window as MODAL.
On the end of your program, release main window.

I think, it should work.

Best regards, Marek

Re: Mixed-Mode: Continue console after gui-window is released

Posted: Tue Dec 23, 2008 12:18 pm
by esgici
Hello Jan, Welcome aboard :)
raumi75 wrote:Hello,

... I plan to rewrite it into using HMG step by step.
IMHO this is the best way. Begin with huge scenarios will be quickly painful.
I am very excited, about all the new possibilities we have with hmg!
You aren't alone; personally, after years I am excited as first days !

This is HMG power :)
Now to my problem: From within my old console-application, I can launch a window, but when it is released, the program does not continue.

I would expect the program to continue running, after the Main-Window is closed and released. Instead it aborts ...

What am I doing wrong?
Your expectation is right true by non-Window programming viewpoint. But in Windows some concepts comes different.

Your program is in mixed mode, no console only. If you have a MAIN window/form and when you ACTIVATE it, control of program passes to this window/form and main loop begins. All other events becomes fact within this loop. So, when main window/form released, the main loop and the program ends; whatever you have after ACTIVATE command goes away. There isn't any way to execute them. This isn't "abort", but normal program termination.

Happy HMG'ing :)

Regards

--

esgici

Re: Mixed-Mode: Continue console after gui-window is released

Posted: Tue Dec 23, 2008 3:01 pm
by raumi75
mol wrote:Try to define other main window and keep it hidden and then load your window as MODAL.
On the end of your program, release main window.
Thank you Marek, I tried it and it works great. This will make the gradual transition a lot easier.

I rewrote my sample. It now does what I want.

Code: Select all

#include <minigui.ch>

procedure main
   Load Window dummy as main && is an invisble main window, that calls dummy_onInit()
   main.Activate
return

function dummy_onInit()
   * Console-Part
   ? "Hello world"
   gui_function() && Calls the visible window
   * After the user closes the window, the console-part will continue
   ? "Welcome back!"
   ? "Program will terminate in 5 seconds"
   inkey(5)
   main.release
return

function gui_function()
   Load Window window1 && is a MODAL window
   window1.Center
   window1.activate
return
This is going to be a great christmas-time ;-)

Jan