Animer un graphisme

GreatNeo Messages postés 13 Date d'inscription mercredi 18 décembre 2002 Statut Membre Dernière intervention 23 avril 2007 - 22 mars 2003 à 13:40
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 22 mars 2003 à 14:02
Je crée par exemple une ligne. Est-il possible de la déplacer ? faut-il la transformer en bitmap ? (si oui quelle est la fonction pour le faire ?)
Je voudrai savoir aussi comment faire pour garder le contenu paint dans une fenêtre, c'est-à-dire que celui-ci ne s'efface pas quand on passe une autre fenêtre par dessus ou qu'on la réduit/agrandi ?
Merci d'avance.

1 réponse

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
22 mars 2003 à 14:02
Exemple complet pour 1ere question:
#include <windows.h>

HINSTANCE hInst;
HWND m_hBand;
RECT rct;

int posX, posY;
int heightFnt;
HBITMAP hbmp;
HDC memDc;
char *szAppName "Bandeau", *szBand "bndCls";
char *szMail = "Auteur: BruNews - Email: bnutiles@wanadoo.fr";

LRESULT CALLBACK BandWndProc(HWND hwnd, UINT mssg, WPARAM wParam, LPARAM lParam)
{
switch(mssg) {
case WM_CREATE:
{
TEXTMETRIC tm;
SIZE size;
HDC hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm); heightFnt = tm.tmHeight;
int len = strlen(szMail);
memDc = CreateCompatibleDC(hdc);
GetTextExtentPoint32(hdc, szMail, len, &size);
GetClientRect(hwnd, &rct);
size.cx += 50;
if(rct.right < size.cx) rct.right = size.cx;
hbmp = CreateCompatibleBitmap(hdc, rct.right, rct.bottom);
SelectObject(memDc, hbmp);
SelectObject(memDc, GetStockObject(LTGRAY_BRUSH));
PatBlt(memDc, 0, 0, rct.right, rct.bottom, PATCOPY);
posY = rct.bottom / 2 - heightFnt / 2;
SetBkMode(memDc, TRANSPARENT);
TextOut(memDc, 20, posY, szMail, len);
ReleaseDC(hwnd, hdc);
InvalidateRect(hwnd, 0, 1);
SetTimer(hwnd, 1, 20, 0);
}
return 0;
case WM_TIMER:
{
int tmaxX = rct.right - 1;
BitBlt(memDc, tmaxX, posY, 1, heightFnt, memDc, 0, posY, SRCCOPY);
BitBlt(memDc, 0, posY, tmaxX, heightFnt, memDc, 1, posY, SRCCOPY);
InvalidateRect(hwnd, &rct, 0);
}
return 0;
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
BitBlt(hdc, ps.rcPaint.left, ps.rcPaint.top,
ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top,
memDc, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);
EndPaint(hwnd, &ps);
}
return 0;
case WM_DESTROY:
KillTimer(hwnd, 1);
DeleteDC(memDc);
return 0;
}
return DefWindowProc(hwnd, mssg, wParam, lParam);
}

LRESULT CALLBACK AppWndProc(HWND hwnd, UINT mssg, WPARAM wParam, LPARAM lParam)
{
switch(mssg) {
case WM_SIZE:
rct.bottom = HIWORD(lParam) / 2;
m_hBand = CreateWindow(szBand, 0, WS_CHILDWINDOW | WS_VISIBLE,
0, rct.bottom / 2, LOWORD(lParam), rct.bottom,
hwnd, 0, hInst, NULL);
return 0;
case WM_SYSCOMMAND:
if((wParam==SC_SCREENSAVE)) return 0; // interdit SCREENSAVE
break;
case WM_CHAR:
if(wParam == VK_ESCAPE) PostMessage(hwnd, WM_CLOSE, 0, 0l);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, mssg, wParam, lParam);
}

HWND PrepareWndApp()
{
WNDCLASSEX wclsx;
wclsx.cbSize = sizeof(WNDCLASSEX);
wclsx.style = CS_HREDRAW | CS_VREDRAW;
wclsx.hCursor = LoadCursor(NULL, IDC_ARROW);
wclsx.hInstance = hInst; wclsx.cbClsExtra wclsx.cbWndExtra 0; wclsx.hIconSm 0; wclsx.lpszMenuName 0;
wclsx.hIcon = LoadIcon(hInst, szAppName);
wclsx.lpfnWndProc = AppWndProc;
wclsx.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wclsx.lpszClassName = szAppName;
if(!RegisterClassEx(&wclsx)) goto errWndApp;
wclsx.hIcon = 0;
wclsx.style = CS_HREDRAW | CS_VREDRAW;
wclsx.lpfnWndProc = BandWndProc;
wclsx.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
wclsx.lpszClassName = szBand;
if(!RegisterClassEx(&wclsx)) goto errWndApp;
return CreateWindowEx(0, szAppName, szAppName,
WS_OVERLAPPED | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInst, NULL);
errWndApp:
MessageBox(NULL, "ERREUR", szAppName, MB_ICONERROR); return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
MSG msg;
HWND hwApp;
hInst = hInstance;
if(!(hwApp = PrepareWndApp())) return 0;
ShowWindow(hwApp, SW_SHOW); UpdateWindow(hwApp);
while(GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
tu peux recompiler. Tu auras un bandeau texte deroulant et permanent sans scintillement.
2) Si WM_PAINT traite comme il se doit l'affichage n'est pas altere par deplacement.
BruNews, ciao...
0
Rejoignez-nous