Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Putting line breaks in win32 edit box

This topic is 5232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to put some text in a message box in multiple lines by putting \n where I want the new line. This isn''t working though...All I get is a little black rectangle. How can I put the line breaks in??

Share this post

Link to post
Share on other sites
Hi tHiSiSbOb,

I think I have the answer to your question.

Here is how it goes, nice and simple. First, make sure your edit box supports multi-line. (ES_MULTILINE):

#include <windows.h>

void createEditBox(HWND hWnd, HWND hControl, HINSTANCE hInstance,
char tempText[255], int x, int y, int width, int height, int identifier ) {
x, y, width, height, hWnd, (HMENU)identifier, NULL, NULL);

// In main code

#define IDEDIT 110
HWND hEdit;
HINSTANCE hInstance;

createEditBox(hWnd, hEdit, hInstance, "My Edit Box", 24, 65, 100, 250, IDEDIT);

Now, as you might see above createEditBox() has ES_MULTILINE in the CreateWindow() code. Also I made sure that the height of the edit box was large enough to fit multilines in there without having to scroll down and the alike. Now to also make sure you can add more lines to the edit box I'll paste a code that lets you append text to your existing text box:

void appendText( HWND hwndEditBox, char *lpszText ) {
int iLineLen;
int iLineCount;
int iCurTextLen;

if( SendMessage( hwndEditBox, EM_GETLINECOUNT, 0, 0 ) > 128 ) {
iLineLen = SendMessage( hwndEditBox, EM_LINELENGTH, 0, 0 );
SendMessage( hwndEditBox, EM_SETSEL, 0, iLineLen+2 );
SendMessage( hwndEditBox, EM_REPLACESEL, FALSE, (long)"" );

iCurTextLen = SendMessage( hwndEditBox, WM_GETTEXTLENGTH, 0, 0);
SendMessage( hwndEditBox, EM_SETSEL, iCurTextLen, iCurTextLen );
SendMessage( hwndEditBox, EM_REPLACESEL, FALSE, (long)lpszText );

iLineCount = SendMessage( hwndEditBox, EM_GETLINECOUNT, 0, 0);
SendMessage( hwndEditBox, EM_LINESCROLL, 0, iLineCount );

Now all you have to do is appendText( hEdit, "My Text..." ); and it will automatically append the text with whatever is already there. Now back to your question about adding a new line without seeing that big black block, I think I have the answer.

Dont just use "\n", use "\r\n". For example:

appendText( hEdit, "My Text...\r\n" );

I hope this helps!,

[edited by - BlueDev on March 22, 2004 2:18:15 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!