Solved

Edit Box Size

Posted on 1998-08-04
4
210 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 50 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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