Microsoft Knowledge Base Email Alertz

KBAlertz.com: (92626) - In specific situations, it may be desirable to make multiline edit controls behave similar to list boxes, such that entries can be selected and manipulated on a per-line basis. This article describes how to implement the line-based interface.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 92626 - Last Review: July 11, 2005 - Revision: 1.3

How To Implement a Line-Based Interface for Edit Controls

This article was previously published under Q92626

SUMMARY

In specific situations, it may be desirable to make multiline edit controls behave similar to list boxes, such that entries can be selected and manipulated on a per-line basis. This article describes how to implement the line-based interface.

MORE INFORMATION

A multiline edit control must be subclassed to achieve the desired behavior. The subclass function is outlined below.

Most of the work necessary to implement a line-based interface is done by the predefined window function of the edit control class. With the return value from the EM_LINEINDEX message, the offset of the line under the caret can be determined; with the length of that line retrieved via the EM_LINELENGTH message, the EM_SETSEL message can be used to highlight the current line.

There are two problems with this approach:
  • The first problem is that the EM_LINEINDEX message, when sent to the control with wParam=-1, returns the line index of the caret, which is not necessarily the same as the current mouse position. Thus, upon receiving the WM_LBUTTONDOWN message, the subclass function should first call the old window function, which will set the caret to the character under the current mouse position, then compute the beginning and ending offsets of the corresponding line, and eventually set the selection to that line.
  • The other problem is that the WM_MOUSEMOVE message should be ignored by the subclassing function because otherwise the built-in selection mechanism will change the selection when the mouse is being dragged with the left mouse button pressed, thus defeating the purpose.
Following is the subclassing function that follows from this discussion:
   LRESULT CALLBACK EditSubClassProc(HWND hWnd,
                  UINT wMsg,
                  WPARAM wParam,
                  LPARAM lParam)
   { int iLineBeg, iLineEnd;
     long lSelection;
     switch (wMsg)
     { case WM_MOUSEMOVE:
        break;                       /* Swallow mouse move messages.  */ 
       case WM_LBUTTONDOWN:          /* First pass on, then process.  */ 
        CallWindowProc((WNDPROC)lpfnOldEditFn,hWnd,wMsg,wParam,lParam);
        iLineBeg = SendMessage(hWnd,EM_LINEINDEX,-1,0);
        iLineEnd=iLineBeg+SendMessage(hWnd,EM_LINELENGTH,iLineBeg,0);
   #ifndef WIN32
        SendMessage(hWnd,EM_SETSEL,0,MAKELPARAM(iLineBeg,iLineEnd));
   #else
        SendMessage(hWnd,EM_SETSEL,iLineBeg,iLineEnd)  /* Win 32 rearranges
                         parameters.  */ 
   #endif
        break;
       case WM_LBUTTONDBLCLK:
        lSelection = SendMessage(hWnd,EM_GETSEL,0,0);
        /* Now we have the indices to the beginning and end of the line in
           the LOWORD and HIWORD of lSelection, respectively.
           Do something with it... */ 
        break;
       default:

   return(CallWindowProc((WNDROC)lpfnOldEditFn,hWnd,wMsg,wParam,lParam));
   };
   return(0);
   }
				


If STRICT is defined, the lpfnOldEditFn has the datatype WNDPROC. If STRICT is not defined and also for 16-bit programming lpfnOldEditFn has the data type FARPROC.

The WNDPROC type is declared as follows:
LRESULT (CALLBACK *WNDPROC) (HWND, UINT, WPARAM, LPARAM);

The FARPROC type is declard as follows:
int (FAR WINAPI * FARPROC)();

For more information please take a look at the MSDN documentation for CallWindowProc.

APPLIES TO
  • Microsoft Platform Software Development Kit-January 2000 Edition
  • Microsoft Windows Software Development Kit 3.1
Keywords: 
kbhowto kbeditctrl kbctrl KB92626
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please