Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Edit Box Size

Posted on 1998-08-04
4
Medium Priority
?
217 Views
Last Modified: 2013-12-03
I have a dialog box with a multi-line editbox control. The editbox is loaded with some data on WM_INITDIALOG. After the data is in the editbox I would like to resize the dialog and editbox so that the editbox is just big enough to view the longest line. ie: I dont want a horizontal scroll bar. Is there a function or message that can be used to get the witdth of the longest line in the editbox?
I am not using MFC.
0
Comment
Question by:marvinm
4 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1412999
The closest to that are the EM_LINELENGTH and EM_GETLINECOUNT messages.
You have to iterate trough all lines, and check each line's lenght using EM_LINELENGTH. This way you can get the longest line
0
 

Expert Comment

by:PhilC
ID: 1413000
You could create the window with a horizontal scroll bar, then call GetScrollInfo(HWND,SB_HORZ,SCROLLINFO*);
You could then use the SCROLLINFO structure member .nMax to determine the width to make your window. Then remove the scroll bar from the window.

0
 
LVL 1

Author Comment

by:marvinm
ID: 1413001
Using the scroll info almost works. I am off by a few pixels. Could you give more detail as to how I should calulate the width of my editbox window from the scroll info?
0
 
LVL 6

Accepted Solution

by:
WxW earned 100 total points
ID: 1413002
Use the SetWindowPos() function to change the size of any Window.
To calculate the longest line , just get the text from the window using GetWindowText() . The control breaks the line using \r\n ( or \n , I don't remember ! ) . So you only have to extract each line from the text and do a strlen() .
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

824 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