Simple Click Double click Bouton Pressé Bouton Relaché ?

mcallan Messages postés 17 Date d'inscription mardi 6 mai 2003 Statut Membre Dernière intervention 28 janvier 2011 - 2 déc. 2005 à 14:52
mcallan Messages postés 17 Date d'inscription mardi 6 mai 2003 Statut Membre Dernière intervention 28 janvier 2011 - 3 déc. 2005 à 09:13
Bonjour,





Comment gerer en API Win32 (C) les evenements souris via les WM_ (WM_LBUTTONDOWN ...)
sachant que je voudrais recuperer differents etats du click de la souris c-a-d un simple click, un double click , le bouton est pressé , ou le bouton est relaché





je pense qu'il faut utiliser des timers ?





Quelque chose comme cela :





Mais cela ne fonctionne pas super bien :s





Please Help me .... LOL





HANDLE_MSG(hWindow,WM_LBUTTONDOWN,ON_EVENT_GRAPH_WM_LBUTTONDOWN);
HANDLE_MSG(hWindow,WM_LBUTTONUP,ON_EVENT_GRAPH_WM_LBUTTONUP);
HANDLE_MSG(hWindow,WM_LBUTTONDBLCLK,ON_EVENT_GRAPH_WM_LBUTTONDBLCLK);
HANDLE_MSG(hWindow,WM_MOUSEMOVE,ON_EVENT_GRAPH_WM_MOUSEMOVE);





....





static BOOL RemoveLeftUp=FALSE;
static BOOL RemoveSingle=FALSE;





#define TIMER1LEFTBUTTONPRESSED 10
#define TIMER2LEFTBUTTONSINGLE 20





static BOOL bTimerLeftPressedON=FALSE;
static BOOL LeftPressedON=FALSE;
static BOOL bTimerLeftSingleClickON=FALSE;





void CALLBACK LeftPressedClick(HWND hwnd,UINT msg,UINT_PTR id,DWORD data);
void CALLBACK LeftSingleClick(HWND hwnd,UINT msg,UINT_PTR id,DWORD data);
/*-----------------------------------------------------------------------------------*/
void ON_EVENT_GRAPH_WM_LBUTTONDOWN(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
if (fDoubleClick)
{
sciprint("Down Double Click NEVER Called \n");
}
else
{
if (LeftPressedON)
{
}
else
{
if (!RemoveLeftUp)
{

sciprint("Launch TIMER1LEFTBUTTONPRESSED\n");
bTimerLeftPressedON=TRUE;
LeftPressedON=FALSE;
SetTimer(hwnd, TIMER1LEFTBUTTONPRESSED, GetDoubleClickTime()/5,LeftPressedClick);
}
}
}
}
/*-----------------------------------------------------------------------------------*/
void ON_EVENT_GRAPH_WM_LBUTTONUP(HWND hwnd, int x, int y, UINT keyFlags)
{
if (!RemoveLeftUp)
{
if (bTimerLeftPressedON)
{
KillTimer(hwnd, TIMER1LEFTBUTTONPRESSED);
bTimerLeftPressedON=FALSE;

sciprint("Launch TIMER2LEFTBUTTONSINGLE\n");
bTimerLeftSingleClickON=TRUE;
SetTimer(hwnd, TIMER2LEFTBUTTONSINGLE , GetDoubleClickTime(),LeftSingleClick);
}
else
{
if (LeftPressedON)
{
LeftPressedON=FALSE;
sciprint("Released\n");
}
else
{
sciprint("Released 2\n");
}

}
}
else
{
RemoveLeftUp=FALSE;
}
}
/*-----------------------------------------------------------------------------------*/
void ON_EVENT_GRAPH_WM_LBUTTONDBLCLK(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
if (fDoubleClick)
{
if (bTimerLeftSingleClickON)
{
KillTimer(hwnd, TIMER2LEFTBUTTONSINGLE);
bTimerLeftSingleClickON=FALSE;
}





if (bTimerLeftPressedON)
{
KillTimer(hwnd, TIMER1LEFTBUTTONPRESSED);
bTimerLeftPressedON=FALSE;
}





sciprint("LBUTTONDBLCLK\n");





RemoveLeftUp=TRUE;
}
else
{
sciprint("Down Never Called \n");
}
}
/*-----------------------------------------------------------------------------------*/
void ON_EVENT_GRAPH_WM_MOUSEMOVE(HWND hwnd, int x, int y, UINT keyFlags)
{
if (keyFlags & MK_LBUTTON)
{
sciprint("Move and Pressed MK_LBUTTON\n");
KillTimer(hwnd, TIMER1LEFTBUTTONPRESSED);
bTimerLeftPressedON=FALSE;
LeftPressedON=TRUE;
}
else
if ( (bTimerLeftSingleClickON) && (bTimerLeftPressedON) )
{
sciprint("Single click and move\n");
KillTimer(hwnd, TIMER1LEFTBUTTONPRESSED);
KillTimer(hwnd, TIMER2LEFTBUTTONSINGLE);
}
else
if ( (LeftPressedON) || (bTimerLeftPressedON) )
{
if (LeftPressedON)
{
sciprint("Move and -->Pressed\n");
}
else
{
sciprint("Move and Pressed -->Timer\n");
KillTimer(hwnd, TIMER1LEFTBUTTONPRESSED);
bTimerLeftPressedON=FALSE;
LeftPressedON=TRUE;
}

}
else
{
if (bTimerLeftPressedON)
{
KillTimer(hwnd, TIMER1LEFTBUTTONPRESSED);
bTimerLeftPressedON=FALSE;
}

sciprint("Move\n");
LeftPressedON=FALSE;

}
}
/*-----------------------------------------------------------------------------------*/
void CALLBACK LeftPressedClick(HWND hwnd,UINT msg,UINT_PTR id,DWORD data)
{
KillTimer(hwnd, id);
bTimerLeftPressedON=FALSE;
LeftPressedON=TRUE;
sciprint("Pressed Left Click\n");





}
/*-----------------------------------------------------------------------------------*/
void CALLBACK LeftSingleClick(HWND hwnd,UINT msg,UINT_PTR id,DWORD data)
{





KillTimer(hwnd, id);
bTimerLeftSingleClickON=FALSE;
if (RemoveSingle)
{
RemoveSingle=FALSE;
}
else sciprint("Single Left Click\n");
}
/*-----------------------------------------------------------------------------------*/

2 réponses

vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
2 déc. 2005 à 16:02
WM_LBUTTONDOWN quand clic gauche et WM_LBUTTONDBLCLK quand double clique.
Le problème c'est qu'avant un WM_LBUTTONDBLCLK tu recevra toujours un WM_LBUTTONDOWN. La solution de timer me semble correcte, mais ca veut dire qu'un simple clic va impliquer une légère attente pour l'utilisateur
Cela dit, ta solution semble un peu compliquée. Tout ce que tu as a faire c'est créer un timer dans WM_LBUTTONDOWN et le killer dans WM_LBUTTONDBLCLK
Si le timer va jusqu'au bout, ca veut dire pas double clic
Pour la vitesse d'un double clic (et donc la durée du timer), c'est SystemParametersInfo
0
mcallan Messages postés 17 Date d'inscription mardi 6 mai 2003 Statut Membre Dernière intervention 28 janvier 2011
3 déc. 2005 à 09:13
WM_LBUTTONDOWN pour "appuyer" sur le bouton de la souris

WM_LBUTTONUP pour "delaisser" sur le bouton de la souris

ce que j'ai besoin ce n'est pas ces actions mais
le fait que le bouton est maintenu "presssé" et qu'il soit "relaché" par la suite
ainsi qu'un simple click ou un double

cela ne semble trop un "algo" courant car je n'ai reussi a le trouver ...

Merci de votre aide ...

N.B : SystemParametersInfo & GetDoubleClickTime ne renvoyent il pas la meme valeur ?
(pour la compatibilité avec 2k :s)
0
Rejoignez-nous