[API] Changement de Background
Bonjour, je commence depuis peu avec l'API Win32 et je voudrai changer le background de ma fenêtre pendant l'exécution de mon programme, parce que je sais qu'on peut s'en occuper lors de la création de la fenêtre :
Code:
1 2
| WNDCLASS wc;
wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE); |
Par exemple...
J'ai vu aussi le message WM_ERASEBKGND, mais j'ai pas très bien saisi son rôle, j'aimerais bien avoir quelques explications... merci :)
Re: [API] Changement de Background
Citation:
Envoyé par Taron31
J'ai vu aussi le message WM_ERASEBKGND, mais j'ai pas très bien saisi son rôle, j'aimerais bien avoir quelques explications... merci :)
Avant de faire ce genre de chose il faut bien piger ( et dieu sait si c'est un peu complexe) l'architecture d'une application Windows, la boucle de messages d'une fenêtre.
Pour traiter WM_ERASEBKGND il suffit de traiter ce message avec un case WM_ERASEBKGND.....break et placer le code correspondant
Citation:
WM_ERASEBKGND
The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting.
A window receives this message through its WindowProc function.
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_ERASEBKGND
WPARAM wParam, // handle to device context (HDC)
LPARAM lParam // not used
);
Parameters
wParam
Handle to the device context.
lParam
This parameter is not used.
Return Values
An application should return nonzero if it erases the background; otherwise, it should return zero.
Remarks
The DefWindowProc function erases the background by using the class background brush specified by the hbrBackground member of the WNDCLASS structure. If hbrBackground is NULL, the application should process the WM_ERASEBKGND message and erase the background.
An application should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If the application returns zero, the window will remain marked for erasing. (Typically, this indicates that the fErase member of the PAINTSTRUCT structure will be TRUE.)
:wink:
Re: [API] Changement de Background
Citation:
Envoyé par mat.M
Citation:
Envoyé par Taron31
J'ai vu aussi le message WM_ERASEBKGND, mais j'ai pas très bien saisi son rôle, j'aimerais bien avoir quelques explications... merci :)
Avant de faire ce genre de chose il faut bien piger ( et dieu sait si c'est un peu complexe) l'architecture d'une application Windows, la boucle de messages d'une fenêtre.
Pour traiter WM_ERASEBKGND il suffit de traiter ce message avec un case WM_ERASEBKGND.....break et placer le code correspondant
Je sais comment ça fonctionne merci, j'ai du mal m'exprimer...
Je voulais juste savoir si on utilisait SetBkColor() dans le message WM_ERASEBKGND, donc à chaque fois que le background de la fenêtre est redessiné par Windows ?