Problem with a While

I'm reading a Richbox of another app from my app, works fine until I try to get each line in a loop, I'm sure my mistake is in the loop because manually editing nbucle without the loop this works perfectly ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
DWORD dwlineas = SendMessage(hListWnd,EM_GETLINECOUNT,0,0); // Get the number of lines of RichTextBox
   int nbucle=0;
   
    while(nbucle<=dwlineas){ // lo inicio
    DWORD dwCount = SendMessage(hListWnd,EM_LINELENGTH,0,0); // get the length of the line
	if(dwCount){ // si todo esta correcto
		char* lpBuff = new char[dwCount+1]; // I think that is a pointer to the length of the line +1
		if(!lpBuff){ // if no buffer, error
			MessageBox(NULL,"Error with memory!",NULL,MB_OK);
			return 1;
		}
		if(LB_ERR != SendMessage(hListWnd,EM_GETLINE,nbucle,(LPARAM)lpBuff)){ // if no error, I select the line from nbucle
			cout<< "Bucle: " << nbucle << endl; // gives me the number of loop
            cout << lpBuff << endl; // print line
		}
		delete [] lpBuff; // I clear the buffer pointer
	}
    //
    nbucle++; // a high loop
    Sleep(2000); // wait 2 seconds
    }

The code works only with the first line, if I remove the "while" and put other lines work. Anyone can help me?, sorry about my english, thanks.
SendMessage(hListWnd, EM_LINELENGTH, 0, 0);
Quoting MSDN, wParam is:
The character index of a character in the line whose length is to be retrieved. If this parameter is greater than the number of characters in the control, the return value is zero.


This means you need to track the char position too:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
DWORD dwlineas = SendMessage(hListWnd,EM_GETLINECOUNT,0,0);
int nbucle=0;

DWORD dwCharPos = 0;
while(nbucle<=dwlineas){ // lo inicio
	DWORD dwCount = SendMessage(hListWnd,EM_LINELENGTH,dwCharPos,0);
	if(dwCount){ // si todo esta correcto
		dwCharPos += dwCount;
		char* lpBuff = new char[dwCount+1];
		if(!lpBuff){ // if no buffer, error
			MessageBox(NULL,"Error with memory!",NULL,MB_OK);
			return 1;
		}
		if(LB_ERR != SendMessage(hListWnd,EM_GETLINE,nbucle,(LPARAM)lpBuff)){
			cout<< "Bucle: " << nbucle << endl; // gives me the number of loop
			cout << lpBuff << endl; // print line
		}
		delete [] lpBuff;
	}
Last edited on
Could you give me any examples of how it should do what you say?, I have not fully understood, by the way thank you
This work a lil!, now I get this output

Bucle: 0
Please connect
Bucle: 1

Bucle: 2
Authorising...
Bucle: 3

Bucle: 4
, _______


And this is the actual text
Please connect
Connecting to: Thierry Henry
Authorising...
Connection accepted
, _______
- \O |.. ,.|
- /\ _ o |.o/ .|:
__/\ ` ' /\ | /\..|::
` \,O /\ ` |`.<<.|:::
^^^``^^`^^^`^^^`^`^``^^^`^^`^`^^`^

What I can do?
Last edited on
Does the edit text lines end with \n ? You may need to use:
 
dwCharPos += dwCount + 1;
In any event, you know what your problem was and you know how to fix it. I'm not in a position to compile that code right now.
Topic archived. No new replies allowed.