/* boxbox.c (win32) */ #include #define STEP 3 static char name[] = "BoxBox"; static int xBox1; static int yBox1; static int xBox2; static int yBox2; LRESULT CALLBACK callback(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev,PSTR commandLine,int showCommand) { HWND window; MSG message; WNDCLASSEX winclass; winclass.cbSize = sizeof (winclass); winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = callback; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = instance; winclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL,IDC_ARROW); winclass.lpszMenuName = NULL; winclass.lpszClassName = name; winclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION); winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); RegisterClassEx(&winclass); window = CreateWindow (name,"Boxes in Boxes", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,instance,NULL); ShowWindow(window,showCommand); UpdateWindow (window); while(GetMessage(&message,NULL,0,0)) { TranslateMessage(&message); DispatchMessage(&message); } return(message.wParam); } LRESULT CALLBACK callback(HWND window,UINT messageType, WPARAM wParam,LPARAM lParam) { int x1; int y1; int x2; int y2; HDC hdc; PAINTSTRUCT ps; switch (messageType) { case WM_SIZE: xBox1 = 10; yBox1 = 10; xBox2 = LOWORD(lParam) - 10; yBox2 = HIWORD(lParam) - 10; return(0); case WM_PAINT: hdc = BeginPaint(window,&ps); SetViewportOrgEx(hdc,0,0,NULL); x1 = xBox1; x2 = xBox2; y1 = yBox1; y2 = yBox2; while((x1 < x2) && (y1 < y2)) { MoveToEx(hdc,x1,y1,NULL); LineTo(hdc,x2,y1); LineTo(hdc,x2,y2); LineTo(hdc,x1,y2); LineTo(hdc,x1,y1); x1 += STEP; y1 += STEP; x2 -= STEP; y2 -= STEP; } EndPaint(window,&ps); return(0); case WM_DESTROY: PostQuitMessage(0); return(0); } return(DefWindowProc(window,messageType, wParam,lParam)); }