Here is how I am creating the window, the loop, and the creation of the DC.
Code:
HWND MainWindow;
...
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
{
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = MainWndProc;
wc.lpszClassName = "TED MainWindow";
wc.lpszMenuName = NULL;
wc.style = 0;
if (!RegisterClass(&wc))
{
MessageBox(NULL, "Error registering window class!", "Error", MB_OK);
return 1;
}
}
if (!CreateWindowEx(0, "TED MainWindow",
"GDI Tile Engine Demo - Main Window",
WS_OVERLAPPED | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance,
NULL))
{
MessageBox(NULL, "Error creating main window!", "Error", MB_OK);
return 1;
}
MSG msg;
HDC hdcMainWin = GetDC(MainWindow);
HBITMAP hbmBall = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1));
while (TRUE)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message != WM_QUIT)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
break;
}
tempX ++;
tempY ++;
graphics.BeginFrame(hdcMainWin);
graphics.TransBlit(hbmBall, tempX, tempY);
graphics.EndFrame();
}
ReleaseDC(MainWindow, hdcMainWin);
return msg.wParam;
}