Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Trapping Key ESCAPE before is processed by a CNiNumEdit Control that has the Focus

I'm using Viual C++ 6.0 and Measurement Studio UI control compoenents.
I inserted a CNiNumEdit control inside a Form View in an MDI application. When this control has the Focus and the Key ESCAPE is pressed the control dissapears. I can't trap this key to avoid the control dissapear. How can I modify or configure this control to not allow it to process the ESCAPE key?
0 Kudos
Message 1 of 13
(6,708 Views)
It's actually the dialog that's handling the ESCAPE key, not CNiNumEdit. You can work around this by overriding the PreTranslateMessage method in your dialog class. For example, add this under the public declarations section in your dialog header file:

virtual BOOL PreTranslateMessage(MSG* pMsg);

Then here's a example implementation that you can add to your dialog class that prevents the dialog from closing when pressing ESCAPE:

BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_ESCAPE))
return TRUE;

return CDialog::PreTranslateMessage(pMsg);
}

- Elton
0 Kudos
Message 2 of 13
(6,706 Views)
This is actually a bug. You can find a hotfix to this problem at the following location:

ftp://ftp.ni.com/support/mstudio/vc/fixes/6.0/NumEdit/

Please let me know if you have any questions regarding this fix.

Regards,
Azucena
NI
Message 3 of 13
(6,707 Views)
It solves this problem. There is another bug related with this control. The OnError Event generates a Exception due to some failure with the arguments of the function that catch the event. How can I solve this?
Thanks you!
0 Kudos
Message 4 of 13
(6,708 Views)
I haven't seen this behavior. Please post some code that reproduces the issue.

Azucena
0 Kudos
Message 5 of 13
(6,708 Views)
Execute the following ex in debug. If you enter something wrong inside control NumEdit1 or NumEdit2 the OnError event is generated but it is not processed well by the dialog MessageMap. An exception of type argument coercion failed is raised. I added the Event through the ClassWizard.
I found other discussion thread that talks about this event, but there isn't any solution. I need to catch this event to show the user a specific error message rather than the NI standard error message.
0 Kudos
Message 6 of 13
(6,708 Views)
I'm seeing different behavior from you but incorrect behavior nonetheless. In my case I don't get an exception but the code inside the OnError event function is never executed. Although as you say, the error is generated since I do get a Type Mismatch error. I'll let the developers know but I can't promise that this will get fix anytime soon. If it does, you will be the first to know.
0 Kudos
Message 7 of 13
(6,708 Views)
I have just found what is the problem. It appears in the MSDN as a bug from Microsoft. The third argument type must be changed long -> SCODE, then the event is processed. You can find more info on the MSDN knowledge base Article "ActiveX Control's Stock Error Event Uses SCODE Value" ID: Q182434.
0 Kudos
Message 8 of 13
(6,708 Views)
Thanks for the info! I'll give that a try.
0 Kudos
Message 9 of 13
(6,708 Views)

Hi,

I write the following code on VisualStudio2005 and Measurement Studio 8.0.1, where CWaveGenPage is derived from CPropertyPage and m_cwspinEdit is a variable of CNiNumEdit. I found a problem when I edit the text of  m_cwspinEdit on the GUI of my application, method1 fails to trap the message but at the same time method2 works well. How do I trap the flow by comparing the window handle?

Thanks!

 CWaveGenPage::PreTranslateMessage(MSG* pMsg)
{
 // TODO: Add your specialized code here and/or call the base class

if ( pMsg->message == WM_CHAR ){
   HWND hWndCtl = ::GetFocus();
  
   //method1
   if ( hWndCtl == m_cwspinEdit.m_hWnd ){
      //Should trap the message here but actually never.........
     m_cwspinEdit..Value = 1.23;
   }

   //method2
   char buf[24];
   sprintf(buf, "%f", 1.23);
   ::SetWindowText(hWndCtl, buf);

}

 return CPropertyPage::PreTranslateMessage(pMsg);
}

0 Kudos
Message 10 of 13
(6,418 Views)