- //************************************************************
- #include <windows.h>
- #include <commctrl.h>
- #include <string.h>
- #include <stdio.h>
- //************************************************************
- LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
- //************************************************************
-
- int WINAPI WinMain(
- HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- PSTR szCmdLine,
- int iCmdShow
- )
- {
- static char szAppName[] = "TIMER et DEGRADE";
- HWND hwnd;
- MSG msg;
- WNDCLASSEX wndclass;
-
- wndclass.cbSize = sizeof(wndclass);
- wndclass.style = 0;
- wndclass.lpfnWndProc = WndProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
- wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
- wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = szAppName;
- wndclass.hIconSm = NULL;
-
- RegisterClassEx(&wndclass);
-
- hwnd = CreateWindow ( szAppName, // nom de la classe
- szAppName, // titre de la fenetre
- WS_OVERLAPPEDWINDOW, // style de la fenetre
- CW_USEDEFAULT, // position initiale en x
- CW_USEDEFAULT, // position initiale en y
- CW_USEDEFAULT, // largeur initiale
- CW_USEDEFAULT, // hauteur initiale
- NULL, // handle de la fenetre mere
- NULL, // handle du menu de la fenetre
- hInstance, // handle de l'instance
- NULL) ; // parametres de creation
-
- ShowWindow(hwnd,iCmdShow);
- UpdateWindow(hwnd);
-
- while(GetMessage(&msg,NULL,0,0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- //************************************************************
- LRESULT CALLBACK WndProc(
- HWND hwnd,
- UINT iMsg,
- WPARAM wParam,
- LPARAM lParam
- )
- {
- static int colorRed,colorGreen,colorBlue;
-
- switch (iMsg)
- {
- case WM_CREATE:
- {
- colorRed = 0;
- colorGreen = 0;
- colorBlue = 0;
- SetTimer(hwnd,1001,100,NULL);
- return 0;
- }
- case WM_PAINT:
- {
- HDC hdc;
- PAINTSTRUCT ps;
- RECT rc;
- HGDIOBJ oldBrush;
-
- hdc = BeginPaint(hwnd,&ps);
- GetClientRect(hwnd,&rc);
-
- oldBrush = SelectObject(hdc,CreateSolidBrush(RGB(colorRed,colorGreen,colorBlue)));
-
- Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
-
- DeleteObject(SelectObject(hdc,oldBrush));
- EndPaint(hwnd,&ps);
- return 0;
- }
- case WM_TIMER:
- {
- switch(wParam)
- {
- case 1001:
- {
- colorBlue = (colorBlue + 3) & 255;
- colorGreen = (colorGreen + 5) & 255;
- colorBlue = (colorBlue + 7) & 255;
- InvalidateRect(hwnd,NULL,FALSE);
- return 0;
- }
- }
- break;
- }
- // -------------------------------------
- case WM_DESTROY:
- {
- KillTimer(hwnd,1001);
- PostQuitMessage(0);
- return 0;
- }
- }
- return DefWindowProc(hwnd,iMsg,wParam,lParam);
- }
//************************************************************
#include <windows.h>
#include <commctrl.h>
#include <string.h>
#include <stdio.h>
//************************************************************
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
//************************************************************
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow
)
{
static char szAppName[] = "TIMER et DEGRADE";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = NULL;
RegisterClassEx(&wndclass);
hwnd = CreateWindow ( szAppName, // nom de la classe
szAppName, // titre de la fenetre
WS_OVERLAPPEDWINDOW, // style de la fenetre
CW_USEDEFAULT, // position initiale en x
CW_USEDEFAULT, // position initiale en y
CW_USEDEFAULT, // largeur initiale
CW_USEDEFAULT, // hauteur initiale
NULL, // handle de la fenetre mere
NULL, // handle du menu de la fenetre
hInstance, // handle de l'instance
NULL) ; // parametres de creation
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//************************************************************
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT iMsg,
WPARAM wParam,
LPARAM lParam
)
{
static int colorRed,colorGreen,colorBlue;
switch (iMsg)
{
case WM_CREATE:
{
colorRed = 0;
colorGreen = 0;
colorBlue = 0;
SetTimer(hwnd,1001,100,NULL);
return 0;
}
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
HGDIOBJ oldBrush;
hdc = BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rc);
oldBrush = SelectObject(hdc,CreateSolidBrush(RGB(colorRed,colorGreen,colorBlue)));
Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
DeleteObject(SelectObject(hdc,oldBrush));
EndPaint(hwnd,&ps);
return 0;
}
case WM_TIMER:
{
switch(wParam)
{
case 1001:
{
colorBlue = (colorBlue + 3) & 255;
colorGreen = (colorGreen + 5) & 255;
colorBlue = (colorBlue + 7) & 255;
InvalidateRect(hwnd,NULL,FALSE);
return 0;
}
}
break;
}
// -------------------------------------
case WM_DESTROY:
{
KillTimer(hwnd,1001);
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}