Code:
#include <windows.h>
#include "variables.h"
#define ID_TIMER 101
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Invalidaterect") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
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 (BLACK_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_CREATE:
SetTimer (hwnd, ID_TIMER, 1000, NULL);
break;
case WM_TIMER :
bFlipFlop = !bFlipFlop ;
InvalidateRect (hwnd, &rect1, FALSE) ;
InvalidateRect (hwnd, &rect2, FALSE) ;
InvalidateRect (hwnd, &rect3, FALSE) ;
InvalidateRect (hwnd, &rect4, FALSE) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
paint();
EndPaint(hwnd, &ps);
return 0 ;
case WM_DESTROY:
KillTimer (hwnd, ID_TIMER) ;
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Code:
//variables.h
static BOOL bFlipFlop = FALSE ;
HDC hdc ;
PAINTSTRUCT ps ;
HBRUSH hBrush ;
static int cxClient, cyClient ;
//RECT rect1,rect2,rect3,rect4;
RECT rect1 = {15,15,235,125} ;
POINT arrow1 [7] = {{20, 50},{180, 50},{180, 20},{230, 70},
{180, 120},{180, 90},{20, 90}} ;
RECT rect2 = {cxClient -235, 15, cxClient -15, 125} ;
POINT arrow2 [7] = {{cxClient -230, 70},{cxClient -170, 20},{cxClient -170, 50},{cxClient -25, 50},
{cxClient -25, 90},{cxClient -170, 90},{cxClient -170, 120}} ;
RECT rect3 = {15, cyClient -125, 235, cyClient -15} ;
POINT arrow3 [7] = {{20, cyClient -90},{180, cyClient-90},{180, cyClient-120},
{230, cyClient-70},{180, cyClient-20},
{180, cyClient-50},{20, cyClient-50}} ;
RECT rect4 = {cxClient -235, cyClient -125, cxClient -15, cyClient -15} ;
POINT arrow4 [7] = {{cxClient -230, cyClient -70},{cxClient -170, cyClient -120},
{cxClient -170, cyClient -90}, {cxClient -25, cyClient -90},
{cxClient -25, cyClient -50}, {cxClient -170, cyClient -50},
{cxClient -170, cyClient -20}} ;
void paint()
{
//rectangles
hBrush = CreateSolidBrush (bFlipFlop ? RGB(255,0,0) : RGB(0,0,255)) ;
FillRect (hdc, &rect1, hBrush) ;
hBrush = CreateSolidBrush (bFlipFlop ? RGB(0,0,255) : RGB(255,0,0)) ;
FillRect (hdc, &rect2, hBrush) ;
hBrush = CreateSolidBrush (bFlipFlop ? RGB(0,0,255) : RGB(255,0,0)) ;
FillRect (hdc, &rect3, hBrush) ;
hBrush = CreateSolidBrush (bFlipFlop ? RGB(255,0,0) : RGB(0,0,255)) ;
FillRect (hdc, &rect4, hBrush) ;
//arrows
hBrush = CreateSolidBrush (bFlipFlop ? RGB(0,0,255) : RGB(255,0,0)) ;
SelectObject(hdc, hBrush);
Polygon(hdc, arrow1, 7);
hBrush = CreateSolidBrush (bFlipFlop ? RGB(255,0,0) : RGB(0,0,255)) ;
SelectObject(hdc, hBrush);
Polygon(hdc, arrow2, 7);
hBrush = CreateSolidBrush (bFlipFlop ? RGB(255,0,0) : RGB(0,0,255)) ;
SelectObject(hdc, hBrush);
Polygon(hdc, arrow3, 7);
hBrush = CreateSolidBrush (bFlipFlop ? RGB(0,0,255) : RGB(255,0,0)) ;
SelectObject(hdc, hBrush);
Polygon(hdc, arrow4, 7);
DeleteObject (hBrush) ;
}