borland c++ event handler crash

T

Turbo_King

I am trying to write a program in Borland c++ 5.5 which has multiple
windows.

I am having trouble registering an event to be called from one class
to another.

I have two classes in my application. One class manages all the
windows in the app (TWinMan) and the other represents a particular
window (TWindow). When TWinMan is created it registers the window
class and assigns the WndProc function to a static member of TWindow.

Whenever this static function receives a WM_CREATE event it uses
SetWindowsLong to put the this pointer into GWL_USERDATA. Then
whenever another event is received it calls the appropriate member
function for the this pointer.

I need to app to close when all windows in TWinMan are closed. I
therefore am trying to set up and event so that whenever a TWindow
gets a WM_CLOSE message it raises an event in TWinMan so it can
deallocate the class instance and check to see if it needs to close
the application.

Whenver I close the window though I get a windows crash.

Thanks for any help
Gareth Williams

Some code:

typedef void __fastcall (__closure *TMyEvent)();

class TWindow {
....
public: TMyEvent OnClose;
....
}

class TWinMan {
....
private:
void __fastcall _windowKilled();
TWindow* _win[255];
....
}

void TWinMan::AddWindow(char* title, int width, int height, int bits)
{
....
_win[_winCount] = new TWindow(...);
_win[_winCount]->OnClose=_windowKilled;
....
}

bool TWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam)
{
switch (uMsg)
{
...
case WM_CLOSE:
{
if(OnClose!=NULL)OnClose();
return TRUE;
}
}
return FALSE; // unhandled message (invoke default wndproc)
}
 
T

Thomas Matthews

Turbo_King said:
I am trying to write a program in Borland c++ 5.5 which has multiple
windows.

I am having trouble registering an event to be called from one class
to another.
Events (especially windowing events) and Windowing is not
a part of the _standard_ C++ language and thus is not
discussed here. You'll find better resources in a Borland
newsgroup or a Windows newsgroup. Read the Welcome.txt
and FAQs below for newsgroup ideas.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,661
Latest member
FloridaHan

Latest Threads

Top