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