Mon problème est le suivant:
Je voudrais compter le nombre de changement de valeur dans un EditBox
Le problème c'est que WM_COMMAND, est envoyé par Windows au moins trois fois pour un valeur rentrée au clavier dans un EditBox particulier.
J'ai essayé WM_ACTIVATE, n'est pas envoyé par Windows quand je clic et je rentre une valeur dans mon EditBox..
j'ai essayé KILLFOCUS, ça marche mais je pers le focus pour toute la suite du programme et je n'accède plus à mon EditBox.
Dans mon programme je capture l'EditBox concerné car j'en ai plusieurs dans mon apli,.par case WM_COMMAND: je n'affiche qu'un caractere en effaçant si plus d'un caractere et j'ai créé ma fenêtre de travail et mes EditBox, par VisualC++ V5.
Donc comment récuperer un seule fois le "Operation.Unit.ResClic++" de mon programme quand celui-ci est modifié par l'utilisateur.
MERCI
Ci-joint mon programme pour diagnostique.
#include <windows.h>
#include "resource.h"
HINSTANCE hInst = NULL; // instance du programme
struct Base {
int res; //Résultat
int ResClic; //Resultat non cliqué = 0 sinon = 1
int ResVide; //Resultat non renseigné = 0 sinon = 1
} ;
struct TAB {
int NbErreur;
struct Base Unit; //Unité
} ;
struct TAB Operation; //Structure de l'opération en cours
//Prototypage
int CALLBACK DialogProc (HWND , UINT , WPARAM , LPARAM );
/**********************************************************************************/
int CALLBACK DialogProc (HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) {
//Handle commun
HFONT hfontDlg; // Font for dialog text
static char Res_U [2] = "";
switch (message) {
case WM_INITDIALOG:
{
hfontDlg = CreateFont(48,0,0,0,700,FALSE,FALSE,0,0,0,0,0,0,"Arial");
SendMessage (GetDlgItem (hwndDlg, IDC_EDIT1) , WM_SETFONT, (WPARAM)hfontDlg,(LPARAM)TRUE);
hfontDlg = CreateFont(24,0,0,0,700,FALSE,FALSE,0,0,0,0,0,0,"Arial");
SendMessage (GetDlgItem (hwndDlg, IDC_NB_ERREUR), WM_SETFONT, (WPARAM)hfontDlg,(LPARAM)TRUE);
Operation.NbErreur = 0;
Operation.Unit.ResClic = 0;
SetWindowText(GetDlgItem(hwndDlg, IDC_NB_ERREUR),"0");
}
case WM_COMMAND:
{
HDC hdc = (HDC) wParam;
HWND hwnd = (HWND) lParam;
i f (GetFocus() == GetDlgItem(hwndDlg, IDC_EDIT1)) {
GetWindowText (GetDlgItem(hwndDlg, IDC_EDIT1), Res_U, 3);
if (strlen(Res_U)!=0 ) {
Operation.Unit.ResClic++; //Compte les changements
Operation.Unit.ResVide = 1;
if(strlen(Res_U)>1) {
Res_U[1] = '\0'; // Pas plus de 1 caractères
SetWindowText(GetDlgItem(hwndDlg, IDC_EDIT1),Res_U);
}
} else {
Operation.Unit.ResVide = 0;
Operation.Unit.ResClic = 0;
}
Operation.Unit.res = atoi (Res_U);
}
switch (LOWORD (wParam)) {
case IDOK:
case IDCANCEL:
{
EndDialog(hwndDlg, 0);
return TRUE;
break;
}
} //Find switch (LOWORD)
break;
} //Fin de WM_COMMAND
break;
} //Fin de switch (message)
return 0;
}
/******************************************************************/
/******************************************************************/
/***************** Fonction WinMain *****************************/
/******************************************************************/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
//Allouer de la mémoire pour notre dialog template:
LPDLGTEMPLATE lpdt = ( LPDLGTEMPLATE) GlobalAlloc(GPTR, 512);
if (!lpdt) return 1;
// Définir les propriétés de la boite de dialogue:
lpdt->style = DS_CENTER | WS_POPUP | WS_MINIMIZEBOX| WS_SYSMENU | DS_MODALFRAME | WS_CAPTION;
lpdt->x = lpdt->y = 0; lpdt->cx = 230; lpdt->cy = 155;
//Lancer la boite de dialogue
DialogBox (hInst, MAKEINTRESOURCE (IDD_DIALOG1), NULL, DialogProc);
//Libération de la mémoire allouée:
GlobalFree((HGLOBAL)lpdt);
//Retour:
return 0;
}
Timy94