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

Windows Discussion :

Gérer les clics sur les boutons


Sujet :

Windows

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 26
    Points : 19
    Points
    19
    Par défaut Gérer les clics sur les boutons
    Salut,


    Voilà j'ai fait un code "test" avec deux edits et deux boutons,


    Svp pouvez-vous m'aider et me dire comment faire pour que quand je clique par ex sur un bouton ça lance une fonction FONCTION(edit1) avec comme argument la valeur d'un de mes edits ...


    Svp, merci d'avance pour toute aide ...


    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
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    #include <windows.h>
    
    HINSTANCE hInst;
    
    #define IDC_EDIT_SRC_FILE      0x01
    #define IDC_EDIT_DEST_FILE     0x02
    #define IDC_BUTTON_ENCODE      0x03
    #define IDC_BUTTON_DECODE      0x04
    
    
    LRESULT CALLBACK WndProc&#40; HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam &#41; 
    &#123;
        switch&#40;message&#41; 
        &#123; 
            case WM_KEYDOWN &#58; 
                 PostQuitMessage&#40;0&#41;;
                 break;
    
            case WM_DESTROY &#58; 
                 PostQuitMessage&#40;0&#41;;
                 break;
    
            case WM_PAINT &#58;
            &#123;
                PAINTSTRUCT PaintStruct; 
                HDC PaintDC=BeginPaint&#40; hWnd, &PaintStruct &#41;; 
                EndPaint&#40; hWnd, &PaintStruct &#41;;
            &#125;
            break;
        &#125;
        return DefWindowProc&#40; hWnd, message, wParam, lParam &#41;;
    &#125;
    
    
    
    
    
    int WINAPI WinMain&#40;HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int nCmdShow&#41; 
    &#123; 
        WNDCLASS W;
        HWND hWnd;
        LPSTR Name = "Exemple d'Application";
        MSG Msg;
    
    
        memset&#40; &W, 0, sizeof&#40;WNDCLASS&#41; &#41;;
        W.style = CS_HREDRAW | CS_VREDRAW;
        W.hInstance = hInst;
        W.lpszClassName = Name;
        W.hbrBackground =&#40;HBRUSH&#41; COLOR_WINDOW;
        W.lpfnWndProc = WndProc;
        RegisterClass&#40; &W &#41;;
    
    
        hWnd = CreateWindowEx&#40; 0, Name, Name, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 300, 300, 
    		NULL, NULL, hInst, NULL &#41;; 
    
    
        ShowWindow&#40; hWnd, nCmdShow &#41;; 
        UpdateWindow&#40; hWnd &#41;;
    
    
    static HWND hEdit_Src_File = NULL;
    static HWND hEdit_Dest_File = NULL;
    static HWND hButton_Src_File = NULL;
    static HWND hButton_Dest_File = NULL;
    
    
    hEdit_Src_File = CreateWindow&#40; "EDIT", "",
    WS_CHILD | WS_VISIBLE | 
    ES_LEFT | WS_BORDER,
    20, 8, 100, 20,
    hWnd,
    NULL,
    hInst, NULL &#41;;
    
    hEdit_Dest_File = CreateWindow&#40; "EDIT", "",
    WS_CHILD | WS_VISIBLE | 
    ES_LEFT | WS_BORDER,
    20, 30, 100, 20,
    hWnd,
    NULL,
    hInst, NULL &#41;;
    
    hButton_Src_File = CreateWindow&#40; "BUTTON", "Encoder",
    WS_CHILD | WS_VISIBLE | 
    ES_LEFT | WS_BORDER,
    20, 50, 100, 20,
    hWnd,
    NULL,
    hInst, NULL &#41;;
    
    hButton_Dest_File = CreateWindow&#40; "BUTTON", "Décoder",
    WS_CHILD | WS_VISIBLE | 
    ES_LEFT | WS_BORDER,
    140, 50, 100, 20,
    hWnd,
    NULL,
    hInst, NULL &#41;;
    
    
    
    
        while&#40; GetMessage&#40; &Msg, NULL, 0, 0&#41; &#41; 
        &#123; 
            TranslateMessage&#40; &Msg &#41;; 
            DispatchMessage&#40; &Msg &#41;;
        &#125;
        return Msg.wParam; 
    &#125;
    http://www.earning.online.fr

  2. #2
    Expert éminent sénior

    Homme Profil pro
    pdg
    Inscrit en
    Juin 2003
    Messages
    5 749
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : pdg

    Informations forums :
    Inscription : Juin 2003
    Messages : 5 749
    Points : 10 666
    Points
    10 666
    Billets dans le blog
    3
    Par défaut
    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
    static void Fonction&#40; LPCTSTR Text &#41;;
    &#91;...&#93;
    case WM_LBUTTONDOWN&#58;
        OnLeftButtonDown&#40; hWnd, LOWORD&#40;lParam&#41;, HIWORD&#40;lParam&#41; &#41;;
        return 0;
    &#91;...&#93;
    static void OnLeftButtonDown&#40; HWND hWin, int X, int Y &#41;
    &#123;
        LPCTSTR text;
        int size;
        HWND hText;
    
        hText = GetDlgItem&#40; hWin, IDC_EDIT_SRC_FILE &#41;;
        size = GetWindowTextLength&#40; hText &#41; + 1;
        text = malloc&#40; size * sizeof&#40;TCHAR&#41; &#41;;
        GetWindowText&#40; hText, text, size &#41;;
        Fonction&#40; text &#41;;
        free&#40; text &#41;;
    &#125;
    Remonte tes var
    static HWND hEdit_Src_File = NULL;
    static HWND hEdit_Dest_File = NULL;
    static HWND hButton_Src_File = NULL;
    static HWND hButton_Dest_File = NULL;
    en haut.
    Il serait mieux de placer ce code :
    hEdit_Src_File = CreateWindow( "EDIT", "",
    WS_CHILD | WS_VISIBLE |
    ES_LEFT | WS_BORDER,
    20, 8, 100, 20,
    hWnd,
    NULL,
    hInst, NULL );

    hEdit_Dest_File = CreateWindow( "EDIT", "",
    WS_CHILD | WS_VISIBLE |
    ES_LEFT | WS_BORDER,
    20, 30, 100, 20,
    hWnd,
    NULL,
    hInst, NULL );

    hButton_Src_File = CreateWindow( "BUTTON", "Encoder",
    WS_CHILD | WS_VISIBLE |
    ES_LEFT | WS_BORDER,
    20, 50, 100, 20,
    hWnd,
    NULL,
    hInst, NULL );

    hButton_Dest_File = CreateWindow( "BUTTON", "Décoder",
    WS_CHILD | WS_VISIBLE |
    ES_LEFT | WS_BORDER,
    140, 50, 100, 20,
    hWnd,
    NULL,
    hInst, NULL );
    dans WM_CREATE.
    Pour les message que tu gères (WM_KEYDOWN, WM_DESTROY, WM_PAINT) retourne la valeur recommandée par la doc et n'appelle pas DefWindowProc. Soit tu gère le message, soit tu demandes à Windows de le faire via DefWindowProc avec :
    default:
    break;
    En faisant des break dans ton code, tu appelles DefWindowProc ce qui fait traiter 2 fois le même message. Tu risques d'avoir des surprises.

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 26
    Points : 19
    Points
    19
    Par défaut
    Oki merci je vais essayer ...
    http://www.earning.online.fr

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 26
    Points : 19
    Points
    19
    Par défaut
    Je ne pex pas utiliser le code car malloc me donnes des erreurs (conversion impssible de *char), même en incluant les headers recommandés par MSDN ...


    J'ai remanié le code, mais la fenêtre ne reste qu'une demi seconde, comment faire svp ?


    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
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    #include "windows.h"
    
    
    
    #define IDC_EDIT_SRC_FILE      0x01
    #define IDC_EDIT_DEST_FILE     0x02
    #define IDC_BUTTON_ENCODE      0x03
    #define IDC_BUTTON_DECODE      0x04
    
    static HWND hEdit_Src_File = NULL; 
    static HWND hEdit_Dest_File = NULL; 
    static HWND hButton_Src_File = NULL; 
    static HWND hButton_Dest_File = NULL; 
    
    
    
    HWND hWnd;
    HINSTANCE hInst;
    
    
    
    int Encode&#40;&#41;
    &#123;
    	MessageBox&#40;hWnd, "TEST", "TEST", MB_OK&#41;;
    
    	 return 0;
    &#125;
    
    
    
    LRESULT CALLBACK WndProc&#40; HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam &#41; 
    &#123;
    	switch&#40;message&#41; 
    	&#123; 
    		case WM_LBUTTONDOWN&#58;
    
    			Encode&#40;&#41;;
    
    			break;
    
    		case WM_CREATE &#58; 
    			 
    			hEdit_Src_File = CreateWindow&#40; "EDIT", "", 
    			WS_CHILD | WS_VISIBLE | 
    			ES_LEFT | WS_BORDER, 
    			20, 8, 100, 20, 
    			hWnd, 
    			NULL, 
    			hInst, NULL &#41;; 
    
    			hEdit_Dest_File = CreateWindow&#40; "EDIT", "", 
    			WS_CHILD | WS_VISIBLE | 
    			ES_LEFT | WS_BORDER, 
    			20, 30, 100, 20, 
    			hWnd, 
    			NULL, 
    			hInst, NULL &#41;; 
    
    			hButton_Src_File = CreateWindow&#40; "BUTTON", "Encoder", 
    			WS_CHILD | WS_VISIBLE | 
    			ES_LEFT | WS_BORDER, 
    			20, 50, 100, 20, 
    			hWnd, 
    			NULL, 
    			hInst, NULL &#41;; 
    
    			hButton_Dest_File = CreateWindow&#40; "BUTTON", "Décoder", 
    			WS_CHILD | WS_VISIBLE | 
    			ES_LEFT | WS_BORDER, 
    			140, 50, 100, 20, 
    			hWnd, 
    			NULL, 
    			hInst, NULL &#41;; 
    			 
    		case WM_DESTROY &#58; 
    			 
    			 PostQuitMessage&#40;0&#41;;
    			 
    			 break;
    
    		case WM_PAINT &#58;
    		&#123;
    			
    			PAINTSTRUCT PaintStruct; 
    			
    			HDC PaintDC=BeginPaint&#40; hWnd, &PaintStruct &#41;; 
    			
    			EndPaint&#40; hWnd, &PaintStruct &#41;;
    		&#125;
    		break;
    	&#125;
    	return DefWindowProc&#40; hWnd, message, wParam, lParam &#41;;
    &#125;							
    
    
    			
    int WINAPI WinMain&#40;HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpszCmpParam,int nCmdShow&#41; 
    &#123;
    	WNDCLASS W;
    	HWND hWnd;
    	LPSTR Name = "Fenêtre Windows";
    	MSG msg;
        
    	memset&#40; &W, 0, sizeof&#40;WNDCLASS&#41; &#41;;
    	W.style = CS_HREDRAW | CS_VREDRAW;
    	W.hInstance = hInst;
    	W.lpszClassName = Name;
    	W.hbrBackground =&#40;HBRUSH&#41; COLOR_WINDOW;
    	W.lpfnWndProc = WndProc;
    	RegisterClass&#40; &W &#41;;
    
    	hWnd = CreateWindowEx&#40; 0, Name, Name, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 300, 300, 
    		NULL, NULL, hInst, NULL &#41;; 
    
    	ShowWindow&#40; hWnd, nCmdShow &#41;; 
    	UpdateWindow&#40; hWnd &#41;;
    
    	while&#40; GetMessage&#40; &msg, NULL, 0, 0&#41; &#41; 
    	&#123;
    		TranslateMessage&#40; &msg &#41;; 
    		DispatchMessage&#40; &msg &#41;;
    	&#125;
    	return msg.wParam; 
    &#125;
    http://www.earning.online.fr

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 26
    Points : 19
    Points
    19
    Par défaut
    J'avais oublié un break; pour le WM_CREATE, par contre svp comment savoir si on cliques sur le PREMIER BOUTON svp ???
    http://www.earning.online.fr

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

Discussions similaires

  1. Ecouter les clics sur les boutons de volume
    Par titou624 dans le forum Composants graphiques
    Réponses: 1
    Dernier message: 16/08/2010, 16h40
  2. Réponses: 1
    Dernier message: 14/01/2009, 13h53
  3. Comment gérer des clics sur les touches du clavier:
    Par choko83 dans le forum Débuter avec Java
    Réponses: 4
    Dernier message: 11/03/2008, 11h15

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