Type over mode in CEdit control
spillman!bworthen@uunet.uu.net Monday, October 21, 1996 Environment: VC++ 4.2, Win NT 4.0 I have a number of CEdit controls that I'm working with. I want to be able to allow the user to "type-over" any characters that might be present in the control. In other words, when the insertion point is positioned to the left of a character in the control, and the user types a key, the new character will "type-over" the character that is to the right of the insertion point. I would like to turn on (or off) this "type-over" mode either when the user toggles the insertion key, or programmatically in the code (possibly both). I've been looking through the documentation and other sources of help for CEdit and its parent classes, and I can't find an easy way to do this. Can anyone tell me if MFC provides an easy way to do this? If MFC doesn't provide a solution, can anyone give me an example of how to go about solving this? I would be very appreciative!! Thanks in advance Brad bworthen@spillman.com
Jim Alsup -- epi!alsup@amd.com Tuesday, October 22, 1996 [Mini-digest: 2 responses] On 21 Oct 96 at 17:20, spillman!bworthen@uunet.uu.ne wrote about "Type over mode in CEdit control": I had the same issue to deal with and also failed to find anything useful in the various sources of help I checked. I still think this ought to be (and probably is) built in, but I found that you can work around the issue fairly easily by subclassing CEdit and overriding OnChar as follows: Note that I stored my over type variable in the main frame class because insert/overtype mode is generally a sticky global concept. You can also override PreTranslateMessage here to look for the insert key and toggle modes. I hope this helps. void CExtEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default int start, end; GetSel( start, end ); CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd(); if ( pFrame->m_overtype && start == end ) { SetSel( start, end + 1 ); ReplaceSel(""); // This is like Clear(), but also deselects the sel. } CEdit::OnChar(nChar, nRepCnt, nFlags); } -jim alsup ja@episupport.com > Environment: VC++ 4.2, Win NT 4.0 > > I have a number of CEdit controls that I'm working with. I want to be > able to allow the user to "type-over" any characters that might be present > in the control. In other words, when the insertion point is positioned to > the left of a character in the control, and the user types a key, the new > character will "type-over" the character that is to the right of the insertion > point. I would like to turn on (or off) this "type-over" mode either when the > user toggles the insertion key, or programmatically in the code (possibly > both). > I've been looking through the documentation and other sources of > help for CEdit and its parent classes, and I can't find an easy way to do > this. Can anyone tell me if MFC provides an easy way to do this? If MFC > doesn't provide a solution, can anyone give me an example of how to go > about solving this? I would be very appreciative!! > Thanks in advance > Brad > bworthen@spillman.com > > -----From: Igor NedelkoI would do that this way: 1. Derive a class from CEdit, let's say CMyEdit; 2. Add a handler message function on WM_CHAR: void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if(m_bOvertype) { WORD wPosition = LOWORD(GetSel()); SetSel(wPosition,wPosition++); } CEdit::OnChar(nChar,nRepCnt,nFlags); } 3. Associate your edit with the CMyEdit class through ClassWizard/Member Variables or subclass it manually ( using SubclassDlgItem call ). You just need to set m_bOvertype member variable. It should work. Regards, Igor
| Вернуться в корень Архива |