IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage C++ Discussion :

Lire ligne par ligne un edit control


Sujet :

Langage C++

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    360
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 360
    Points : 137
    Points
    137
    Par défaut Lire ligne par ligne un edit control
    Bonjour,

    J'essaye de lire ligne par ligne le contenu d'un edit control, la longueur de la ligne retourne toujours 0.

    les trois code suivants ne fonctionne pas, je ne voit pas ou est l'erreur;

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
     
    int nbLig = ::SendMessage(GetDlgItem(_hSelf, IDC_EDIT_FILTER), EM_GETLINECOUNT, 0, 0);
    	for (int lineIndex = 0; lineIndex < nbLig; lineIndex++)
    	{
    		int characterIndex = ::SendMessage(_hSelf, EM_LINEINDEX, (WPARAM)lineIndex, (LPARAM)0);
    		int lineLength = ::SendMessage(_hSelf, EM_LINELENGTH, (WPARAM)lineIndex, (LPARAM)0);
     
    		if (lineLength > 0)
    		{
    			TCHAR* pBuffer = new TCHAR[lineLength + 1];
     
    			if (pBuffer)
    			{
    				// Set the size of the buffer
    				*(WORD*)pBuffer = lineLength + 1;
     
    				// Retrieve the line
    				int characterCount = ::SendMessage(_hSelf, EM_GETLINE, (WPARAM)lineIndex, (LPARAM)pBuffer);
    				// NUL-terminate buffer
    				pBuffer[characterCount] = TEXT('\0');
    				DebugMsg(TEXT("lineindex: %d characther index: %d linelength: %d buffer: %s\n"), lineIndex, characterIndex, lineLength, pBuffer);
    				delete[] pBuffer;
    			}
    		}
    	}
     
    	for (int i = 0; i < nbLig; i++)
    	{
    		int characterIndex = SendMessage(_hSelf, EM_LINEINDEX, i, 0);
    		int length = SendMessage(_hSelf, EM_LINELENGTH, characterIndex, 0);
     
    		if (length > 0)
    		{
    			TCHAR* buffer = new TCHAR[length + 1];
    			if (buffer)
    			{
    				buffer[length] = '\0';
    				buffer[0] = length;
     
    				SendMessage(_hSelf, EM_GETLINE, (WPARAM)i, (LPARAM)buffer);
    				DebugMsg(TEXT("i: %d length: %d buffer: %s\n"), i, length, buffer);
    				delete[] buffer;
    			}
    		}
    	}
     
    	for (int i = 0; i < nbLig; i++)
    	{
    		int length = SendMessage(_hSelf, EM_LINELENGTH, (WPARAM)i, 0);
    		TCHAR* buffer = new TCHAR[length + 1];
    		buffer[0] = length + 1;
    		buffer[length] = '\0';
    		SendMessage(_hSelf, EM_GETLINE, (WPARAM)i, (LPARAM)buffer);	
     
    		DebugMsg(TEXT("i: %d buffer: %s\n"), i, buffer);				
    		delete[] buffer;
    	}
    Je sous sous windows x64 en UNICODE (vs 2013);

    Merci de votre aide.

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    360
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 360
    Points : 137
    Points
    137
    Par défaut
    Désolé pour le dérangement, en fait ce n'est pas _hSelf mais l'id du control qu'il fallait mettre (GetDlgItem(_hSelf, IDC_EDIT_FILTER))
    Donc maintenant ca fonctionne.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Lire un fichier ligne par ligne
    Par lephyrexian dans le forum VBScript
    Réponses: 2
    Dernier message: 07/12/2006, 08h29
  2. Lire un fichier ligne par ligne avec Awk
    Par Krispy dans le forum Linux
    Réponses: 8
    Dernier message: 07/09/2006, 15h14
  3. Lire un fichier ligne par ligne
    Par Guillaume602 dans le forum C
    Réponses: 3
    Dernier message: 18/03/2006, 21h41
  4. lire un fichier ligne par ligne
    Par peuf23 dans le forum C
    Réponses: 6
    Dernier message: 21/09/2005, 10h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo