Solved

Multiline Textbox

Posted on 2004-04-16
19
1,702 Views
Last Modified: 2013-11-20
I have a multiline text box that I am trying to write to.  However, I cannot get it to write to the next line.  All that displays is the last thing that it writes, you can actually see it writing everything by the movement of the scrollbar, but it is all on the same line.  This is the relavent code:

if(strcmp(ext, "rul") == 0)
{
      wsprintf(szBuffer, "%s%s", szBuffer, "\r\n");
      HWND hwnd = GetDlgItem( hDlg, IDC_LISTVIEW );
      SetWindowText( hwnd, szBuffer );

      //DeleteFile(szBuffer);
}
I tried formatting a new line/carriage return to the end of the string that I want to display, but it does not work (actually it nullify's my whole string).

Each time the program enters the if statement I would like to write szBuffer to screen.  All help would be greatly appreciated.
0
Comment
Question by:CodeDeamon
  • 6
  • 3
  • 3
  • +4
19 Comments
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10845515
In the properties for the edit-box (using resource editor) , make sure that Multiline is enabled
in the string that you want displayed you should use \r\r\n to go to the next line in the edit box
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 10845561
IF u want to go to the next line by using enter u have to enable the wantreturn in the CEditBox Properties, otherwise u have to use Ctrl+enter (use it for writing on it too)
0
 

Author Comment

by:CodeDeamon
ID: 10845648
I have multiline turned (hence, why I was able to watch the scrollbar) and I have wantreturn enabled.  I tried adding an extra \r but to no avail.
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 10846396
I just made a new MFC rekt..only made a button & a multiline CEditBox with Wantreturn..
and inserted the code for the button:
void CtestmultiDlg::OnBnClickedButton1()
{
      
      m_Text="asd\r\n dsfsd";//m_Text is a CString variable for the CEditBox
      UpdateData(false);
}

i only can say..it works!
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 10846407
I just made a new MFC Project*...
0
 
LVL 14

Expert Comment

by:wayside
ID: 10846511
>    wsprintf(szBuffer, "%s%s", szBuffer, "\r\n");

How much text is in szBuffer?

MSDN says this is limited to 1024 characters.

Also you are copying szBuffer onto itself, which is not a good thing to do. Why not just append the \r\n?

strcat(szBuffer, "\r\n");



0
 
LVL 14

Expert Comment

by:wayside
ID: 10846528
Also, if you need more than 1024 characters, you can use sprintf instead of wsprintf.

Finally:

>    HWND hwnd = GetDlgItem( hDlg, IDC_LISTVIEW );

Are you sure you've created a multi-line edit box and not a list view? Based on the fact that the id is "IDC_LISTVIEW", it makes me wonder.

0
 

Author Comment

by:CodeDeamon
ID: 10846568
Originally, I was going to use a List view control, but changed it and haven't changed the name yet.  Just trying to get this thing to work first.
0
 

Author Comment

by:CodeDeamon
ID: 10846664
I have verified that I have a multiline control.  The following code works:

SetWindowText( hwnd, "Multiline \r\n Test" );

So what is wrong with the concat??
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10846725
At the time you call "wsprintf(szBuffer, "%s%s", szBuffer, "\r\n");" what exactly is szBuffer set to? Before and after the call? Are you sure you do have several lines in this buffer? It will not automatically append the new line to the text that's already in the edit control, you need to have multiple lines in this buffer in order to get the multi-line text in the control.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10846729
Have you tried to use a different output buffer than szBuffer?
0
 
LVL 2

Expert Comment

by:dxdat99
ID: 10847694
Hei!
Try this
make sure that "Multiline" & "Want return" is enabled and EDIT BOX as big as you can see
---------
GetDlgItem(IDC_LISTVIEW)->SetWindowText(_T("Hello Hello Hello Hello Hello \r\nHello Hello Hello Hello Hello"));
---------
Good luck
0
 
LVL 7

Accepted Solution

by:
vijay_visana earned 125 total points
ID: 10847911
I tried this and it is working fine I have added extra code to just check that \r\n is really inserted at the end of text.


void CDlgTestDlg::OnButton1()
{
      char szBuffer[250];
      char* szGetBuffer;
      strcpy(szBuffer,"The system calls this to obtain the cursor to display while the user dragsthe minimized window.");
      wsprintf(szBuffer, "%s%s", szBuffer, "\r\n");//remove this line once you run this programme to
//see that what you intended to do is really happening.
    HWND hwnd = ::GetDlgItem(this->m_hWnd ,IDC_EDIT1);
    ::SetWindowText( hwnd, szBuffer );
//just to check that \r\n is inserted at end
      szGetBuffer = new char [250 - strlen(szBuffer)];
      if(::GetWindowText(hwnd,szGetBuffer,249 - strlen(szBuffer)))
      {
            wsprintf(szBuffer, "%s%s", szBuffer, szGetBuffer);
            ::SetWindowText( hwnd, szBuffer );
      }
      delete [] szGetBuffer;
      ::SetFocus(hwnd);
      
}

Hope I understood what you say and
Hope u understand what I am trying to say

Good luck
Vijay
0
 

Author Comment

by:CodeDeamon
ID: 10858775
Vijay,

I understand what you are saying.  Perhaps, there is a better way to do what I want to do.  I would like to be able to write a string of text to some sort of text box letting the user know what file has been deleted.  Ideally, I would like to not have to keep appending to the end of the previous string.  Just dump it to the screen and forget about it.

Is there a better way of doing it then I am?  What would be the ideal text box to use?  Do you have an example?

Thanks.
0
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10859417
Now I do not understand what you want to do.
I tried and gave you code which is working as you wanted it to be.
(actually there was no problem what you were doing  I just gave you proof that thing is happening as you wanted it to be)
using  listbox for this is good idea go ahead.


vijay
0
 

Author Comment

by:CodeDeamon
ID: 10861374
All right, let me see if I can explain this better.  The program goes through a specific folder and deletes .rul files.  Everytime it deletes a file I would like to display the file path with the file name in a text box and the word DELETED.  Your suggestion above would require me to keep track of everytime it deletes a file and append the new file path to the previous file path.  So, if I deleted 100 files, I would have 100 file paths seperated by /r/n's.  I was hoping that I could just display the path in the text box and then move on and forget about the path.  The next one to be deleted would display the path on the next line and be forgotten and so on down the line.  Is this possible?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10861450
You don't have to keep track of the paths, you can first read the current string stored in your edit control (with GetWindowText()), add your new path and set the window text again. Just make sure that you also set the scroll bar position so that it's displaying the end of the list.
0
 

Author Comment

by:CodeDeamon
ID: 10861630
Well, thanks for the help, but I used the list control instead.  It actually did what I wanted with out having to worry about append the paths together with a carriage return in between.  For anyone that might come across this trying to do the same thing, here is the code:

HWND hwnd = GetDlgItem( hDlg, IDC_LISTVIEW2 );

            lvi.mask = LVIF_TEXT;
            lvi.iItem = 0;
            lvi.pszText = szBuffer;
            SendMessage(hwnd, LVM_INSERTITEM, (WPARAM)0, (LPARAM)&lvi);

            lvi.iSubItem = 1;
            lvi.pszText = "DELETED";
            SendMessage(hwnd, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
0
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10865932
//using  listbox for this is good idea go ahead.

As I told you earlier may be you missed that part.
use of listbox or listcontrol would be good for you
As listbox is easy and less complex it is best fit.


Good luck

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

744 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