3rd Tuesday of the month. 7:30PM - C/C++ Group, SPRS
Welcome to the C++ Users Group. This group is a "Special Interest Group" of the ACGNJ devoted to discussing programming languages in general and C, C++, and C++ for Windows programming in particular. Each month a small but hopefully useful program (complete with source code) is presented for discussion.
Object of the Disk Free Space Program: To present a small utility which draws a Pie Chart showing the free space on the main hard drive, usually "C:". It demonstrates a new system of graphic programming objects introduced by Microsoft called "GDIPLUS", or "GDI+".At the meeting on Tuesday night we will be discussing the utility and the source code.
SAMPLE CODE =========== void CPie1Dlg::DrawResults(HDC hdc) { RECT rr; GetClientRect(&rr); Graphics graphics(hdc); // Create a SolidBrush object. SolidBrush blackBrush(Color(255, 0, 0, 0)); SolidBrush greyBrush(Color(255, 224, 224, 224)); SolidBrush usedBrush(Color(255, 0, 0, 0)); if (fPercentUsed >= 95.) usedBrush.SetColor(Color(255, 255, 0, 0)); // red else if (fPercentUsed >= 75.) usedBrush.SetColor(Color(255, 255, 192, 0)); // yellow else usedBrush.SetColor(Color(255, 0, 255, 0)); // green // Create a Pen object. Pen blackPen(Color(255, 0, 0, 0), 3); blackPen.SetDashStyle(DashStyleDot); // Make it dotted instead of solid. // Define the pie. Rect ellipseRect(0, 0, rr.right, rr.bottom); ellipseRect.Inflate(-3,-3); REAL startAngle = 0.0f; REAL sweepAngle = 3.6f * (100.0f - fPercentUsed); // Draw the pie. graphics.FillPie(&greyBrush, ellipseRect, startAngle, sweepAngle); graphics.FillPie(&usedBrush, ellipseRect, sweepAngle, 360 - sweepAngle); graphics.DrawPie(&blackPen, ellipseRect, startAngle, sweepAngle); graphics.DrawPie(&blackPen, ellipseRect, sweepAngle, 360 - sweepAngle); // Create a string. char text[256]; sprintf(text, "FREE\n%.1f%%\n%s\n%ld MB", 100.0-fPercentUsed, sTargetDrive.GetBuffer(100), ulFreeMegs); WCHAR freetext[256]; // convert string to wide-characters ZeroMemory(freetext, sizeof(freetext)); mbstowcs(freetext, text, strlen(text)); // Initialize arguments and then draw string inside box. REAL x, y, width, height; x = (float) (3*rr.right)/4; y = (float) rr.bottom/2; width = (float) (rr.right - x); height = (float)(rr.bottom - y); RectF layoutRect(x, y, width, height); // rectangle defines boundary of string. Font myFont(L"Arial", 16, FontStyleBold); // define font. StringFormat format; format.SetAlignment(StringAlignmentNear); // align it near the x,y origin. // Draw string. graphics.DrawString(freetext, -1, &myFont, layoutRect, &format, &blackBrush); }