We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

OXMaskedEdit Seems To Be Disabled when another thread is running

rickatseasoft
on
Medium Priority
314 Views
Last Modified: 2013-11-20
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
Comment
Watch Question

IT Professional
Top Expert 2005
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
Do you get the same behaviour with a 'normal' edit control ?

Author

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
      
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT
Commented:
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.
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
If you read the help on TranslateMessage it sounds like that could solve your problem.

Author

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

Author

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.
mahesh1402IT Professional
Top Expert 2005

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

MAHESH
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
For the TAB key I think you also require the IsDialogMessage function in the routine.
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
if(!IsDialogMessage(GetSafeHwnd(), msg)
{
  Translate, dispatch
}
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
sorry -I'm in a rush here.
mahesh1402IT Professional
Top Expert 2005

Commented:
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

Author

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  
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.