?
Solved

OXMaskedEdit Seems To Be Disabled when another thread is running

Posted on 2006-03-28
13
Medium Priority
?
293 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
0
Comment
Question by:rickatseasoft
  • 6
  • 4
  • 3
13 Comments
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 800 total points
ID: 16318858
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
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16319024
Do you get the same behaviour with a 'normal' edit control ?
0
 

Author Comment

by:rickatseasoft
ID: 16321819
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 1200 total points
ID: 16321883
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
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16321957
If you read the help on TranslateMessage it sounds like that could solve your problem.
0
 

Author Comment

by:rickatseasoft
ID: 16322059
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
 

Author Comment

by:rickatseasoft
ID: 16322123
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
 
LVL 22

Expert Comment

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

MAHESH
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16322453
For the TAB key I think you also require the IsDialogMessage function in the routine.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16322483
if(!IsDialogMessage(GetSafeHwnd(), msg)
{
  Translate, dispatch
}
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16322486
sorry -I'm in a rush here.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16322707
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
 

Author Comment

by:rickatseasoft
ID: 16323854
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question