Savoir quand on clique sur un bouton

cyberlewis Messages postés 50 Date d'inscription samedi 4 janvier 2003 Statut Membre Dernière intervention 20 février 2005 - 8 févr. 2004 à 18:23
cs_Matt67 Messages postés 549 Date d'inscription samedi 6 septembre 2003 Statut Membre Dernière intervention 6 mars 2010 - 9 févr. 2004 à 20:46
Slt à tous,

Voilà j'ai un code que j'ai fait, et normalement si on cliques sur les boutons, ça lance la fonction Encode() ou Decode() en fonction du bouton cliqué ...

En revanche, le code ne fonctionne pas, j'arrive par contre à gérer les clics sur les boutons sur la fenêtre, sur les boutons aussi (mais pas sur un en particulier) ...

Pouvez-vous m'aider à trouver l'erreur svp ???

#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()
{
MessageBox(hWnd, "TEST", "TEST", MB_OK);
return 0;
}

int Decode()
{
MessageBox(hWnd, "TEST2", "TEST2", MB_OK);
return 0;
}

Code:
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch(message)
{
case WM_COMMAND : if ((LOWORD(wParam) IDC_BUTTON_ENCODE) && (HIWORD(wParam) BN_CLICKED))
{
Encode();
} else if ((LOWORD(wParam) IDC_BUTTON_DECODE) && (HIWORD(wParam) BN_CLICKED))
{
Decode();
}
break;

case WM_CREATE :

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 );

break;

case WM_DESTROY :

PostQuitMessage(0);

break;

case WM_PAINT :
{

PAINTSTRUCT PaintStruct;

HDC PaintDC=BeginPaint( hWnd, &PaintStruct );

EndPaint( hWnd, &PaintStruct );
}
break;
}
return DefWindowProc( hWnd, message, wParam, lParam );
}

int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpszCmpParam,int nCmdShow)
{
WNDCLASS W;
HWND hWnd;
LPSTR Name = "Fenêtre Windows";
MSG msg;

memset( &W, 0, sizeof(WNDCLASS) );

W.style = CS_HREDRAW | CS_VREDRAW;
W.hInstance = hInst;
W.lpszClassName = Name;
W.hbrBackground =(HBRUSH) COLOR_WINDOW;
W.lpfnWndProc = WndProc;

RegisterClass( &W );

hWnd = CreateWindowEx( 0, Name, Name, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 300, 300,
NULL, NULL, hInst, NULL );

ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );

while( GetMessage( &msg, NULL, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;

}

@+ Merci d'avance ...

http://www.realtuning.online.fr

3 réponses

cs_Arnotic Messages postés 933 Date d'inscription dimanche 1 avril 2001 Statut Membre Dernière intervention 9 janvier 2012
8 févr. 2004 à 19:56
Bonjour,

Il suffit de :

(LOWORD(wParam) == IDC_BUTTON_ENCODE)

@+
Arnotic
Admin CS, MVP Visual C++
0
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
8 févr. 2004 à 23:25
lors de la création de tes boutons, il faut leur donner l'Id de commande dans le paramètres HMENU :

hButton_Src_File = CreateWindow( "BUTTON", "Encoder",
WS_CHILD | WS_VISIBLE |
ES_LEFT | WS_BORDER,
20, 50, 100, 20,
hWnd,
(HMENU)IDC_BUTTON_ENCODE ,
hInst, NULL );
0
cs_Matt67 Messages postés 549 Date d'inscription samedi 6 septembre 2003 Statut Membre Dernière intervention 6 mars 2010 3
9 févr. 2004 à 20:46
Bonsoir,

Rien a voir avec le sujet mais pourquoi declares tu les handles de tes controles en static si tu les declares en globales ??? C'est bon si tu les declarais dans ta WindowProc.

Matt...
0
Rejoignez-nous