Evenement touche presse sur edit

Résolu
NairodDorian Messages postés 130 Date d'inscription lundi 26 juin 2006 Statut Membre Dernière intervention 18 août 2008 - 25 mars 2007 à 11:54
NairodDorian Messages postés 130 Date d'inscription lundi 26 juin 2006 Statut Membre Dernière intervention 18 août 2008 - 25 mars 2007 à 13:04
Bonjour,

Je rencontre un petit blocage avec l'API Win32.

BOOL CALLBACK AppDlg(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)

{

switch (msg) {

case WM_INITDIALOG:SetClassLong(hdlg, GCL_HICON, (LONG)LoadIcon(NULL, IDI_APPLICATION));

SetDlgItemInt(hdlg, IDC_EDIT_CM, 18, FALSE);

return TRUE;

case WM_COMMAND:

switch (LOWORD(wparam)) {

/* Analyse des menus */

case ID_APPLICATION_QUITTER:

case IDCANCEL:EndDialog(hdlg, 0);

return TRUE;

case ID_RESULTAT_NETTOYER:

if (MessageBox(hdlg, TEXT(
"Voulez vous supprimer toute votre configuration ?"),TEXT(

"Question"), MB_YESNO | MB_ICONQUESTION) == IDYES) {

/* Supprime toute la configuration utilisateur */SetDlgItemInt(hdlg, IDC_EDIT_CM, 18, FALSE);

SetDlgItemText(hdlg, IDC_EDIT_MAX, NULL);

SetDlgItemText(hdlg, IDC_EDIT_VALUE, NULL);

SendDlgItemMessage(hdlg, IDC_LIST_VALUE, LB_RESETCONTENT, 0, 0);

SendDlgItemMessage(hdlg, IDC_LIST_RESULT, LB_RESETCONTENT, 0, 0);

break;}

break;}

case WM_KEYDOWN:

if (LOWORD(wparam) == IDC_EDIT_VALUE) {

/* Recupere le code de la touche */

switch (wparam) {

case VK_LEFT:

/* NE FAIT RIEN */

break;

default:

/* blabla */}

}

break;

default:

return FALSE;}

return FALSE;}

int

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

DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_APP), NULL, (DLGPROC)AppDlg, 0);

return 0;}

Je cherche a recupere l'evenement WM_KEYDOWN correspondant au controle IDC_EDIT_VALUE.
Je teste alors si la touche presse est la fleche de gauche mais ca ne fonctionne jamais !

Pouvez vous m'aider ?
Merci d'avance

2 réponses

racpp Messages postés 1909 Date d'inscription vendredi 18 juin 2004 Statut Modérateur Dernière intervention 14 novembre 2014 17
25 mars 2007 à 12:38
Salut,
Tu peux sous-classer ton Edit:

WNDPROC OldEditProc;

LRESULT CALLBACK EditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
    case WM_GETDLGCODE:
        return (DLGC_WANTALLKEYS |  CallWindowProc(OldEditProc, hwnd, message,   wParam, lParam));

    case WM_KEYDOWN:
        MessageBox(0,TEXT("Touche pressée"),0,0);
        break;
    }

    return CallWindowProc(OldEditProc, hwnd, message, wParam, lParam);
}

BOOL CALLBACK AppDlg(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)

{
    switch (msg)
    {
    case WM_INITDIALOG:
        HWND hEdit;
        hEdit=GetDlgItem(hdlg, IDC_EDIT_VALUE);
        OldEditProc=(WNDPROC)SetWindowLong(hEdit, GWL_WNDPROC,(LONG)EditProc);
        SetClassLong(hdlg, GCL_HICON, (LONG)LoadIcon(NULL, IDI_APPLICATION));
        SetDlgItemInt(hdlg, IDC_EDIT_CM, 18, FALSE);
        return TRUE;
    }
    //.....
}

L'événement de pression sur une touche est donc récupéré dans la procédure de sous-classement EditProc().
3
NairodDorian Messages postés 130 Date d'inscription lundi 26 juin 2006 Statut Membre Dernière intervention 18 août 2008
25 mars 2007 à 13:04
Impecable merci beaucoup !
0
Rejoignez-nous