June 29, 2024, 01:24:56 AM

News:

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


Program Quit error

Started by LarryMc, February 21, 2006, 05:08:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

Have a program with following relevant code snipets:

Quoteclass tlmWindow : Cwindow
{
ÂÃ,  ÂÃ, // Overridden functions
ÂÃ,  ÂÃ, declare tlmWindow();
ÂÃ,  ÂÃ, declare OnClose(),ÂÃ,  int;
ÂÃ,  ÂÃ, declare OnCreate(), int;
ÂÃ,  ÂÃ, declare OnMenuPick(int nID),INT;
ÂÃ,  ÂÃ, // Variables
ÂÃ,  ÂÃ, def run as int;
ÂÃ,  ÂÃ, CStatusBar *m_pStatus;
ÂÃ,  ÂÃ, tlmwindow *winIMAGE, *winEDIT, *winHIDE;
ÂÃ,  ÂÃ, CTabCtrl tab1;
}

tlmWindow::OnCreate(), int
{

ÂÃ,  ÂÃ, run = 1;
ÂÃ,  ÂÃ, CenterWindow();
ÂÃ,  ÂÃ, tab1.Create(0,0,795,28,
ÂÃ,  ÂÃ,  ÂÃ,  AWS_BORDER|AWS_VISIBLE|AWS_TABSTOP|ATCS_HOTTRACK,
ÂÃ,  ÂÃ,  ÂÃ,  500,"",this);

ÂÃ,  ÂÃ, winIMAGE = new(tlmChildWin,1);
ÂÃ,  ÂÃ, winIMAGE->Create(20,40,600,480,AWS_BORDER| AWS_CHILD,0,"",this);
ÂÃ,  ÂÃ, winEDIT = new(tlmChildWin,1);
ÂÃ,  ÂÃ, winEDIT->Create(20,40,600,480,AWS_BORDER| AWS_CHILD,0,"",this);
ÂÃ,  ÂÃ, winHIDE = new(tlmChildWin,1);
ÂÃ,  ÂÃ, winHIDE->Create(20,40,600,480,AWS_BORDER| AWS_CHILD,0,"",this);

ÂÃ,  ÂÃ, Return True;
}

I can exit the program either by selecting Quit from the menu or by clicking the 'x' in the upper right corner of the program window.

With the code as above th menu quit path closes the program without incident.ÂÃ,  Closing using the "x" closes the program but I immediately get a "poor baby...tell MS all about it" error message.

if I remove the 'create.tab1' line then I can close program either way without incident.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

You need to post all of your code, specifically what you are doing in OnClose.
Ionic Wind Support Team

LarryMc

I'm just starting to try to convert an IBP program that works to aurora.
QuoteDeclare Import, GetSysColor(index as int),int;

class tlmWindow : Cwindow
{
ÂÃ,  ÂÃ, // Overridden functions
   declare tlmWindow();
ÂÃ,  ÂÃ, declare OnClose(),ÂÃ,  int;
ÂÃ,  ÂÃ, declare OnCreate(), int;
ÂÃ,  ÂÃ, declare OnMenuPick(int nID),INT;
ÂÃ,  ÂÃ, // Variables
ÂÃ,  ÂÃ, def run as int;
   CStatusBar *m_pStatus;
   tlmwindow *winIMAGE, *winEDIT, *winHIDE;
   CTabCtrl tab1;
}

class tlmChildWin : Cwindow
{
   declare OnClose(),int;
//   declare OnCreate(),int;
//   declare OnMenuPick(int nID),int;
}

tlmWindow::OnClose(), int
{
   run = 0;
ÂÃ,  ÂÃ, Destroy();
ÂÃ,  ÂÃ, if(winImage <> NULL)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  delete winImage;
ÂÃ,  ÂÃ, if(winEdit <> NULL)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  delete winEdit;
ÂÃ,  ÂÃ, if(winHide <> NULL)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  delete winHide;
   if(m_pStatus <> NULL)
      delete m_pStatus;

ÂÃ,  ÂÃ, Return 0;

}


tlmWindow::OnCreate(), int
{

ÂÃ,  ÂÃ, run = 1;
ÂÃ,  ÂÃ, CenterWindow();
   tab1.Create(0,0,795,28,
      AWS_BORDER|AWS_VISIBLE|AWS_TABSTOP|ATCS_HOTTRACK,
      500,"",this);
   tab1.InsertTab(0,"ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Image EditorÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ");
   tab1.InsertTab(1,"ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, Map EditorÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, ");
   tab1.InsertTab(2,"ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Text EditorÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ");
   tab1.InsertTab(3,"ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, ConfigÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ");
   tab1.InsertTab(4,"ÂÃ,  ÂÃ,  ÂÃ, TMG Name UtilityÂÃ,  ÂÃ,  ÂÃ, ");

   winIMAGE = new(tlmChildWin,1);
ÂÃ,  ÂÃ, winIMAGE->Create(20,40,600,480,AWS_BORDER| AWS_CHILD,0,"",this);
ÂÃ,  ÂÃ, winIMAGE->SetWindowColor(GetSysColor(14));

   winEDIT = new(tlmChildWin,1);
ÂÃ,  ÂÃ, winEDIT->Create(20,40,600,480,AWS_BORDER| AWS_CHILD,0,"",this);
ÂÃ,  ÂÃ, winEDIT->SetWindowColor(GetSysColor(13));

   winHIDE = new(tlmChildWin,1);
ÂÃ,  ÂÃ, winHIDE->Create(20,40,600,480,AWS_BORDER| AWS_CHILD,0,"",this);
ÂÃ,  ÂÃ, winHIDE->SetWindowColor(GetSysColor(12));

ÂÃ,  ÂÃ, Return True;
}

tlmChildWin::OnClose(),int
{
   Destroy();
   return 0;
}
tlmWindow::tlmWindow()
{
   m_pStatus = new(CStatusBar,1);

}

global sub main()
{
   tlmWindow winMain;

ÂÃ,  ÂÃ, winMain.Create(0,0,800,600,
ÂÃ,  ÂÃ,  ÂÃ,  AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_AUTODRAW,
ÂÃ,  ÂÃ,  ÂÃ,  0,"Second Site Image Editor",NULL);
ÂÃ,  ÂÃ, winMain.SetWindowColor(GetSysColor(15));
ÂÃ,  ÂÃ, menu m;
ÂÃ,  ÂÃ, //create the file menuÂÃ,  ÂÃ, 
ÂÃ,  ÂÃ, m.BeginMenu();
ÂÃ,  ÂÃ,  ÂÃ,  m.MenuTitle( "&File");
ÂÃ,  ÂÃ,  ÂÃ,  m.MenuItem( "&Load Image ",0,1);
ÂÃ,  ÂÃ,  ÂÃ,  m.Separator();
ÂÃ,  ÂÃ,  ÂÃ,  m.MenuItem( "&Del ImageÂÃ,  ",0,2);
ÂÃ,  ÂÃ,  ÂÃ,  m.Separator();
ÂÃ,  ÂÃ,  ÂÃ,  m.MenuItem( "&Quit ",0,4);
      m.MenuTitle("&Help");
ÂÃ,  ÂÃ,  ÂÃ,  m.MenuItem( "About Image Manager...",0,450);
ÂÃ,  ÂÃ,  ÂÃ,  m.MenuItem( "Help",0,3);
ÂÃ,  ÂÃ, m.EndMenu();
ÂÃ,  ÂÃ, winMain.SetMenu(m.Detach());

   rect rc = winMain.GetClientRect();
   int panes[4];
   int width = rc.right - rc.left;
   panes =ÂÃ,  width - 120,width - 80,width - 40,-1;
   winMain.m_pStatus->CreateBar(AWS_VISIBLE,2,winMain);
   winMain.m_pStatus->SetPanes(4,panes);
   winMain.m_pStatus->SetPaneText(0,"Pane 1");
   winMain.m_pStatus->SetPaneText(1,"Pane 2");
   winMain.m_pStatus->SetPaneText(2,"Pane 3");
   winMain.m_pStatus->SetPaneText(3,"Pane 4");
   winMain.m_pStatus->Resize();


ÂÃ,  ÂÃ, do
ÂÃ,  ÂÃ, {
ÂÃ,  ÂÃ,  ÂÃ,  wait();
ÂÃ,  ÂÃ, }
ÂÃ,  ÂÃ, until winMain.run = 0;
ÂÃ,  ÂÃ, return;
}

tlmWindow::OnMenuPick(int nID),int
{
ÂÃ,  ÂÃ, switch nID
ÂÃ,  ÂÃ, {
ÂÃ,  ÂÃ,  ÂÃ,  case 1:
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winIMAGE->ShowWindow(SWRESTORE);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winEDIT->ShowWindow(SWHIDE);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winHIDE->ShowWindow(SWHIDE);
ÂÃ,  ÂÃ,  ÂÃ,  case 2:
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winIMAGE->ShowWindow(SWHIDE);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winEDIT->ShowWindow(SWRESTORE);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winHIDE->ShowWindow(SWHIDE);
ÂÃ,  ÂÃ,  ÂÃ,  case 3:
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winIMAGE->ShowWindow(SWHIDE);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winEDIT->ShowWindow(SWHIDE);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  winHIDE->ShowWindow(SWRESTORE);

ÂÃ,  ÂÃ,  ÂÃ,  //quit the program
ÂÃ,  ÂÃ,  ÂÃ,  case 4:
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, *(tlmWindow)this.run = 0;

ÂÃ,  ÂÃ,  ÂÃ,  //close the current child
ÂÃ,  ÂÃ,  ÂÃ,  case 200:

ÂÃ,  ÂÃ,  ÂÃ,  //add a new child window;
ÂÃ,  ÂÃ,  ÂÃ,  case 100:

ÂÃ,  ÂÃ, }
ÂÃ,  ÂÃ, //we return false to let the client handle other menu items from children.
ÂÃ,  ÂÃ, return false;
}
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

"run = 0"  should be the last thing you do in OnClose.   Deleting a child window causes a lot of messages to be sent to the wait handler.   If you set "run=0" before deleteing the child windows then your exiting your main sub before all messages are processed.

That is why I normally check the m_hwnd of the main window in all of my examples, unless there is only one window in the program of course.

   do
   {
      wait();
   }
   until winMain.m_hWnd = 0;

Not that for that to work you should call Destroy() of your main window last.
Ionic Wind Support Team

LarryMc

February 21, 2006, 01:19:34 PM #4 Last Edit: February 21, 2006, 01:25:13 PM by tlmccaughn
Paul
While waiting for your reply I did the following:

changed CTabCtrl tab1;ÂÃ,  ÂÃ, -to-ÂÃ,  CTabCtrl *tab1;

change to the following in the oncreate:

   tab1 = new(CTabCtrl,1);
   tab1->Create(0,0,795,28,
      AWS_BORDER|AWS_VISIBLE|AWS_TABSTOP|ATCS_HOTTRACK,
      500,"",this);
   tab1->InsertTab(0,"ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Image EditorÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ");
   tab1->InsertTab(1,"ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, Map EditorÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, ");
   tab1->InsertTab(2,"ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Text EditorÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ");
   tab1->InsertTab(3,"ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, ConfigÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ");
   tab1->InsertTab(4,"ÂÃ,  ÂÃ,  ÂÃ, TMG Name UtilityÂÃ,  ÂÃ,  ÂÃ, ");

That basically treats it the same way the status bar was treated in the code.

Worked fine and eliminated my problem!ÂÃ,  Without the change you suggested (because I remembered I got the error when it was the last thing in the onclose-I changed it during my debug effort).

What gives?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

My version of the compiler is different from the current alpha so I can't test your code, I was just stating facts and giving you something to try out.

Bottom line is Aurora is still an Alpha and many things may give problems that won't in the final release.   There are also some thing you should be doing in your code for fault tolerance.

Member variables should always be initialized in the class constructor, especially pointer variables.  You don't have a constructor in any of your window classes.

Your OnClose would have been more properly coded like so:

tlmWindow::OnClose(), int
{
    tab1.Destroy();
    Destroy();
   if(winImage <> NULL)
        delete winImage;
   if(winEdit <> NULL)
        delete winEdit;
   if(winHide <> NULL)
        delete winHide;
   if(m_pStatus <> NULL)
      delete m_pStatus;
   run = 0;
   Return true;

}

Since you have changed it to a pointer, and it works then go with it.  You could have built a debug executable and run it through the debugger to indicate where it was giving a GPF.

Just remember to initialize those pointers to NULL ;)

Ionic Wind Support Team

LarryMc

Thanks Paul;

Changing it to a pointer makes more sense to me because it does match the statusbar example code I had to go by.

I'm struggling since I have always been a Basic programmer.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library