Teen Programmers Unite  
 

 

Return to forum top

Win32 API Edit Windows

Posted by SantSys [send private reply] at January 24, 2002, 04:55:10 AM

I am working on making a simple messaging application. What i am curious about is how to make a edit control like ones that are used in AOL instant messanger not the HTML part but the ability to scroll and hold very large amounts of data. Any information on this would be very help full.

Thank you.

--Josh
j_santomieri@hotmail.com

Posted by taubz [send private reply] at January 24, 2002, 01:11:34 PM

It is probably using Microsoft's RichEdit control. If you're using MSVC, you can create one with MFC's classes, or in VB it's just another control.

Otherwise.... you'll have to make the control yourself, from scratch (that is, if you want to make it and not just find someone else's code to do it for you). It wouldn't be too complicated (a buffer, scrollbars, and printing the text).

- taubz

Posted by Mike_L [send private reply] at January 27, 2002, 02:38:26 AM

You can use the CreateWindowEx() function to create a window instance of the EDIT window class. This works for simple status displays, but it is not ideal for interactive windows. The difficulty comes in appending text to the window. With the EDIT window you have to send it a message to position the cursor at the end of the text, and then you have to send another message to insert the new text. This causes a problem when the user is scrolling because the window suddenly jumps to the bottom of the text. Also if the user is selecting anything, their selection gets screwed up.

I haven't played with the richedit control at all. When I was really into the Win32 API I implemented my own text output control. At the time I didn't realize how much work it was. =) I don't think you want the code because it is really ugly.

Perhaps MS has better documentation on RICHEDIT now? MSVC++5.0's docs on it are quite poor.

To make your own control you will need to create a WndProc() function to handle all of the window's messages. Then you must call RegisterClassEx() to associate a class name with your WndProc. The WndProc will need to recognize the WM_CREATE message and create the window's scroll bars and initialize all the internal variables. It is best to create a special structure to store the edit window's data in. When you register the class you need to specify four extra window bytes. Then your WM_CREATE handler can allocate the data structure and store the pointer to it by using SetWindowLong(). This way all subsequent calls to the WndProc() will be able to get the data for the specific window instance. This is important when your application has more than one instance of the window. It is also good practice for making your code reusable. You may want to put your custom window's code into a DLL. Then it will be truly reusable. =)

Then you will need to implement code to handle WM_PAINT, the scroll bar notifications, and the add-text messages from your application. Painting is easy. WM_SIZE means you have to recalculate the word-wrap. It's a annoying because you have to call that GDI function to find how much of your string will fit in the certain width on the DC. I have forgotten the name of the function. I just remember that it was a difficult figuring out how to make it work.

If I wrote that code again, I would split up the text into words and then determine the width of each word and store it. Then word wrap would be quick. Rendering the text would be a little slower though.

There are many ways to implement word-wrap tho.

Hope this helps.

-Mike_L
mike@NOSPAM.tamale.net

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.