timmay3141
Programmer
I'm doing a bit of win32, and I am writing a very large and complicated application for which I cannot use MFC because of the lack of versitility (I need total control over everything, I'll just leave it at that). Anyway, I find myself recreating MFC to an extent. Specifically, I am creating a class similar to CDialog and deriving all of my dialogs from that base class. This is all fine, but I have a problem when it comes to having multiple modeless dialogs up at once. Basically, I don't want to have to change the global DialogProc (which is shared by all CDialog derived classes) to include every possible modeless dialog that could be active. I want it to look something like this:
BOOL WINAPI DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return g_pDialog->MsgProc(hwnd, msg, wParam, lParam);
}
MsgProc is a virtual member of DialogProc, and is unique for each dialog. I know there will be more than this, but I don't want to have to change the code any when I add a new modeless dialog to the program. This is what my dialog proc is looking like now:
BOOL WINAPI DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if(g_pDialog1->m_hwndDlg == hwnd)
return g_pDialog1->MsgProc(hwnd, msg, wParam, lParam);
if(g_pDialog2->m_hwndDlg == hwnd)
return g_pDialog2->MsgProc(hwnd, msg, wParam, lParam);
if(g_pDialog3->m_hwndDlg == hwnd)
return g_pDialog3->MsgProc(hwnd, msg, wParam, lParam);
// etc
}
It is apparent that MFC managed to accomplish this, but I am not sure how. The only way that I could think of doing this is create a global vector, and every time a modeless dialog is created add it to the vector, and when it is destroyed remove it from the vector. Then, when DialogProc is called, loop through the vector to find the correct dialog and call the correct MsgProc. Is this the best way to accomplish this, or is there a better way?
BOOL WINAPI DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return g_pDialog->MsgProc(hwnd, msg, wParam, lParam);
}
MsgProc is a virtual member of DialogProc, and is unique for each dialog. I know there will be more than this, but I don't want to have to change the code any when I add a new modeless dialog to the program. This is what my dialog proc is looking like now:
BOOL WINAPI DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if(g_pDialog1->m_hwndDlg == hwnd)
return g_pDialog1->MsgProc(hwnd, msg, wParam, lParam);
if(g_pDialog2->m_hwndDlg == hwnd)
return g_pDialog2->MsgProc(hwnd, msg, wParam, lParam);
if(g_pDialog3->m_hwndDlg == hwnd)
return g_pDialog3->MsgProc(hwnd, msg, wParam, lParam);
// etc
}
It is apparent that MFC managed to accomplish this, but I am not sure how. The only way that I could think of doing this is create a global vector, and every time a modeless dialog is created add it to the vector, and when it is destroyed remove it from the vector. Then, when DialogProc is called, loop through the vector to find the correct dialog and call the correct MsgProc. Is this the best way to accomplish this, or is there a better way?