Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does MFC do its DialogProc?

Status
Not open for further replies.

timmay3141

Programmer
Dec 3, 2002
468
US
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?
 
>> I am writing a very large and complicated application
>> for which I [red]cannot use MFC because of the lack of
>> versitility[/red]
(I need total control over everything, I'll
>> just leave it at that).

That is an invalid statement. I'll just leave it at that.

-pete
 
OK, I'll try to explain. This is going to be using Direct3D a lot, and I'm going to be making this a full screen application eventually, and probably get rid of the dialogs in the first place. I'm using dialogs now because it will be faster and I just want to get everything running before I change everything around. My MFC book didn't talk about making an application full screen as this will be eventually, and the document/view architecture would be more cumbersome than useful in this particular application.
 
I dont think you can get more cumbersone than trying to write your own message handling routines.


/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top