Modal MessgeBox Problem
-
I have a problem with my app when displaying a MessageBox to indicate an error. I display the message box in a losingFocus callback, if the value of a dialog field is out of range. Most times the message box behaves correctly. The problem occurs when the user clicks in a window outside the application, the message box gets displayed and keeps reappearing when the OK button is pressed. This will continue for 10-20 times before the dialog will stop appearing. I have tried all three of the modality values (MB_APPLMODAL, MB_SYSTEMMODAL, MB_TASKMODAL) with the same results. Any suggestions as to how I can make the messagebox behave properly when the user clicks outside my application? Thanks in advance, Bob
-
I have a problem with my app when displaying a MessageBox to indicate an error. I display the message box in a losingFocus callback, if the value of a dialog field is out of range. Most times the message box behaves correctly. The problem occurs when the user clicks in a window outside the application, the message box gets displayed and keeps reappearing when the OK button is pressed. This will continue for 10-20 times before the dialog will stop appearing. I have tried all three of the modality values (MB_APPLMODAL, MB_SYSTEMMODAL, MB_TASKMODAL) with the same results. Any suggestions as to how I can make the messagebox behave properly when the user clicks outside my application? Thanks in advance, Bob
Could you post that part of the code please? Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix
They say I'm lazy but it takes all my time
-
Could you post that part of the code please? Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix
They say I'm lazy but it takes all my time
I think I need to determine if the focus is going to a window outside my app. How do I do that? Here is the code.
void DataImportDlg2::OnKillfocusProtocolNameCb()
{
CString protoName;// Get the protocol item just typed in. m\_protocolNameCB.GetWindowText(protoName); // If an item was typed in // verify this protocol exists. if (protoName.GetLength() > 0) { int index = m\_protocolNameCB.FindStringExact(0, protoName); if (index == CB\_ERR) { MessageBox (\_T ("Protocol does not exist, to create it, use the Create Protocol button"), \_T ("Data Import"), MB\_ICONERROR | MB\_OK | MB\_APPLMODAL | MB\_TOPMOST); m\_protocolNameCB.SetFocus(); }
Thanks, Bob
-
Could you post that part of the code please? Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix
They say I'm lazy but it takes all my time
I am trying to determine if the control that focus is going to next is on my app's window. Here is how I am attempting to do this
void DataImportDlg2::OnKillfocusProtocolNameCb(CWnd* pNewWnd )
{
CString protoName;// CWnd *pMainWnd = (CWnd *) AfxGetApp()->m_pMainWnd;
CWnd *pMainWnd = (CWnd *) AfxGetMainWnd();BOOL child = pMainWnd->IsChild(pNewWnd);
When I click on a control on my apps window, the IsChild returns FALSE. I would expect it to return TRUE. What am I doing wrong? Thanks in advance, Bob
-
I am trying to determine if the control that focus is going to next is on my app's window. Here is how I am attempting to do this
void DataImportDlg2::OnKillfocusProtocolNameCb(CWnd* pNewWnd )
{
CString protoName;// CWnd *pMainWnd = (CWnd *) AfxGetApp()->m_pMainWnd;
CWnd *pMainWnd = (CWnd *) AfxGetMainWnd();BOOL child = pMainWnd->IsChild(pNewWnd);
When I click on a control on my apps window, the IsChild returns FALSE. I would expect it to return TRUE. What am I doing wrong? Thanks in advance, Bob
Well, this won't work because the control is the child of your View class; not the CMainFrame class. I have two suggestions: The first one is the easier way: Don't try to validate the data everytime you loose focus. Instead, validate it when the user clicks on OK button. If you want to do it whenever the window looses focus do it this way: Create a bool variable as a member of your view. Lets say m_bChildHasFocus Now, whenever the control gets the focus set the variable to true and whenever it looses set it false. Here is the code:
void DataImportDlg2::OnKillfocusProtocolNameCb() { if (!m_bChildHasFocus) return CView::OnKillFocus(); // or whatever! I am not sure. Just exit the function properly!! m_bChildHasFocus = false; CString protoName; // Get the protocol item just typed in. m_protocolNameCB.GetWindowText(protoName); // If an item was typed in // verify this protocol exists. if (protoName.GetLength() > 0) { int index = m_protocolNameCB.FindStringExact(0, protoName); if (index == CB_ERR) { MessageBox (_T ("Protocol does not exist, to create it, use the Create Protocol button"), _T ("Data Import"), MB_ICONERROR | MB_OK | MB_APPLMODAL | MB_TOPMOST); m_protocolNameCB.SetFocus(); m_bChildHasFocus = true; }
Also, don't forget to add theOnGetFocus
function. In OnGetFocus functions, just setm_bChildHasFocus = true
. Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrixThey say I'm lazy but it takes all my time