Thread sur WndProc

kidpigeyre Messages postés 96 Date d'inscription mardi 3 juillet 2001 Statut Membre Dernière intervention 2 novembre 2006 - 25 mai 2003 à 12:29
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 25 mai 2003 à 13:33
G une fonction WndProc chargé de réaliser tout mon programme (application GUI) (avec fenetre windows) et jmerai pouvoir faire un thread de cette fonction principale lors d'un timer a l'intérieur de cette fonction, comment faire. Voici le format de la fonction WndProc :

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)

C'est elle qui est chargée d'appeler toutes les autres, c'est elle qui contiendra la creation du thread. je n'ai pas possibilité de faire pointer mon createThread sur une otr fct. Cmt faire?

Mci

4 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
25 mai 2003 à 12:36
"faire pointer mon createThread sur une otr fct" ???
Je n'ai pas tout (RIEN) compris.
CreateThread() prend bien un ptr sur une func callback, je cerne pas ton prob.
BruNews, ciao...
0
kidpigeyre Messages postés 96 Date d'inscription mardi 3 juillet 2001 Statut Membre Dernière intervention 2 novembre 2006
25 mai 2003 à 13:20
Jte met ma fonction :

LRESULT CALLBACK
WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
static HPEN h_stylo;
static POINT lppoint;
static POINT lppointo;
static POINT lppointt;
POINT lppointa;
static Cellule *point;
Cellule *temppoint;
static int boucle;
float coef;
int vn;
static int couleurr;
static int couleurv;
static int couleurb;
static COLORREF color;
static int largeur;
static int hauteur;
int i,k;
static int gboucle; ///////////// définition static handle hthread;

switch(iMsg)
{

case WM_CREATE:

point = NULL;
h_stylo=CreatePen(PS_SOLID, 1, RGB(220,0,0));
boucle=0;
gboucle=0;

case WM_SIZE :
largeur=LOWORD(lParam);
hauteur=HIWORD(lParam);
return 0;

case WM_TIMER :
switch(wParam)
{
case IDM_TIMERL :
if (boucle > (nbparticule-1))
{
for(k=0;k<nbgerbe;k++)
{
for(i=0;i<(grosseurpoint*grosseurpoint);i++)
suppression_tete(&point);
}
}
if(boucle<longueurgerbe)
{
insertaff_fin(&point,color);
boucle++;
}
else
{
KillTimer(hwnd, IDM_TIMERL);
SetTimer(hwnd, IDM_TIMERD, degrad, (TIMERPROC) NULL);
}
break;

case IDM_TIMERD :
if(degrade(&point,color)==nbparticule*nbgerbe*grosseurpoint*grosseurpoint)
{
boucle=0;
suppression_tout(&point);
KillTimer(hwnd, IDM_TIMERD);
if(gboucle==1)
{
srand(time(NULL));
largcercle=(rand() % 8)+4;
(lppointo.x)=(rand() % (largeur-20))+10;
(lppointo.y)=(rand() % (hauteur/2))+10;
(lppointt.x)=largeur/2;
(lppointt.y)=hauteur;
(lppoint.x)=(lppointt.x);
(lppoint.y)=(lppointt.y);
couleurr=(rand() % 200) + 50;
couleurv=(rand() % 200) + 50;
couleurb=(rand() % 200) + 50;
color=RGB(couleurr,couleurv,couleurb);
SetTimer(hwnd, IDM_TIMERR, lancement, (TIMERPROC) NULL);
}
}
break;

case IDM_TIMERR :
if((lppointt.y)>(lppointo.y))
{
insert_fin(&point,(lppointt.x),(lppointt.y),RGB(255,255,255));
if((lppointo.x)<(lppoint.x))
{
coef=((lppointo.y)-(lppoint.y))*1.0/((lppointo.x)-(lppoint.x));
if(grosseurpoint*1.0/coef>grosseurpoint)(lppointt.x)-=grosseurpoint/coef;
else (lppointt.x)-=grosseurpoint;
}
else if((lppointo.x)>(lppoint.x))
{
coef=((lppointo.y)-(lppoint.y))*1.0/((lppointo.x)-(lppoint.x));
if(grosseurpoint*1.0/coef>grosseurpoint)(lppointt.x)+=grosseurpoint/coef;
else (lppointt.x)+=grosseurpoint;
}
vn=(lppointo.y)-coef*(lppointo.x);
(lppointt.y)=coef*(lppointt.x)+vn;
if (boucle>nbparticulefusee)
{
for(i=0;i<(grosseurpoint*grosseurpoint);i++)
suppression_tete(&point);
}
boucle++;
}
else
{
suppression_tout(&point);
boucle=0;
(lppoint.x)=(lppointo.x);
(lppoint.y)=(lppointo.y);
creer_cercle(&point,(lppointo.x),(lppointo.y),largcercle,color);////////////////////jvoudrai insérer le hthread=createthread(null,0,wndproc,null,0,null);
sndPlaySound("feu.wav", SND_SYNC);
SetTimer(hwnd, IDM_TIMERL, affichage, (TIMERPROC) NULL);
KillTimer(hwnd, IDM_TIMERR);
}
break;
}
GetClientRect (hwnd, &rect);
InvalidateRect (hwnd, &rect, TRUE);
return 0;

case WM_COMMAND :
switch(wParam)
{
case IDM_LANCER :
srand(time(NULL));
suppression_tout(&point);
largcercle=(rand() % 8)+4;
(lppointo.x)=(rand() % (largeur-20))+10;
(lppointo.y)=(rand() % (hauteur/2))+10;
(lppointt.x)=largeur/2;
(lppointt.y)=hauteur;
(lppoint.x)=(lppointt.x);
(lppoint.y)=(lppointt.y);
couleurr=(rand() % 200) + 50;
couleurv=(rand() % 200) + 50;
couleurb=(rand() % 200) + 50;
color=RGB(couleurr,couleurv,couleurb);
SetTimer(hwnd, IDM_TIMERR, lancement, (TIMERPROC) NULL);
return 0;

case IDM_BOUCLE :
srand(time(NULL));
suppression_tout(&point);
largcercle=(rand() % 8)+4;
(lppointo.x)=(rand() % (largeur-20))+10;
(lppointo.y)=(rand() % (hauteur/2))+10;
(lppointt.x)=largeur/2;
(lppointt.y)=hauteur;
(lppoint.x)=(lppointt.x);
(lppoint.y)=(lppointt.y);
couleurr=(rand() % 200) + 50;
couleurv=(rand() % 200) + 50;
couleurb=(rand() % 200) + 50;
color=RGB(couleurr,couleurv,couleurb);
gboucle=1;
SetTimer(hwnd, IDM_TIMERR, lancement, (TIMERPROC) NULL);
return 0;

case IDM_ARRET :
gboucle=0;
return 0;
case IDM_QUIT :
if((MessageBox( hwnd, "Voulez-vous vraiment quitter?", "Fermeture", MB_OKCANCEL ))==IDOK)
PostQuitMessage (0);
return 0;
}
return 0;

case WM_PAINT :
hdc =BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rect);
SelectObject (hdc, h_stylo);
temppoint=point;
while(point!=NULL)
{
(lppointa.x)=(point->x);
(lppointa.y)=(point->y);
ClientToScreen(hwnd,&lppointa);
SetPixel(hdc,(lppointa.x),(lppointa.y), RGB((point->rouge),(point->vert),(point->bleu)));
point=(point->suiv);
}
point=temppoint;
EndPaint (hwnd, &ps);
return 0;

case WM_CLOSE :
if((MessageBox( hwnd, "Voulez-vous vraiment quitter?", "Fermeture", MB_OKCANCEL ))==IDOK)
PostQuitMessage (0);
return 0;
case WM_DESTROY :
suppression_tout(&point);//////////////et la le closehandle(hthread);
KillTimer(hwnd, IDM_TIMERL);
KillTimer(hwnd, IDM_TIMERR);
KillTimer(hwnd, IDM_TIMERD);
DeleteObject (h_stylo);
PostQuitMessage (0);

return 0;
}
return DefWindowProc( hwnd, iMsg, wParam, lParam);
}
0
kidpigeyre Messages postés 96 Date d'inscription mardi 3 juillet 2001 Statut Membre Dernière intervention 2 novembre 2006
25 mai 2003 à 13:21
Et jaimerai faire cela ms ça marche pas
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
25 mai 2003 à 13:33
hthread=createthread(null,0,wndproc,null,0,null); ???
tu ne vas pas lancer un thread avec ta proc de fenetre comme callback. Donne lui un ptr sur une fonction.
Va voir dans mes sources et autres (kaid etc...) tu y trouveras exemples.
Desole mais pas le temps de corriger un prog entier, je surveille le forum en bossant et + pas possible pour moi.
BruNews, ciao...
0
Rejoignez-nous