?
Solved

LButtonDblClk in CEditView

Posted on 2003-03-25
8
Medium Priority
?
258 Views
Last Modified: 2013-11-20
In my Edit object, For example,it may contain some text as below:
if (iRet == -1)
{
::GlobalFree(lpBuff);
::GlobalFree(lpBuffUndo);
::GlobalFree(lpBuffRedo);
lpBuffUndo = 0;
lpBuffRedo = 0;
lpBuff = 0;
return;
}

when I double click left mouse button in ::GlobalFree, it will select "::GlobalFree" not "GlobalFree" just as in vc edit window.
How to make it works like in vc edit window.
thanks.

0
Comment
Question by:dead_fish
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 3

Expert Comment

by:aphillips
ID: 8208640
Intercept the double click event, work out where in the edit control was d-clicked (what word was d-clicked) and select it wth SetSel().
0
 
LVL 1

Expert Comment

by:jemax
ID: 8209773
Hi,

 aphillips is completely right, but instead of detecting where user has clicked, just let default hander work first, then GetSel(), adjust if needed, and SetSel(). It looks easier a bit.

HTH,
jemax
0
 

Author Comment

by:dead_fish
ID: 8236772
here is my code:
void CDsbView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
     CEdit& mEdit = GetEditCtrl();
     mEdit.GetSel(iStart,iEnd);
     iEnd = iStart + 1;

     CEditView::OnLButtonDblClk(nFlags, point);

     CString sTmp;
     char sChar[3];
     int i,j;

     GetSelectedText(sTmp);
     memset(sChar,0,sizeof(sChar));    
     mEdit.SetSel(iStart,iEnd);
     GetSelectedText(sTmp);
     strcpy(sChar,sTmp.GetBuffer(2));

     if ((sChar[0] >= 48)&&(sChar[0] <= 57) ||
        (sChar[0] >= 65)&&(sChar[0] <= 90) ||
          (sChar[0] >= 97)&&(sChar[0] <= 122))
     {
        i = iStart;
        while (1)
          {
               mEdit.SetSel(i-1,i);
               GetSelectedText(sTmp);
               strcpy(sChar,sTmp.GetBuffer(2));
               if (!((sChar[0] >= 48)&&(sChar[0] <= 57) ||
                      (sChar[0] >= 65)&&(sChar[0] <= 90) ||
                      (sChar[0] >= 97)&&(sChar[0] <= 122)))
               {
                    break;
               }
               i--;
          }
         
          j = iEnd;
        while (1)
          {
               mEdit.SetSel(j,j+1);
               GetSelectedText(sTmp);
               strcpy(sChar,sTmp.GetBuffer(2));
               if (!((sChar[0] >= 48)&&(sChar[0] <= 57) ||
                    (sChar[0] >= 65)&&(sChar[0] <= 90) ||
                    (sChar[0] >= 97)&&(sChar[0] <= 122)))
               {
                    break;
               }
               j++;
          }

          mEdit.SetSel(i,j);
          GetSelectedText(sTmp);
     }
}

when debug to the last line: GetSelectedText(sTmp);
sTmp = "GlobalFree"

but when out of the function,it still select "::GlobalFree"!!

why???
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:aphillips
ID: 8237687
jemax said:
> but instead of detecting where user has clicked, just let default hander work first, then GetSel()...

trouble is you can't tell whether they clicked on the "::" or on the "GlobalFree".  So you don't know which word to select.

dead_fish said:
> here is my code:

I suspect that something is setting it back before the mouse event returns, or perhaps in OnLButtonUp.

What does GetSelectedText do?
0
 
LVL 1

Accepted Solution

by:
jemax earned 1000 total points
ID: 8238156
aphillips said:
>>trouble is you can't tell whether they clicked on the "::" or on the "GlobalFree"

dead_fish said "...just as in vc edit window". In vc editor if you click on "::", only ":" is selected

aphillips said:
>>I suspect that something is setting it back before the mouse event returns, or perhaps in OnLButtonUp.

that's right, it seems like you cannot change selection inside OnLButtonDblClk

As it came out, CEdit has func CharFromPos(CPoint), so the best solution, in my opinion, is aphillips's first comment. Something like that:
void CMyEditView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
     LPCTSTR lpszBuffer;
     int iStart, iEnd, iBufLen;
     CEdit& theEdit = GetEditCtrl();

     iBufLen = GetBufferLength();

     iStart = LOWORD(theEdit.CharFromPos(point));
     iEnd = iStart;
     
     if (iBufLen == iStart)
          return;

     lpszBuffer = LockBuffer();

     if (_istalnum(lpszBuffer[iStart])) //to select only ":" as in vc:)
     {
          for (; (iStart > 0) && _istalnum(lpszBuffer[iStart-1]); iStart--);
          for (; (iEnd < iBufLen) && _istalnum(lpszBuffer[iEnd+1]); iEnd++);
     }

     UnlockBuffer();

     theEdit.SetSel(iStart, iEnd+1);
}


or if you want to rely on CEdit selection code, you can set some flag in OnLButtonDblClk, and move your selection adjusting code into OnLButtonUp

CMyEditView::CMyEditView()
{
     // TODO: add construction code here
     m_fAdjustSelection = FALSE;
}


void CMyEditView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
     CEditView::OnLButtonDblClk(nFlags, point);

     m_fAdjustSelection = TRUE;
}

void CMyEditView::OnLButtonUp(UINT nFlags, CPoint point)
{
     LPCTSTR lpszBuffer;
     int iStart, iEnd;
     CEdit& theEdit = GetEditCtrl();

     CEditView::OnLButtonUp(nFlags, point);

     if (!m_fAdjustSelection)
          return;

     theEdit.GetSel(iStart, iEnd);

     lpszBuffer = LockBuffer();

     for (; (iStart < iEnd) && !_istalnum(lpszBuffer[iStart]); iStart++);
     for (--iEnd; (iEnd > iStart) && !_istalnum(lpszBuffer[iEnd]); iEnd--);

     UnlockBuffer();

     theEdit.SetSel(iStart, iEnd+1);
}




HTH,
jemax
0
 
LVL 3

Expert Comment

by:aphillips
ID: 8241768
jemax said:
> dead_fish said "...just as in vc edit window". In vc editor if you click on "::", only ":" is selected

Exactly my point.  If the user clicks on a colon or if the user clicks on an 'e' or any other character of "::GlobalFree" then all of "::GlobalFree" is selected.  How do you then tell what should be done just by getting the current selection?
0
 

Author Comment

by:dead_fish
ID: 8242573
thank you and others so much!
0
 
LVL 1

Expert Comment

by:jemax
ID: 8244265
Thank you, dead_fish.


aphillips said:
>> user clicks on an 'e' or any other character of "::GlobalFree" then all of "::GlobalFree" is selected

in vc editor if user clicks on a colon only the colon is selected. In my vc(6) at least :-)

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

777 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