Code:
#include <windows.h>
HDC MapDC;
HWND hWnd;
const char ClsName[] = "Grid Test";
const char WindowCaption[] = "Grid Test";
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
WNDCLASSEX WndClsEx;
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProc;
WndClsEx.cbClsExtra = NULL;
WndClsEx.cbWndExtra = NULL;
WndClsEx.hInstance = hInstance;
WndClsEx.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClsName;
WndClsEx.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&WndClsEx);
hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
ClsName,
WindowCaption,
WS_OVERLAPPEDWINDOW,
100,
120,
600,
600,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT Ps;
COLORREF Red = RGB(255, 0, 0);
COLORREF Green = RGB(0, 255, 0);
COLORREF Blue = RGB(0 ,0, 255);
COLORREF Yellow = RGB(191, 196, 9);
HPEN RedPen = CreatePen(PS_SOLID, 0, Red);
HPEN GreenPen = CreatePen(PS_SOLID, 0, Green);
HPEN BluePen = CreatePen(PS_SOLID, 0, Blue);
HPEN YellowPen = CreatePen(PS_SOLID, 0, Yellow);
int y = 0;
switch(Msg)
{
case WM_CREATE:
HDC windowDC;
windowDC = GetDC(hWnd);
MapDC = CreateCompatibleDC(windowDC);
SelectObject(MapDC, CreateCompatibleBitmap(windowDC, 310, 310));
return 0;
case WM_PAINT:
hDC = BeginPaint(hWnd, &Ps);
SelectObject(MapDC, YellowPen);
for (double i = 0; i <= 310; i = i + 30.9) {
MoveToEx(MapDC, i, 0, NULL);
LineTo(MapDC, i, 368);
MoveToEx(MapDC, 0, i, NULL);
LineTo(MapDC, 310, i);
}
BitBlt(hDC, 264, 20, 310, 310, MapDC, 0, 0, SRCCOPY);
EndPaint(hWnd, &Ps);
break;
case WM_DESTROY:
DeleteDC(MapDC);
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
//---------------------------------------------------------------------------
This is a quick test I made. Just grab it and drag like crazy for a minute or so. I took out the custom ICON.