Code:
#include<windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "Pixel Fun";
RegisterClass(&WndClass);
HWND hWindow;
hWindow = CreateWindow("Pixel Fun","Window",WS_OVERLAPPEDWINDOW,0,0,600,460,NULL,NULL,hInstance,NULL);
UpdateWindow(hWindow);
MSG Message;
while(GetMessage(&Message,NULL,0,0))
DispatchMessage(&Message);
return(Message.wParam);
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
static BYTE Pixel[6][5] = {0,255,0,255,0,0,
255,0,255,0,255,0,
0,255,0,255,0,0,
255,0,255,0,255,0,
0,255,0,255,0,0 };
static HBITMAP hBitmap;
static HDC hdcmem;
switch(uiMessage)
{
case WM_LBUTTONDOWN:
HDC hdc;
hdc = GetDC(hWnd);
hdcmem = CreateCompatibleDC(hdc);
hBitmap = CreateBitmap(6,5,1,8,Pixel);
SelectObject(hdcmem, hBitmap);
RECT rect;
GetClientRect(hWnd, &rect);
int x,y;
for(y=0;y<rect.bottom;y+=5)
for(x=0;x<rect.right;x+=5)
BitBlt(hdc,x,y,5,5,hdcmem,0,0,SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(hdcmem);
ReleaseDC(hWnd, hdc);
return 0;
case WM_RBUTTONDOWN:
hdc = GetDC(hWnd);
hdcmem = CreateCompatibleDC(hdc);
hBitmap = CreateBitmap(5,5,1,8,Pixel);
SelectObject(hdcmem, hBitmap);
GetClientRect(hWnd, &rect);
for(y=0;y<rect.bottom;y+=10)
for(x=0;x<rect.right;x+=10)
StretchBlt(hdc,x,y,10,10,hdcmem,0,0,5,5,SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(hdcmem);
ReleaseDC(hWnd, hdc);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, uiMessage, wParam, lParam);
}
}