I'm doing a little proof of concept app using winapi and opengl. I have a main process which fires off a thread and within that thread it creates a window. Now the window isn't on the task bar it's a system tray app and the trayIcon object is a member of the window.
So thread class owns window, window owns tray, tray owns pop up menu. Now when i work this 'thread with window' into the final app, that will already have a working trayicon and menu that will be associated with the other main app and i will just be running a window in a separate thread.
However for the current app its all a bit hacky...okay A LOT hacky. So I am having to add features to this app through the menu which then calls windowproc and windowproc is associated with the window as per usual. All these features work quite nicely...however!
When I called exit in my menu this goes to the big switch in the sky and calls close(), this then kills the trayicon and sends a mesage to wm_close destructs the window and used to close the app....however now we have this thread in the middle that owns the window when the window is close the thread is still running. I'm waffling... but the long of short of it is I did this:
class Window{
void* pParent; // going to be the thread that owns the window. Can't declare the proper type for a very good reason VC++ wont
// explain and I can't find the right search criteria.
};
Window::Close()
{
if (m_trayIcon.IsVisible())
m_trayIcon.OnDestroy();
BluelineThread* pBlueline = static_cast<BluelineThread*>(pParent);
if (pBlueline)
pBlueline->m_bKeepThreadingAlive = false;
if (m_hWnd)
::SendMessage(m_hWnd, WM_CLOSE, 0, 0);
}
pParent = this; // this happen in the window init
So what I want to know is....being that I know this is all hacky, how bad is it that I have done this? AND is it functional enough to leave in a prototype.
Also in my old company we could easily be able to pass a pointer of a parent to one of its children it was part of our model, so why can't I instance an object window in thread and thread in window? I'm sure it's very simple, but I just can't put my finger on it. Do I need to forward declare the class or something?