Here's a neat trick I found that allows you to draw directly to a console window (Only tested under XP). This gives you access to a window using only kernel32 and gdi32 no need to link to user32 at all. The trick is to set the console title to a unique string and then get the HWND to the console using FindWindow. I'm interested in seeing if this works on windows7 because win7 requires you to pump the message queue which adds extra function calls.
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "gdi32.lib")
#undef UNICODE
#undef _UNICODE
#include <windows.h>
const int resx = 256;
const int resy = 256;
int pixel[resx*resy];
int t;
HWND hwnd;
HDC hdc;
RECT rc;
void mainCRTStartup(void)
{
static BITMAPINFO bmi = { sizeof(BITMAPINFOHEADER),0,0,1,32 };
SetConsoleTitle("io");
hwnd = FindWindow(NULL, "io");
if (!hwnd) return;
hdc = GetDC(hwnd);
if (!hdc) return;
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
1,PFD_DRAW_TO_WINDOW|PFD_SUPPORT_GDI|PFD_DOUBLEBUFFER,PFD_TYPE_RGBA,
32,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,PFD_MAIN_PLANE,0,0,0,0 };
static int fmt = ChoosePixelFormat(hdc,&pfd);
if (!fmt) return;
if (!SetPixelFormat(hdc,fmt,&pfd)) return;
while (!GetAsyncKeyState(VK_ESCAPE)) {
for (int y = 0; y < resy; y++) {
for (int x = 0; x < resx; x++) {
pixel[x+y*resx] = (x^y)+t;
}
}
GetClientRect(hwnd, &rc);
bmi.bmiHeader.biWidth = resx;
bmi.bmiHeader.biHeight = resy;
StretchDIBits(hdc,rc.right/2-resx/2,rc.bottom/2-resy/2,resx,resy,
0,0,resx,resy,pixel,&bmi,0,SRCCOPY);
SwapBuffers(hdc);
t++;
}
ReleaseDC(hwnd,hdc);
DestroyWindow(hwnd);
ExitProcess(0);
return;
}
-edit my bad FindWindow requires user32 thought NODEFAULTLIBS was suppose to exclude it apparently it doesn't