[API]Recuper le texte d'une zone de texte

Résolu
shadow1779 Messages postés 706 Date d'inscription mercredi 17 novembre 2004 Statut Membre Dernière intervention 29 septembre 2013 - 3 déc. 2005 à 20:29
Lord_Patoche Messages postés 196 Date d'inscription mercredi 6 août 2003 Statut Membre Dernière intervention 1 mai 2009 - 6 déc. 2005 à 23:20
Bonsoir,



j'ai presque terminé de me faire un bloc notes amelioré, mon dernier
probleme est l'enregistrement de fichier, j'arrive a creer la boite de
dialogue pour choisir ou enregistrer, je fais bien le CreateFile() mais
je ne sais pas parcontre comment recuperer le texte qui a été tapé et
le mettre dans une chaine de caracterer pour un WriteFile()



Merci d'avance

10 réponses

vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
3 déc. 2005 à 21:53
Eh bien GetWindowText sur hEdit
3
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
3 déc. 2005 à 20:44
En général c'est GetWindowText. Dans quoi l'utilisateur entre-t-il le texte?
0
shadow1779 Messages postés 706 Date d'inscription mercredi 17 novembre 2004 Statut Membre Dernière intervention 29 septembre 2013
3 déc. 2005 à 21:15
c'est l'équivalent d'un notepad donc c'est dans la fenetre en elle meme



( hEdit =CreateWindow("edit", "",


WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,


0, 0, 0, 0, hwnd, (HMENU)IDC_MAIN_TEXT, hinst, NULL);

hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);

SendMessage(hEdit,WM_SETFONT,(UINT)hFont,TRUE);


SendMessage(hEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN,


MAKELONG(5, 5));

)
.
0
shadow1779 Messages postés 706 Date d'inscription mercredi 17 novembre 2004 Statut Membre Dernière intervention 29 septembre 2013
3 déc. 2005 à 22:38
Ok merci
.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Lord_Patoche Messages postés 196 Date d'inscription mercredi 6 août 2003 Statut Membre Dernière intervention 1 mai 2009 3
3 déc. 2005 à 22:40
salut, regarde l'une de mes sources sur ce site. c'est une bibliothèque permettant de récupérer toutes les lignes d'une zone de Texte. GetWindowsText ne récupère que la première ligne d'une zone de texte.

LaPatoshe
0
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
3 déc. 2005 à 23:53
D'abord ce n'est pas GetWindowsText mais GetWindowText, et cette fonction récupère bien toutes les lignes d'un edit, tu n'a qu'a essayer
0
Lord_Patoche Messages postés 196 Date d'inscription mercredi 6 août 2003 Statut Membre Dernière intervention 1 mai 2009 3
4 déc. 2005 à 16:47
c'est exact, sauf que dans le cas ici présent, il va falloir sauvegarder le texte dans un fichier, puis pouvoir le restituer dans une zone de texte ultérieurement après chargement, et si tu te contentes uniquement de l'usage de GetWindowText pour se faire, seule la première ligne de ton texte apparaitra par la suite. Il y a eu plusieurs post sur le sujet par le passé.
LaPatoshe
0
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
4 déc. 2005 à 17:14
Pas du tout, les sauts de lignes sont sauvegardés dans le fichier aussi, je vois pas le problème
0
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
4 déc. 2005 à 17:19
Comme le retour à la ligne n'est rien d'autre que 2 caractères ('\r' et '\n'), je vois pas pourquoi la fonction GetWindowText ferait un tri dans les caractères qu'elle prendrait.

YOYO, @+.
YOYO
0
Lord_Patoche Messages postés 196 Date d'inscription mercredi 6 août 2003 Statut Membre Dernière intervention 1 mai 2009 3
6 déc. 2005 à 23:20
Salut à tous. Effectivement, j'ai parlé un peu vite. Le problème que j'avais eu avec GetWindowText était à l'époque lors de l'enregistrement du texte ainsi récupéré.
En effet, en enregistrant le texte et en plaçant \n\r pour le retour à la ligne, ce dernier n'était pas pris en compte. Du coup, j'avais trouvé une solution pour pouvoir enregistrer les textes ligne par ligne.
Ci joint un petit prog expliquant que lors de l'enregistrement d'un texte avec WritePrivateProfileString par exemple, l'enregistrement s'effectue bien. Cependant, lors du chargement avec GetPrivateProfileString, seule la première ligne n'ayant pas été terminée par l'appui sur la touche ENTREE est restituée. Lorsque jaais le même exercice en enregistrant mon texte au moyen de FILE, j'avais eu un problème similaire malgrè mon rajout de \n\r.

#include <windows.h>
#include <malloc.h>


MSG Msg;
HWND hFeuille;
HWND hZoneEdition;
HWND hZoneReception;
HWND hZoneChargement;
HWND hBoutonCopier1;
HWND hBoutonCopier2;
HWND hBoutonEnregistrer;
HWND hBoutonCharger;



LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{


WNDCLASS FEUILLE;
FEUILLE.cbClsExtra = 0;
FEUILLE.cbWndExtra = 0;
FEUILLE.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
FEUILLE.hCursor = (HCURSOR) LoadCursor(0, IDC_ARROW);
FEUILLE.hIcon = (HICON) LoadIcon(0, IDI_APPLICATION);
FEUILLE.hInstance = hInstance;
FEUILLE.lpfnWndProc = WinProc;
FEUILLE.lpszClassName = "F";
FEUILLE.lpszMenuName = 0;
FEUILLE.style = CS_HREDRAW | CS_VREDRAW;


RegisterClass(&FEUILLE);
hFeuille = CreateWindow("F", "Exercice de Copier/Coller et de Chargement/Enregistrement", WS_OVERLAPPEDWINDOW, 0, 0, 800, 800, 0, 0, hInstance, 0);
ShowWindow(hFeuille, nShowCmd);


hZoneEdition = CreateWindow("edit", "", WS_CHILD | ES_MULTILINE | WS_BORDER, 10, 10, 250, 300, hFeuille, 0, hInstance, 0);
ShowWindow(hZoneEdition, nShowCmd);


//Mettre 250 à la place de 100
hZoneReception = CreateWindow("edit", "", WS_CHILD | ES_MULTILINE | WS_BORDER, 320, 10, 100, 300, hFeuille, 0, hInstance, 0);
ShowWindow(hZoneReception, nShowCmd);


hZoneChargement = CreateWindow("edit", "", WS_CHILD | ES_MULTILINE | WS_BORDER, 100, 330, 250, 300, hFeuille, 0, hInstance, 0);
ShowWindow(hZoneChargement, nShowCmd);


hBoutonCopier1 = CreateWindow("button", ">", WS_CHILD, 270, 50, 40, 30, hFeuille, 0, hInstance, 0);
ShowWindow(hBoutonCopier1, nShowCmd);


hBoutonCopier2 = CreateWindow("button", "<", WS_CHILD, 270, 150, 40, 30, hFeuille, 0, hInstance, 0);
ShowWindow(hBoutonCopier2, nShowCmd);


hBoutonEnregistrer = CreateWindow("button", "Enregistrer", WS_CHILD, 370, 350, 100, 30, hFeuille, 0, hInstance, 0);
ShowWindow(hBoutonEnregistrer, nShowCmd);


hBoutonCharger = CreateWindow("button", "Charger", WS_CHILD, 370, 400, 100, 30, hFeuille, 0, hInstance, 0);
ShowWindow(hBoutonCharger, nShowCmd);


while(GetMessage(&Msg, 0, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}


return 0;
}



LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
}


case WM_COMMAND:
{
if((HWND) lParam == hBoutonCopier1)
{
LPTSTR Texte1 = (LPTSTR) malloc(10000);
GetWindowText(hZoneEdition, Texte1, 10000);
SetWindowText(hZoneReception, (LPCTSTR) Texte1);
}


if((HWND) lParam == hBoutonCopier2)
{
LPTSTR Texte2 = (LPTSTR) malloc(10000);
GetWindowText(hZoneReception, Texte2, 10000);
SetWindowText(hZoneEdition, (LPCTSTR) Texte2);
}


if((HWND) lParam == hBoutonEnregistrer)
{
LPTSTR Texte3 = (LPTSTR) malloc(10000);
GetWindowText(hZoneReception, Texte3, 10000);
WritePrivateProfileString("0", "ENREGISTREMENT", Texte3, "c:\\LaPatoshe.txt");
}


if((HWND) lParam == hBoutonCharger)
{
LPTSTR Texte4 = (LPTSTR) malloc(10000);
GetPrivateProfileString("0", "ENREGISTREMENT", "$", Texte4, 10000, "c:\\LaPatoshe.txt");
SetWindowText(hZoneChargement, Texte4);
}
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

LaPatoshe
0
Rejoignez-nous