OXMaskedEdit Seems To Be Disabled when another thread is running

I am using the MDI interface not for the purpose of actually interacting with documents, it is to allow multiple dialogs to be active on the screen at once.  When the use makes a menu selection, I call OnOpenDocument and from there tell the view class which dialog do open modelessly.  The view sizes itself to the dialog, and the user provides input which will sometimes cause a report to run.  When the user requests a report, I use AfxBeginThread(&FunctionName, LPVOID *) to launch a Thread.  This act of launching a thread somehow disables OXMaskedEdit so that no input may be made to a MaskedEdit field until the Thread Exits.

For instance, there might be two or more documents open, each of which is really just an empty document, but the view knows to Create a specific dialog based on the parameters when the document was opened.  When the user clicks OK on one of the dialogs, the OK and Cancel buttons are disabled, the WM_CLOSE message is disabled, the cursor becomes IDC_WAIT(for the specific view only), and a thread is launched using the non-interactive version of AfxBeginThread().

EVERYTHING else seems to work as I would expect (all other dialogs, reports, fields, etc. work a little more slowly, but otherwise correctly), but any field that is COXMaskedEdit simply acts as if there has been no keyboard input at all.  If I click in one of the MaskedEdit fields, then the cursor moves there, but input is ignored.  The keystrokes are not stored either.  When the thread returns, the field works correctly, but doesn't rememer the items typed while the thread was running.  This seems to occur whether the dialog that started the thread contained a COXMaskedEdit field or not.

I'm still completely in the dark, but I did do some further testing, and it would seem that the control is receiving the OnKeyDown message, but not the OnChar message.

Does anyone have any ideas?

Thanks in advance, Rick
rickatseasoftAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mahesh1402Commented:
Dont you need message pump while waiting for thread ????

Same like you did asked in this :
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21762444.html <====

MSG msg;
   while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1, &m_pThread->m_hThread, FALSE, IFINITE, QS_ALLINPUT) )
           {
               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }
           }


MAHESH
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
Do you get the same behaviour with a 'normal' edit control ?
0
rickatseasoftAuthor Commented:
Andy and MAHESH:

Thanks for taking the time to get back to me; I really appreciate your efforts.

I've got to guit doing this at midnight.  I truly thought that I had tried this with normal CEdits, and that they worked properly.  This morning, CEdit doesn't work either, so lat night I must have been mistaken.  So, to answer your question, CEdit doesn't work at all either; although, push buttons, check boxes, radio button, etc. work just fine---even in the light of day.

The original code was:

      m_HCursor=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
      m_bCursor=TRUE;   //Cause OnSetCursor() to set the cursor to m_HCursor
      m_ButtonOK.EnableWindow(FALSE);  //No Double Clicks
      m_ButtonCancel.EnableWindow(FALSE);  //Don't want to cancel after the thread starts
      ((CAma5DlgView*)m_pParent)->SetIsCloseable(FALSE);  //Make OnClose() in the View return
      pThread=AfxBeginThread(&process41,&ta);
        if(pThread){
              MSG msg;
              while(WaitForSingleObject(pThread->m_hThread,500)==WAIT_TIMEOUT){
                    while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
                          DispatchMessage(&msg);
                    }
              }
        }

MAHESH, based on your suggestion, I changed it to

      m_HCursor=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
      m_bCursor=TRUE;
      m_ButtonOK.EnableWindow(FALSE);
      m_ButtonCancel.EnableWindow(FALSE);
      ((CAma5DlgView*)m_pParent)->SetIsCloseable(FALSE);
//ta is a structure containing arguments, and process41 has no message pump
      pThread=AfxBeginThread(&process41,&ta);
      if(pThread){
            MSG msg;
            while(WAIT_OBJECT_0!=MsgWaitForMultipleObjects(1,&pThread->m_hThread,FALSE,INFINITE,QS_ALLINPUT)){
                  while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
                        DispatchMessage(&msg);
                  }
            }
      }
I also tried changing the INFINITE above to a value such as 200.  In each case, all of the controls that I have tried, EXCEPT CEdit and COXMaskedEdit work just fine.  CEdit and COXMaskedEdit will not accept any keyboard input.  In COXMaskedEdit, it sees the OnKeyDown event, but does not see the OnChar.

Just so I am clear, the input that I am attempting is in other dialogs brought up with OnNewDocument() which creates a view, which, in turn,  opens the non-modal dialog as a child of the view.

I just tried to perform input in the CDialog which called the Thread, and its CEdits would not accept input either.

Thanks again, Rick
      
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

AndyAinscowFreelance programmer / ConsultantCommented:
Give this a quick try
      while ( ::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE ) )
      {  
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
      }
in place of your code to strip the queue of waiting messages.
0
AndyAinscowFreelance programmer / ConsultantCommented:
If you read the help on TranslateMessage it sounds like that could solve your problem.
0
rickatseasoftAuthor Commented:
Andy:

Thanks, it worked like a champ.  I have read the TranslateMessage help on MSDN, and I still don't understand one thing.  Since the CDialog that started the CWinThread is no longer in focus, another CDialog is, I don't understand why it would receive the messages at all.

If you have a second to either explain it, or point me in the right direction, I would really appreciate it.

Thanks again, Rick
0
rickatseasoftAuthor Commented:
Andy:

When I take your suggestion, which as I said works like a champ, the TAB key no longer moves between fields.  Do I need to trap that before calling TranslateMessage()?

Thanks again.
0
mahesh1402Commented:
you need to trap that in PreTranslateMessage like here : http://www.codeguru.com/cpp/controls/editctrl/keyboard/article.php/c513/

MAHESH
0
AndyAinscowFreelance programmer / ConsultantCommented:
For the TAB key I think you also require the IsDialogMessage function in the routine.
0
AndyAinscowFreelance programmer / ConsultantCommented:
if(!IsDialogMessage(GetSafeHwnd(), msg)
{
  Translate, dispatch
}
0
AndyAinscowFreelance programmer / ConsultantCommented:
sorry -I'm in a rush here.
0
mahesh1402Commented:
you may also use WM_GETDLGCODE message with DLGC_WANTTAB for this :

UINT CTabInEditDlg::OnGetDlgCode()
{
        return CEdit::OnGetDlgCode() | DLGC_WANTTAB;
}


void CTabInEditDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
        if (nChar==VK_TAB)
                ReplaceSel("\t",TRUE);
        else
                CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}

MAHESH
0
rickatseasoftAuthor Commented:
Andy and Mahesh:

The TAB stuff that Andy recommended doesn't work.

Mahesh, I believe that you may misunderstand the problem. I'm not certain.  It seems that the suggestions that you offered were designed to allow a TAB to be inserted into a control.  My problem is that I want the TAB to behave normally, and advance the cursor to the next dialog.

This is getting very involved.  I'll award points, and start a new quesion.

Thanks again, Rick  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.