SetTimer

palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006 - 30 mars 2005 à 14:20
palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006 - 6 avril 2005 à 10:01
Svp aider moi.

J'utilise la fonction SetTimer, a pparemment je la rempli correctement (pas d'erreur ni a la compilation ni a l'execution). Je me suis appuyer sur un fichier C++ qui utilise deja cette fonction, j'ai lu lpein de sujet et d'exemple sur le forum mais rien ne m'éclaire.

JAMAIS JE N'ARRIVE DANS LE CASE WM_TIMER!!!

Le SetTimer est bien pris en compte mais jamais je ne me retrouve dans le case WM_TIMER ni dans la fonction que j'attache au timer.

Est ce qu'il n'y aurait pas un truc tout bidon que j'aurai oublié????? Pourquoi quand je fais comme dans vos exemples cela ne marche pas mieux???? Est ce une option à la compilation que j'ai oublié????
Merci de me venir en aide sinon je risque de craquer!!!!
A voir également:

15 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
30 mars 2005 à 15:05
rien de particulier à dire sur SetTimer:
dans ton WM_INITDIALOG par exemple:
SetTimer(hdlg, 1, 1000, 0); // event toutes les 1 seconde sur hdlg

dans la windProc:
switch(message) {
case WM_TIMER:
MessageBeep(0);
return 0;
case WM_xxx:
.....
}

ciao...
BruNews, MVP VC++
0
palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006
30 mars 2005 à 18:12
C'est ça le problème c'est que même comme ça, ça ne marche pas.
Il n'y a jamais l'EVENT sur ma hdlg.
Je ne vois vraiment pas ce que ça peu être.
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
31 mars 2005 à 10:55
Tu pourrais pas mettre ton code stp pour qu'on puisse voir si on voit une erreur ???
0
palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006
31 mars 2005 à 13:56
voilà, c'est juste du code pour essayer des fonctions donc pour le moment il ne fait rien de particulier.


Bonne chance pour la relecture!!


// essai5.cpp : Defines the entry point for the application.
//


#include "stdafx.h"
#include "resource.h"
#include "math.h"
#include <windows.h>

#define MAX_LOADSTRING 100
#define TIMER1 11


// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text


// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void fonctionanous(void);
void AffMouse(HWND);
//void TurnCircle(HWND hWnd);
VOID CALLBACK TurnCircle(HWND hWnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime);
VOID CALLBACK EssaiTime(HWND hWnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime);


int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;


// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_ESSAI5, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);


// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}


hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_ESSAI5);


//Notre fonction d'initialisation
//fonctionanous();


// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}


return msg.wParam;
//return 0;
}





//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;


wcex.cbSize = sizeof(WNDCLASSEX);


wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_ESSAI5);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_ESSAI5;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);


return RegisterClassEx(&wcex);
}


//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;


hInst = hInstance; // Store instance handle in our global variable


hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);


if (!hWnd)
{
return FALSE;
}


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


return TRUE;
}


//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{


int wmId, wmEvent;
// PAINTSTRUCT ps;
// HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);


switch (message)
{
case WM_INITDIALOG:
SetTimer(hWnd, 1, 500, NULL);//(TIMERPROC)TurnCircle);
return 1;


case WM_CREATE:
//SetTimer(hWnd, 1, 500, NULL);//(TIMERPROC)TurnCircle);
SetTimer(hWnd, 2, 500, (TIMERPROC)TurnCircle);
//break;
return 0;


case WM_TIMER:
TurnCircle(hWnd,message,1,0);
break;


case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
/* hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
*/ break;
case WM_DESTROY:
//KillTimer(hWnd, 1);
//KillTimer(hWnd, 2);
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
//MessageBox(NULL, "!!! CLIC !!!", "Mon programme", MB_ICONEXCLAMATION);
AffMouse(hWnd);
break;
case WM_MOUSEMOVE:
//TurnCircle(hWnd,message,1,0);
break;


default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}


// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;


case WM_COMMAND: if (LOWORD(wParam) IDOK || LOWORD(wParam) IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}





void fonctionanous(void)
{



}


void AffMouse(HWND hWnd)
{



PAINTSTRUCT ps;
HDC hdc;
RECT rc, rc3;


hdc = BeginPaint (hWnd, &ps); // début du dessin
GetClientRect (hWnd, &rc); // taille de la fenêtre dans rc
// Exemple d'écriture
SetTextColor(hdc, RGB(90,90,90)); // ecrit en gris
TextOut (hdc, 10,10,"Mon 1er exe en C++",18);


///////////////////////////////////////
//écriture des coordonnées de la souris
POINT ptMouse;


GetCursorPos(&ptMouse);
char buf[10];
itoa(ptMouse.x,buf,10);
TextOut (hdc, 10,100,buf,strlen(buf));
itoa(ptMouse.y,buf,10);
TextOut (hdc, 10,120,buf,strlen(buf));
///////////////////////////////////////


itoa(WM_TIMER,buf,10);
TextOut (hdc, 80,120,buf,strlen(buf));


// Exemple de dessin
HPEN hpen = CreatePen(PS_SOLID, 10, RGB(0, 255, 0)); // pinceau
HBRUSH hbrush = CreateSolidBrush(RGB(255, 0, 0)); // brosse
// Selectionne les nouveaux outils et dessine.
SelectObject(hdc, hpen); SelectObject(hdc, hbrush);
int x = rc.right/2;
int y = rc.bottom/2; // centre
// Rectangle(hdc, x-100,y-100, x,y);//rectangle
// Arc(hdc, x-100,y-100,x+100,y+100,x-80,y-60,x-60,y-80);//cercle
hpen = CreatePen(PS_SOLID, 15, RGB(255, 0, 0)); // pinceau
SelectObject(hdc, hpen);
MoveToEx(hdc,x-10,y-10,NULL); LineTo(hdc,x+40,y+40);


/////////////////////////////////////////
//Convertion des coordonnées de la souris
//dans l'écran aux coordonnées dans la
//fenetre
POINT fen=ptMouse;
ScreenToClient(hWnd,&fen);
itoa(fen.x,buf,10);
TextOut (hdc, 10,140,buf,strlen(buf));
itoa(fen.y,buf,10);
TextOut (hdc, 10,160,buf,strlen(buf));
/////////////////////////////////////////


/////////////////////////////
//ligne qui suit la souris
MoveToEx(hdc,x,y,NULL);


LineTo(hdc,fen.x,fen.y);
RECT rc4;
rc4.bottom = x;
rc4.left = fen.x;
rc4.right = y;
rc4.top = fen.y;
InvalidateRect(hWnd, 0, 0);
/////////////////////////////


// Autre exemple d'écriture
RECT rc2={rc.left,rc.top+y+100,rc.right,rc.bottom };
SetTextColor(hdc, RGB(0,0,255)); // ecrit en bleu
DrawText (hdc, "Bienvenue !",
-1, &rc2, DT_SINGLELINE | DT_CENTER | DT_VCENTER);


EndPaint (hWnd, &ps); // fin du dessin


// InvalidateRect(hWnd, 0, 0);


////////////////////////////////
//actualisation du rectangle rc3
rc3.bottom = 140;
rc3.left = 10;
rc3.right = 50;
rc3.top = 100;
InvalidateRect(hWnd, &rc3, 0);
////////////////////////////////
}


//void TurnCircle(HWND hWnd)
VOID CALLBACK TurnCircle(HWND hWnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{



PAINTSTRUCT ps;
HDC hdc;
RECT rc;


hdc = BeginPaint (hWnd, &ps); // début du dessin
GetClientRect (hWnd, &rc); // taille de la fenêtre dans rc



int x = rc.right/2;
int y = rc.bottom/2; // centre


// Exemple de dessin
HPEN hpen2 = CreatePen(PS_SOLID, 0, RGB(255, 255, 255)); // pinceau
HBRUSH hbrush2 = CreateSolidBrush(RGB(255, 255, 255)); // brosse
// Selectionne les nouveaux outils et dessine.
SelectObject(hdc, hpen2); SelectObject(hdc, hbrush2);
Rectangle(hdc, x-105,y-105, x+105,y+105);//rectangle


// Exemple de dessin
HPEN hpen = CreatePen(PS_SOLID, 10, RGB(0, 255, 0)); // pinceau
HBRUSH hbrush = CreateSolidBrush(RGB(255, 0, 0)); // brosse
// Selectionne les nouveaux outils et dessine.
SelectObject(hdc, hpen); SelectObject(hdc, hbrush);


POINT ptMouse;
GetCursorPos(&ptMouse);


POINT fen=ptMouse;
ScreenToClient(hWnd,&fen);
double arg;
arg = atan2(fen.y-y,fen.x-x); // "argument" des coordonnées de la souris
int x1,y1;
x1 = (int)(100 * cos(arg));
y1 = (int)(100 * sin(arg));
Arc(hdc, x-100,y-100,x+100,y+100,x+x1,y+y1,x+100,y);//cercle
// Arc(hdc, x-100,y-100,x+100,y+100,x-80,y-60,x-60,y-80);//cercle
char buf[10];
itoa(x1,buf,10);
TextOut (hdc, 10,100,buf,strlen(buf));
itoa(y1,buf,10);
TextOut (hdc, 10,120,buf,strlen(buf));


/* hpen = CreatePen(PS_SOLID, 15, RGB(255, 0, 0)); // pinceau
SelectObject(hdc, hpen);
MoveToEx(hdc,x,y,NULL); LineTo(hdc,x+x1,y+y1);
*/
/////////////////////////////
EndPaint (hWnd, &ps); // fin du dessin


InvalidateRect(hWnd, 0, 0);



}



VOID CALLBACK EssaiTime(HWND hWnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rc;


hdc = BeginPaint (hWnd, &ps); // début du dessin
GetClientRect (hWnd, &rc); // taille de la fenêtre dans rc



POINT ptMouse;


GetCursorPos(&ptMouse);
char buf[10];
itoa(ptMouse.x,buf,10);
TextOut (hdc, 80,100,buf,strlen(buf));



EndPaint (hWnd, &ps); // fin du dessin


InvalidateRect(hWnd, 0, 0);


}
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
31 mars 2005 à 20:19
WM_INITDIALOG est pour dialogbox, traite seulement WM_CREATE.

ciao...
BruNews, MVP VC++
0
palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006
1 avril 2005 à 09:56
Ok, j'ai enlevé le WM_INITDIALOG, mais ca ne marche pas mieux!!!
J'ai exécuter en mode debugeur, ça passe bien sur l'instruction SetTimer dans le WM_CREATE, mais ça n'arrive jamais dans le WM_TIMER!!!!
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
1 avril 2005 à 11:23
Tu as bien fait ca ou un truc du genre ??



Case WM_CREATE:

SetTimer(hWnd, 1, 500, NULL);

return 0;

Case WM_TIMER:
TurnCircle(hWnd,message,1,0);
break;
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
1 avril 2005 à 11:27
Je viens d y penser

essaye int err = SetTimer(hWnd, 1, 500, NULL); et regarde si la valeur de err est bien differente de zero !!
0
palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006
1 avril 2005 à 17:16
oui ca retourne une valeur différente de zéro (même que ca retourne 1)!!!
ya pas une option spécial pour la compilation ou un truc du genre!!!
moi je désespère
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
1 avril 2005 à 18:56
Non la je voit pas désolé !!

Et perso j'ai jamais vu non plus d options speciale de compilations
pour les timers j'espere que quelqu'un va trouver la solution parce que
ca m interesse aussi !!
0
cs_Tux Messages postés 6 Date d'inscription samedi 4 mai 2002 Statut Membre Dernière intervention 3 avril 2005
2 avril 2005 à 17:53
essai de configurer ton timer comme sa
SetTimer(hWnd, TIMER1, 500, NULL);

_ _
0
palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006
5 avril 2005 à 12:54
Ca ne marche pas mieux!!!
Juste une question pour faire avancer le schimlblik :
Est ce que le fait de faire un projet de type "Hello World" peut etre la cause de l'erreur (genre ca ne marcherai que en MFC)?????
0
palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006
5 avril 2005 à 15:08
Apparement c'est ça. J'ai refait mon projetavec de vrai dialogbox et ca marche très bien.
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
5 avril 2005 à 18:54
??? tu as fait quoi ???

L exemple qu'on t a montré est aussi sans les mfc, c'est quoi que tu appelles une vrai dialogbox ???
0
palenthir Messages postés 11 Date d'inscription mercredi 16 mars 2005 Statut Membre Dernière intervention 16 février 2006
6 avril 2005 à 10:01
Au début j'avais créé un projet (avec VC++) Windows application mais de type "Hello world" donc avec les fenetre blanches. Maintenant j'ai créé un projet Windows application mais de type Empty projet et j'ai inséré moi meme une fenetre de dialogue (une grise). Je ne sais pas si c'est vraiment ca le fond du probleme, mais là au moins ca marche donc je vais bosser là dessus.
0
Rejoignez-nous