begin process at 2012 05 29 03:26:32
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive C/C++

 > 

Archives

 > 

Graphique

 > 

Gestion des evenements Win32


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Gestion des evenements Win32

jeudi 25 mars 2004 à 13:03:30 | Gestion des evenements Win32

zibo3

J'aimerai créer un événement appuyer sur une touche de type F3 mais cet événement doit se réaliser à chaque fois que j'appuie sur cette touche quelque soit le widget qui a le focus et je ne veux pas à avoir à recopier ce traitement pour chaque objet, voici mon code où je crée une fenêtre avec une zone de texte et un bouton je traite l'action appuyer sur la touche F3 qui fonctionnne au lancement de la fenetre mais dès que j'utilise je suis sur un deux widget, la touche F3 ne réponds plus.
Aidez moi

#include <windows.h>
//#include <windowsx.h>
#include <Shellapi.h> // Pour l'icone


LRESULT CALLBACK toto(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK tutu(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

HINSTANCE g_hInst;
WNDPROC OldScroll[2] ;


LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
TCHAR szFormat[] = TEXT ("%-16s%04X-%04X %04X-%04X"),
szBuffer[50] ;
static HWND g_hWnd[2];
HINSTANCE hInstance ;

switch(uMsg){

case WM_CREATE:
hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;

g_hWnd[0] = CreateWindow("Edit","Entrer",WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_UPPERCASE,50,50,60,17,hwnd,(HMENU)0,hInstance,NULL);
g_hWnd[1] = CreateWindow("Button","Entrer",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON,50,80,61,17,hwnd,(HMENU)1,hInstance,NULL);

OldScroll[0] = (WNDPROC) SetWindowLong (g_hWnd[0], GWL_WNDPROC, (LONG) toto) ;
OldScroll[1] = (WNDPROC) SetWindowLong (g_hWnd[1], GWL_WNDPROC, (LONG) tutu) ;
return 0;


case WM_SIZE:
MoveWindow(g_hWnd[0],50,50,60,17,TRUE);
MoveWindow(g_hWnd[1],50,80,60,17,TRUE);
SetFocus (hwnd) ;
return 0 ;

case WM_KEYDOWN:
if( wParam == VK_F1)
MessageBox(hwnd,"Test de la touche F1","Test",MB_OK);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;


}

return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

BOOL InitApplication(HINSTANCE g_hInst)
{
WNDCLASSEX wcx;
static TCHAR szAppName[] = TEXT ("Peanuts") ;

// Fill in the window class structure with parameters
// that describe the main window.

wcx.cbSize = sizeof(wcx); // size of structure
wcx.style = CS_HREDRAW |
CS_VREDRAW; // redraw if size changes
wcx.lpfnWndProc = WndProc; // points to window procedure
wcx.cbClsExtra = 0; // no extra class memory
wcx.cbWndExtra = 0; // no extra window memory
wcx.hInstance = g_hInst; // handle to instance
//wcx.hIcon = LoadIcon(NULL,IDI_APPLICATION); // predefined app. icon
wcx.hIcon = ExtractIcon(g_hInst,"peanuts.ico",0); // file icon
wcx.hCursor = LoadCursor(NULL, IDC_ARROW); // predefined arrow
wcx.hbrBackground = (HBRUSH)GetStockObject(
WHITE_BRUSH); // white background brush
wcx.lpszMenuName = "MainMenu"; // name of menu resource
wcx.lpszClassName = "Test"; // name of window class
wcx.hIconSm = (HICON)LoadImage(g_hInst, // small class icon
MAKEINTRESOURCE(5),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR);

// Register the window class.


return RegisterClassEx(&wcx);


}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
MSG msg;
HWND g_hWnd;

g_hInst = hInstance;

if( !InitApplication(g_hInst) )
{
return 0;
}

g_hWnd = CreateWindow(
"Test", // name of window class
"Essaie", // title-bar string
WS_OVERLAPPEDWINDOW, // top-level window
CW_USEDEFAULT, // default horizontal position
CW_USEDEFAULT, // default vertical position
800, // default width
600, // default height
(HWND) NULL, // no owner window
(HMENU) NULL, // use class menu
g_hInst, // handle to application instance
(LPVOID) NULL); // no window-creation data

if( !g_hWnd )
{
return 0;
}

ShowWindow(g_hWnd, SW_NORMAL);
UpdateWindow(g_hWnd);



while(1)
{
if( PeekMessage(&msg, 0,0,0,PM_REMOVE) )
{
if( msg.message == WM_QUIT )
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
}


return (0);
}

LRESULT CALLBACK toto(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LONG id;
id = GetWindowLong (hwnd, GWL_ID) ;

switch (uMsg)
{
case WM_KEYDOWN :
if (wParam == VK_TAB)
MessageBox(hwnd,"rien","Coucou",MB_OK);
break ;

case WM_SETFOCUS :
//idFocus = id ;
break ;
}

return CallWindowProc (OldScroll[id], hwnd, uMsg, wParam, lParam) ;


}

LRESULT CALLBACK tutu(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int id = GetWindowLong (hwnd, GWL_ID) ;
int tmpId;
short u;
TCHAR szFormat[] = TEXT ("%-16s%04X-%04X %04X-%04X"),
szBuffer[50] ;

switch (uMsg)
{
case WM_COMMAND:

wsprintf (szBuffer, szFormat, TEXT ("WM_COMMAND"), HIWORD (wParam), LOWORD (wParam),
HIWORD (lParam), LOWORD (lParam)) ;
MessageBox(hwnd,szBuffer,"Test",MB_OK);
SetFocus(hwnd);
break;

case WM_KEYDOWN :
if (wParam == VK_TAB)
u = GetKeyState(VK_SHIFT);
if(u<0)
tmpId = -1;
else
tmpId = 1;
tmpId = (tmpId + id)%2;
SetFocus (GetDlgItem (GetParent (hwnd), tmpId)) ;
break ;

case WM_SETFOCUS :
//idFocus = id ;
break ;
}

return CallWindowProc (OldScroll[id] , hwnd, uMsg, wParam, lParam) ;
}
jeudi 25 mars 2004 à 13:47:43 | Re : Gestion des evenements Win32

hilairenicolas


Avec un hook global, ca pourrait te convenir
jeudi 25 mars 2004 à 14:11:35 | Re : Gestion des evenements Win32

zibo3


C'est quoi un hook global ????
jeudi 25 mars 2004 à 14:30:48 | Re : Gestion des evenements Win32

BruNews

Administrateur CodeS-SourceS
Et change la pompe a messages du WinMain:

while(GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg); DispatchMessage(&msg);
}

ciao...
BruNews, Admin CS, MVP Visual C++
jeudi 25 mars 2004 à 14:38:22 | Re : Gestion des evenements Win32

zibo3


J'ai changé la pompe à message par celle que tu me recommande mais la touche Fx ne répond pas quand je suis dans le champ Edit.
Je n'arrive pas à trapper les événement non prévu par l'objet Edit.
jeudi 25 mars 2004 à 14:52:44 | Re : Gestion des evenements Win32

BruNews

Administrateur CodeS-SourceS
Soit tu mets un hook, soit tu charges une table accelerator, soit le plus simple tu verif dans la pompe a messages si est F3 et alors tu le PostMessage sur GetFocus().

ciao...
BruNews, Admin CS, MVP Visual C++
jeudi 25 mars 2004 à 14:56:32 | Re : Gestion des evenements Win32

hilairenicolas



Tu fais un hook sur le clavier dans une dll (voir SetWindowsHookEx dans msdn avec message WH_KEYBOARD)
puis tu fais en sorte qu'il ne hook que la touche F3 sur ton application

Voir à ce sujet la source de Brunews qui fait un hook sur la touche F11 pour iexplore
http://www.cppfrance.com/code.aspx?ID=18202


Cette discussion est classée dans : hwnd, wparam, hinstance, lparam, wcx


Répondre à ce message

Sujets en rapport avec ce message

DialoBox [ par noel70 ] Voici ce que j'ai fait, mais le souci, c'est que je n'ai aucune fenetre qui s'affiche,Lors de la compilation, aucune erreur, je ne sais pas d'ou sa vi Je trouve pas le bon code [ par vah bi ] Bonjour à tous , voilà je débute en c et comme editeur j'ai le visual c++.Je  fais actuellement une application avec l'api de visual c++  mais en lang Comment faire pour re_afficher un dialogue apres "RedrawWindow" API sous DEV cpp [ par LouisJean ] louisjean dev cpp Bonjours a tous!Comment faire pour remontrer le dialogue "Mon_DIALOG" en API wind32 sous DEV interface en c [ par Med2009 ] salut je suis Mohamed un petit développeur en c et qui désire etre le plus grand développeur dans le monde... transcodage arabe anglais [ par elmarokinho ] bonjour, je suis en DUT 2e année ... je dois réaliser un projet pr la mi-mars  ;:realisation d'un logiciel de transcodage anglais/arabe ...<br Hook WH_MOUSE_LL [ par vecchio56 ] Bonjour,J'utilise un hook bas niveau de type WH_MOUSE_LL, et j'ai un problème lorque je cherche a fermer ma fenêtre principale (la souris se bloque). Win32 problème. [ par TeniX ] Salut, Voila j'ai crée de maniere simple une source qui exprime mon problème , je trouve pas la source du problème , enfaite quand les fenêtres sont l pb avec iwebbrowser2 C++ API Win 32 [ par spyto ] Bonjour,Je tourne en rond, je ne vois pas où ça buggue !!!Voilà, j'ai développé un truc en Win32 pur (j'utilise MSVS.NET C++ 2003)J'ai emprunté une so


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,232 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales