?
Solved

A bug in CEdit

Posted on 2001-07-17
6
Medium Priority
?
398 Views
Last Modified: 2013-11-20
My App crash whenever I press the "-" button. This button is located on the top right hand corner of a standard keyboard.

I created a CEdit control inside my dialog box with member variable of data type float. However, my app crashes whenever I press "-" button. I tried catching this key using OnKeyDown Event, but it crashes before that.

Anyone any idea?
0
Comment
Question by:KeithTeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 6289244
Hi KeithTeo,

I'm not sure, but I think this maybe a hardware problem: I had same behavior for a long time
in a lot of applications. After my keyboard stopped working I bought a new one and since then
this doesn't happen anymore.

ZOPPO
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6306937
I assume you are referring to the dash or "minus" key -- it is not the topmost-rightmost key on *my* keyboard.

If the keyboard thinks that the Alt key is pressed, it will try to drop-down the "system control menu" (top right corner of some windows).  See if the problem occurs if you first press and release the ALT key a few times before pressing dash.

-- Dan
0
 

Expert Comment

by:abegnoche
ID: 6313898
I does the same on my computer but *only* when I'm running VC++ 6.0 in debug mode, and it's not a *real* crash, more like an assert (asm int 3), just press F5 to resume, I find it convenient to monitor where your threads are at a specific time...

--
(..alex..)
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

Accepted Solution

by:
ocbb earned 200 total points
ID: 6315854
You can intercept the minus key press before it reaches the control by overriding PreTranslateMessage with code similar to the following:


BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
     CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDITCTRL);
     if(pMsg->message == WM_KEYDOWN &&
                    GetFocus() == pEdit &&
                    pMsg->wParam == VK_SUBTRACT)
     {
          CString text;
          pEdit->GetWindowText(text);
          text += char(45);   //this is the ascii code for '-'
          pEdit->SetWindowText(text);
          //TODO: set the caret position to the last chararcter in the control
          return TRUE;
     }

     return CDialog::PreTranslateMessage(pMsg);
}

I recommend using other valid solutions first, if any.
Errol
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6317982
hi ocbb,
Please post Comments rather than Answers.  Thanks!

-- Dan
0
 

Expert Comment

by:thazim
ID: 6339357
KeithTeo ,
is the problem with only this '~' Key????
what about other key if u press r u getting the Keyboardevent???
or u try the same program in different machine...

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

762 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