Solved

Edit Box Size

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
This video discusses moving either the default database or any database to a new volume.

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now