I have checked if EndDialog() is getting the handle of the main window and it is not. I even tried forcing the handle of the main window in EndDialog() and it didn't do anything
For the complete source go to http://members.rogers.com/deacon12/windex.zip
I didn't include this code because I thought it might complicate things. Any variables that are not defined are defined in the cWINDOWS class.
Code:
class cDIALOG: public cWINDOW
{
private:
static cDIALOG *Me;
static cSTRING *sCaption;
static BOOL CALLBACK DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
public:
~cDIALOG()
{ Close(); }
int Create(HWND hParent, cSTRING sCaption,
int cx, int cy, int x=0, int y=0,
DWORD dwStyle=0, DWORD dwExStyle=0);
void Close(int nResult=0)
{ ChildWindow.ForEach(del_all); ChildWindow.Clear(); EndDialog(hwnd, nResult); }
//ChildWindow is a linked list structure. This structure has been tested and it work correctly
void OnCreate(void (*Function)())
{ WindowEvents[0].unEvent=WM_INITDIALOG; WindowEvents[0].Function=Function; }
};
Code:
int cDIALOG::Create(HWND hParent, cSTRING sCaption,
int cx, int cy, int x, int y,
DWORD dwStyle, DWORD dwExStyle)
{
HGLOBAL hGlobal;
LPDLGTEMPLATE Dlg;
cDIALOG *PrevDlg=Me;
cWINDOW *PrevObj=Objects;
if ( !(hGlobal=GlobalAlloc(GMEM_ZEROINIT, 1024)) )
return -1;
Dlg=LPDLGTEMPLATE(GlobalLock(hGlobal));
Dlg->cdit=0;
Dlg->cx=cx;
Dlg->cy=cy;
Dlg->dwExtendedStyle=dwExStyle;
Dlg->style=dwStyle;
Dlg->x=x;
Dlg->y=y;
GlobalUnlock(hGlobal);
Me=this; //Incase there are more than one dialog box created
Objects=this; //The objects on the window that can be create are subclassed and the sub-class function needs to be static
this->sCaption=&sCaption;
int nReturn=DialogBoxIndirect(AppInstance, Dlg, hParent, DlgProc);
Me=PrevDlg; //restore old window's handle
Objects=PrevObj; //restore old object's address
GlobalFree(hGlobal);
return nReturn;
}
Code:
BOOL CALLBACK cDIALOG::DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if ( message==WM_INITDIALOG )
Me->SetText(*sCaption);
cCHILDWINDOW **TempChild;
cLINKEDLIST<cCHILDWINDOW*> *ChildWindow=&Me->ChildWindow;
ChildWindow->StepReset();
while ( (TempChild=ChildWindow->GetNode()) )
{
if ( (*TempChild)->ProcessParent(hwnd, message, wParam, lParam) )
return 0;
ChildWindow->StepNext();
}
if ( Me->ProcessEvents(hwnd, message, wParam, lParam) )
return 1;
else if ( message==WM_CLOSE )
Me->Close();
return 0;
}
Any help would be greatly appreciated
-Joe