Here is some windows code to create a simple window, and draw a square in it.
Code:
#include <windows.h>
LONG CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc;
HBRUSH hOldBrush;
hdc = BeginPaint(hwnd,&ps);
/* Set a color to fill the rectangle in */
hOldBrush = SelectObject(hdc,GetSysColorBrush(1));
/* Draw the rectangle */
Rectangle(hdc,100,80,300,280);
EndPaint(hwnd,&ps);
SelectObject(hdc,hOldBrush);
}
break;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASS wndClass;
BOOL bRet;
MSG msg;
wndClass.style = 0;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "MyClass";
if(!RegisterClass(&wndClass))
{
MessageBox(NULL,"Error registering class","Error",0);
return 0;
}
if(!CreateWindow("MyClass","My Window", WS_VISIBLE | WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,400,400,NULL, NULL,hInstance,0))
{
MessageBox(NULL,"Error creating window","Error",0);
return 0;
}
while((bRet = GetMessage(&msg,NULL,0,0)) != 0)
{
if(bRet == -1)
{
/* Error with GetMessage */
return 0;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}