A mam jeszcze jeden problem co zrobic aby ta kontrolka nie miglaa od ciaglego przerysowywanie??
oto jej kod:
#include "control.h"
ATOM RegisterGolControl( HINSTANCE hInstance)
{
WNDCLASSEX wincl;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hInstance = hInstance;
wincl.lpszClassName = "GOL";
wincl.lpfnWndProc = GOLControlProcedure;
wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
wincl.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
wincl.style = 0;
wincl.hIcon = NULL;
wincl.hIconSm = NULL;
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
return RegisterClassEx(&wincl);
};
//X i Y to miejsce gdzie maja byc narysowane kwadraty :)
inline void DrawRectangle( HWND hwnd, int X, int Y, HBRUSH hBrush)
{
RECT rect;
SetRect( &rect, X + 1, Y + 1, X + CellSize.x - 1, Y + CellSize.y - 1 );
HDC hDc = GetDC( hwnd );
X += CellSize.x -15;
Y += CellSize.y -15;
Rectangle(hDc,X,Y,X+CellSize.x,Y+CellSize.y);
FillRect( hDc, &rect, hBrush );
ReleaseDC( hwnd, hDc );
};
void CreateDrawStructure( void )
{
DrawPoint.x = 0;
DrawPoint.y = 0;
CellSize.x = 15;
CellSize.y = 15;
HBRUSH hbrush;
DrawTable.resize(40);
for( int i = 0; i < 40; i++)
{
hbrush = CreateSolidBrush( RGB( 255, 255, 255) );
DrawTable.resize(40, hbrush);
}
};
inline void DrawGrid(HWND hwnd, int left, int top, int right, int bottom)
{
static RECT rect;
bool TooWidth = true,//zmienna ktore maja informowac czy wszystkie
TooHeight = true;//komorki zmieszcza sie na planczy
// najpierw oblicze ile pol moze byc narysowane
//sprawdzam czy wszystkie pola moga byc narysowane
//najpierw szerokosc
// if( CellSize.x * DrawTable.size() > right - left )
// TooWidth = false;
//potem wysokosc
// if( CellSize.y * DrawTable[0].size() > right - left )
// TooHeight = false;
//teraz mozemy to narysowa
SetWindowPos( hwnd, HWND_TOP, left, top, right-left-20, bottom-top-50, SWP_NOMOVE);
for( int i = 0; i < DrawTable.size(); i++)
for( int j = 0; j < DrawTable[0].size(); j++)
{
if( i*CellSize.x >= right - left -20) TooWidth = false;
if( j+CellSize.y >= bottom - top -50) TooHeight = false;
if( TooWidth && TooHeight) DrawRectangle( hwnd, i*14, j*14, DrawTable[j] );
}
};
LRESULT CALLBACK GOLControlProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static RECT rect;
switch (message)
{
case WM_CREATE:
CreateDrawStructure();
break;
case WM_PAINT:
DrawGrid( hwnd, LOWORD(wParam), HIWORD(wParam), LOWORD(lParam), HIWORD(lParam) );
break;
case WM_COMMAND:
MessageBox( NULL, "Tekst", "Tyul", MB_OK);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam) ;
break;
}
return 0;
};
#include "control.h"
ATOM RegisterGolControl( HINSTANCE hInstance)
{
WNDCLASSEX wincl;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hInstance = hInstance;
wincl.lpszClassName = "GOL";
wincl.lpfnWndProc = GOLControlProcedure;
wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
wincl.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
wincl.style = 0;
wincl.hIcon = NULL;
wincl.hIconSm = NULL;
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
return RegisterClassEx(&wincl);
};
//X i Y to miejsce gdzie maja byc narysowane kwadraty :)
inline void DrawRectangle( HWND hwnd, int X, int Y, HBRUSH hBrush)
{
RECT rect;
SetRect( &rect, X + 1, Y + 1, X + CellSize.x - 1, Y + CellSize.y - 1 );
HDC hDc = GetDC( hwnd );
X += CellSize.x -15;
Y += CellSize.y -15;
Rectangle(hDc,X,Y,X+CellSize.x,Y+CellSize.y);
FillRect( hDc, &rect, hBrush );
ReleaseDC( hwnd, hDc );
};
void CreateDrawStructure( void )
{
DrawPoint.x = 0;
DrawPoint.y = 0;
CellSize.x = 15;
CellSize.y = 15;
HBRUSH hbrush;
DrawTable.resize(40);
for( int i = 0; i < 40; i++)
{
hbrush = CreateSolidBrush( RGB( 255, 255, 255) );
DrawTable.resize(40, hbrush);
}
};
inline void DrawGrid(HWND hwnd, int left, int top, int right, int bottom)
{
static RECT rect;
bool TooWidth = true,//zmienna ktore maja informowac czy wszystkie
TooHeight = true;//komorki zmieszcza sie na planczy
// najpierw oblicze ile pol moze byc narysowane
//sprawdzam czy wszystkie pola moga byc narysowane
//najpierw szerokosc
// if( CellSize.x * DrawTable.size() > right - left )
// TooWidth = false;
//potem wysokosc
// if( CellSize.y * DrawTable[0].size() > right - left )
// TooHeight = false;
//teraz mozemy to narysowa
SetWindowPos( hwnd, HWND_TOP, left, top, right-left-20, bottom-top-50, SWP_NOMOVE);
for( int i = 0; i < DrawTable.size(); i++)
for( int j = 0; j < DrawTable[0].size(); j++)
{
if( i*CellSize.x >= right - left -20) TooWidth = false;
if( j+CellSize.y >= bottom - top -50) TooHeight = false;
if( TooWidth && TooHeight) DrawRectangle( hwnd, i*14, j*14, DrawTable[j] );
}
};
LRESULT CALLBACK GOLControlProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static RECT rect;
switch (message)
{
case WM_CREATE:
CreateDrawStructure();
break;
case WM_PAINT:
DrawGrid( hwnd, LOWORD(wParam), HIWORD(wParam), LOWORD(lParam), HIWORD(lParam) );
break;
case WM_COMMAND:
MessageBox( NULL, "Tekst", "Tyul", MB_OK);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam) ;
break;
}
return 0;
};