Problème d'affichage de controles statics lors du redimensionnement de la fenêtre

Bonjour,
j'ai créé une application dont la fenêtre principale contient pleins de controls statics que je crée dynamiquement avec CreateWindowEx.
Dans chaque static, j'affiche une image avec ma fonction DrawPics (seule solution que j'ai trouvé pour afficher des images avec un canal alpha) :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
void DrawPics(HDC hdc,HBITMAP image)
{
    HDC hMemDC=NULL, hTempDC=NULL;
    BLENDFUNCTION bf;
    HBITMAP hBitmapTemp=NULL, hBitmapOld1=NULL, hBitmapOld2=NULL;

    hMemDC = CreateCompatibleDC(hdc);
    hTempDC = CreateCompatibleDC(hdc);

    hBitmapTemp = CreateCompatibleBitmap(hdc, 24, 24);
    hBitmapOld1 = (HBITMAP)SelectObject(hTempDC, hBitmapTemp);

    //while transparency, clear the contents with the source background
    BitBlt(hTempDC, 0, 0, 24, 24, hdc, 0, 0, SRCCOPY);

    hBitmapOld2 = (HBITMAP)SelectObject(hMemDC, image);

    bf.BlendOp = AC_SRC_OVER;
    bf.BlendFlags = 0;
    bf.SourceConstantAlpha = 255;
    bf.AlphaFormat = AC_SRC_ALPHA;

    AlphaBlend(hTempDC, 0, 0, 24, 24, hMemDC, 0, 0, 24, 24, bf);

    //now hTempDC is ready, blt it directly on hdc
    BitBlt(hdc, 0, 0, 24, 24, hTempDC, 0, 0, SRCCOPY);

    SelectObject(hMemDC, hBitmapOld2);
    SelectObject(hTempDC, hBitmapOld1);

    DeleteObject(hBitmapTemp);
    DeleteDC(hTempDC);
    DeleteDC(hMemDC);
}

Tout s'affiche bien sauf pendant le redimensionnement de la fenêtre.
Quand le redimensionnement est en cours, l'affichage des controls statics clignote avec un fond gris jusqu’à la fin du redimensionnement.
Voici ce qui se passe pendant le wm_size :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
        case WM_SIZE:
        {
            if(LOWORD(lParam)>0)
                largeur=LOWORD(lParam);
            if(HIWORD(lParam)>0)
                hauteur=HIWORD(lParam);

            RECT apiRECT;
            GetClientRect(hwnd,&apiRECT);
            hauteurZoneTravail=apiRECT.bottom-apiRECT.top;
            largeurZoneTravail=apiRECT.right-apiRECT.left;

            affichage_items();
        }

voila ce que fait la fonction affichage_items :
1
2
3
4
5
6
7
8
9
10
11
12
13
void affichage_items()
{
    for(unsigned int i=0;i<tab_items.length();i++)
    {
            /*

            ici, le code pour calculer la nouvelle position de chaque item

            */
            tab_items.id(i).change_position(x, y);
    }
    InvalidateRect(mainhwnd, 0, TRUE);
}

j'ai fait une classe qui gère les controls statics et tab_items est un tableau qui contient des objets de cette classe.
Dans affichage_items, je recalcule la position de chaque static pour qu'ils restent centrés dans la fenêtre.
La fonction change_position ne fait que des SetWindowPos sur les statics :
1
2
3
4
5
6
7
8
9
10
11
void item::change_position(int posx,int posy)
{
    x=posx;
    y=posy;
    SetWindowPos(hFond,NULL,-ScrollX+x,-ScrollY+y,0,0,SWP_NOSIZE);
    SetWindowPos(hNom,NULL,-ScrollX+x+35,-ScrollY+y+8,0,0,SWP_NOSIZE);
    SetWindowPos(hDesc,NULL,-ScrollX+x+7,-ScrollY+y+33,0,0,SWP_NOSIZE);
    SetWindowPos(hVersion,NULL,-ScrollX+x+187,-ScrollY+y+35,0,0,SWP_NOSIZE);
    SetWindowPos(hIcone,NULL,-ScrollX+x+6,-ScrollY+y+6,0,0,SWP_NOSIZE);
    SetWindowPos(hPlus,NULL,-ScrollX+x+285,-ScrollY+y+5,0,0,SWP_NOSIZE);
}

l'InvalidateRect de la fonction affichage_items provoque le ré-affichage de chaque control static qui est géré ici :
1
2
3
4
5
6
7
8
9
10
case WM_CTLCOLORSTATIC:
{
	HDC hdcStatic = (HDC) wParam;
	HWND hST = (HWND) lParam;

	for(unsigned int i=0;i<tab_items.length();i++)
		tab_items.id(i).draw(hdcStatic,hST);

	return (INT_PTR) GetStockBrush(NULL_BRUSH);
}

voila ce que fait le draw (utilisation du DrawPics du début):
1
2
3
4
5
6
7
8
9
10
11
void item::draw(HDC hdcStatic,HWND hSTATIC)
{
    if(affiche)
    {
        if(hSTATIC==hIcone)
            DrawPics(hdcStatic,icone);

        if(hSTATIC==hVersion)
            SetTextColor(hdcStatic, RGB(128,0,0));
    }
}

Voila, j'espère que c'est assez clair.
Je voudrais savoir qu'est ce que je fais de mal pour que l'affichage soit mauvais lors du redimensionnement.
Merci pour votre aide.
le problème est le suivant:
InvalidateRect (mainhwnd, 0, TRUE);

le dernier paramètre signifie que le fond sera effacé (rempli avec la couleur de fond). Cela provoque le scintillement
J'ai trouvé la solution :
au lieu de faire appel à affichage_items() dans le WM_SIZE, ce qui change la position de chaque static, je fais simplement un ScrollWindowEx.
Et là, c'est niquel!
Topic archived. No new replies allowed.