Two problems with Modal Dialog boxes

Sep 25, 2009 at 11:07pm
I've written a Dialog-based app to connect to a device via ethernet. In the event of a connection failure (or any other error the user should know about), I want to throw up a modal dialog box telling them what's up. I would happily use MessageBox(), except that in these circumstances it's behaving like a modeless Dialog box. o,O

I also tried making my own modal dialog box. Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void AdviseDialog::OnBnClickedOk()
{
	OnOK();
}
BOOL AdviseDialog::OnInitDialog()
{//header, message, and topLeft are class privates in the .h
	CDialog::OnInitDialog();
	SetWindowText(header);
	adviceCtrl.SetWindowText(message);
	if (!topLeft.x && !topLeft.y)
		CenterWindow();
	SetWindowPos(&CWnd::wndTop, topLeft.x, topLeft.y, 0, 0, SWP_NOSIZE);
	this->SetFocus();
	UpdateData(FALSE);
	return TRUE;
}

int AdviseDialog::lecture(LPCTSTR messageA, LPCTSTR headerA)
	{return lecture(messageA, headerA, 0, 0);}
int AdviseDialog::lecture(LPCTSTR headerA, LPCTSTR messageA, int x, int y)
{	
	header = headerA; message = messageA;topLeft.x = x; topLeft.y = y;
	return DoModal();
}


from my main app I call lecture on a connection failure. The window appears, but doesn't appear to have focus; I also can't interact with either it or my original dialog window x(. Ideas?


Edit: Well, I sorted out why MessageBox was not behaving modally, but I'd still like to know what I'm doing wrong with my own dialog
Last edited on Sep 26, 2009 at 1:09am
Topic archived. No new replies allowed.