May 01, 2024, 09:47:11 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Close a window, shutdown a program correctly?

Started by Shannara, December 22, 2006, 02:20:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Shannara

Heh, on to the next problem ..

As I compile my programs, I realized that even though I close out a window with the X in titlebar, it doesnt shut down the application. Therefore I have lots of the exes running in the background. And then, the linker would error out unable to write the exe .. :) So i narrowed it down. If one window is created and the X is pressed, it doesnt close out the program. If I call Window.Destroy() or Window.OnClose(), application will give a general exception error.

So my question is ... how do you programmically close out an application? And how do you close (unload) a window since .destroy() and .onclose() do not do that?
Love is staying up all night with a sick child, or a healthy adult.

John Syl.

Hi Sync.

The way I run a program is the main calls a routine to create the window then loop the main doing whatever it needs to do but looking at a variable that as long as it is set to 1 the main program loops.  When you close the window(press the x)  .onclose is entered at this point you set the loop variable that the main loop is looking at to 0. the main loop exits, then ends the program.  the reason you get errors is that the main program is still trying to access the window that has been closed, probably.

hope this helps
John
Intel 3.6 p4 ht, XP home,2 gb mem, 400 gb hd 20gb raid 0, Nvidia 6600le.
AMD k6-2 500, 40gb.

Started on PDP11 Assembler, BASIC, GWBASIC, 6502, Z80, 80x86, Java, Pascal, C, C++, 
IBasic (std & pro), Aurora, EBasic.  (Master of none, but it's been fun!)

Shannara

December 22, 2006, 02:42:53 PM #2 Last Edit: December 22, 2006, 02:45:43 PM by Sync
Ah, thank for the help. I too have a variable that the main loop is looking to see if it is a zero or not :) One change I ended up making was a class as global. Turns out global classes are not in just yet and that crashed the application. However, I still need to find a way to close out a program and a window programmically. Is there something in the docs on how to close out of a program without using a KillProcess API? I couldnt find any mentions yet :(

Ah, it's not in the documentation yet, but you need a return 0; at the end of your global sub main() routine to close out the application :) Hehe, that would be usefull in the docs .. very usefull :)
Love is staying up all night with a sick child, or a healthy adult.

Bruce Peaslee

Here is the skeleton I usually start from:



enum MenuConstants
{
FILE_EXIT,
HELP_ABOUT
}

class MainWindow:CWindow
{


// Overridden Methods
declare virtual OnClose(), int;
declare OnMenuPick(int nID), int;

}

MainWindow::OnClose()
{
Destroy();
Return 0;
}

MainWindow::OnMenuPick(int nID), int
{
select nID
{
case FILE_EXIT:
OnClose();
case HELP_ABOUT:
MessageBox(this,"Another great one.","About",0);
}
}

sub main()
{
MainWindow wMain;
CMenu m;

m.BeginMenu();
m.MenuTitle("&File");
m.MenuItem("E&xit",ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, AMF_ENABLED, FILE_EXIT);
m.MenuTitle("&Help");
m.MenuItem("&About...",ÂÃ,  ÂÃ,  ÂÃ, AMF_ENABLED, HELP_ABOUT);
m.EndMenu();

wMain.Create(0,0,700,450,
AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_SIZE|AWS_MINIMIZEBOX|AWS_AUTODRAW,
0,"Test",NULL);
wMain.SetMenu(m.Detach());
wMain.CenterWindow();

// message loop
do
{
wait();
}until wMain.isValid() == false;

return 0;
}

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Shannara

That is an awesome framework :) Any chance of convincing you to post that in the tips and tutorials forum?
Love is staying up all night with a sick child, or a healthy adult.

Bruce Peaslee

Awesome? Not really - just bits I picked up here and there.

I can copy it to the tips forum, if folks think it belongs there; but my advice is for everyone to read every post, even if they don't think it applies to them. It could later.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles