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)
}
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)
}