/********** WinTreeGraph.cpp -> Windows Last Left Threaded Data Tree Graphics This file will hold all the Graphics. ***********/ #include "WinTree.h" // WinTree1.h is 'ifndef' so wont be multipled defind // Draws the gauge that graphically represents the number of tree members left out of the original number. void DrawMembersGauge(int cxChar, int cyChar, int iVertPos, HWND hwnd, TreeData* pTD) { int iNumMemLeft ; HBRUSH hBrush ; RECT rectA; HDC hdc; iNumMemLeft = pTD->FetchCurrentTreeMemberCount( ); SetRect(&rectA, cxChar * 36, cyChar * (27 + iVertPos), cxChar * 88, cyChar * (28 + iVertPos) ); hBrush = CreateSolidBrush( RGB(255,0,0) ); hdc = GetDC(hwnd) ; FillRect(hdc, &rectA, hBrush) ; ReleaseDC(hwnd, hdc) ; DeleteObject(hBrush); hBrush = CreateSolidBrush( RGB(0,0,0) ); FrameRect(hdc, &rectA, hBrush) ; DeleteObject(hBrush); Rectangle(hdc, cxChar * (36 + iNumMemLeft) , cyChar * (27 + iVertPos), cxChar * 88, cyChar * (28 + iVertPos) ); return ; } // This function will get the current system time when a node is removed. // This system time value can then be displayed on the users' interface. // One long string is built up with strcat. The 'if' and 'while's are use to convert day of month, year and time int // values into 'const char*' so strcat can work on them. void PrintTimeStamp(HDC hdc, TreeData* pTD, int& cxChar, int& cyChar, int& cxCaps) { TCHAR *szMonths[12] = {{" January \0"},{" February \0"},{" March \0"},{" April \0"},{" May \0"},{" June \0"},{" July \0"}, {" August \0"},{" September \0"},{" October \0"},{" November \0"},{" December \0"}} ; TCHAR *szDays[7] = {{"Sunday \0"},{"Monday \0"},{"Tuesday \0"},{"Wednesday \0"},{"Thursday \0"},{"Friday \0"},{"Saturday \0"}} ; // Just a bunch of TCHAR buffs. TCHAR szTimeStamp[80] ; // Will hold the built up date/time string. szTimeStamp[0] = NULL ;// TCHAR szTimeStampNumber[6] ; // Will hold the TCHAR convertions of the ushort ints. int iDate ; // Use to hold the ushort ints that are the date values. int iXpoint = cxChar * 36 ; // X position for TextOut. int iYheight = cyChar * 8 ; // Y height of TextOut rectangle. int ii, iy, iTemp; // Use in 'for' and 'while' loops. for(ii=0 ; ii < 6 ; ++ii ) szTimeStampNumber[ii] = NULL ; // To null out. SetTextAlign (hdc, TA_LEFT | TA_TOP) ; // Set text alignment to left of the drawing rectangle. // strcat in day of week to szTimetamp. iDate = (pTD->FetchTimeStampLNR().wDayOfWeek) ; strcat( szTimeStamp, szDays[iDate] ) ; // Now convert day short int to TCHARs and strcat it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wDay ; if(iDate<10) { szTimeStampNumber[0] = '0' ; szTimeStampNumber[1] = iDate + 48 ; // TCAHR #48 = '0' ; } else { szTimeStampNumber[0] = (iDate/10) + 48 ; szTimeStampNumber[1] = (iDate%10) + 48 ; } ; szTimeStampNumber[2] = NULL ; // Put a NULL after the date to end the string. strcat( szTimeStamp, szTimeStampNumber ) ; // cat the date. strcat( szTimeStamp, szMonths[ pTD->FetchTimeStampLNR().wMonth - 1] ) ; // Now cat the month name. // Now convert year short int to TCHARs and strcat it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wYear ; iTemp = iDate ; iy = 1000 ; for( ii = 0; ii < 4; ++ii ) { szTimeStampNumber[ii] = (iTemp / iy) + 48 ; // TCHAR '0' = 48 iTemp -= (iTemp / iy) * iy ; iy /= 10; } ; // Now strcat in the year. strcat( szTimeStamp, szTimeStampNumber ) ; // Now convert hour short int to TCHARs and strcat it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wHour ; if(iDate<10) { szTimeStampNumber[0] = '0' ; szTimeStampNumber[1] = iDate + 48 ; } else { szTimeStampNumber[0] = (iDate/10) + 48 ; szTimeStampNumber[1] = (iDate%10) + 48 ; } ; szTimeStampNumber[2] = NULL ; // Put a NULL at end just like strcat. // Now strcat in the hour. strcat( szTimeStamp, " @ " ) ; strcat( szTimeStamp, szTimeStampNumber ) ; // Now convert minute short int to TCHARs and strcat it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wMinute ; if(iDate<10) { szTimeStampNumber[0] = '0' ; szTimeStampNumber[1] = iDate + 48 ; } else { szTimeStampNumber[0] = (iDate/10) + 48 ; szTimeStampNumber[1] = (iDate%10) + 48 ; } ; szTimeStampNumber[2] = NULL ; // Put a NULL at end just like strcat. // Now strcat in the minutes. strcat( szTimeStamp, ":" ) ; strcat( szTimeStamp, szTimeStampNumber ) ; // Now convert second short int to TCHARs and strcat it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wSecond ; if(iDate<10) { szTimeStampNumber[0] = '0' ; szTimeStampNumber[1] = iDate + 48 ; } else { szTimeStampNumber[0] = (iDate/10) + 48 ; szTimeStampNumber[1] = (iDate%10) + 48 ; } ; szTimeStampNumber[2] = NULL ; // Put a NULL at end just like strcat. // Now strcat in the seconds. strcat( szTimeStamp, ":" ) ; strcat( szTimeStamp, szTimeStampNumber ) ; // Now convert the 1,000ths of a second short int to TCHARs and strcat it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wMilliseconds ; iTemp = iDate ; iy = 1000 ; for( ii = 0; ii < 4; ++ii ) { szTimeStampNumber[ii] = (iTemp / iy) + 48 ; // TCHAR '0' = 48 iTemp -= (iTemp / iy) * iy ; iy /= 10; } ; // Now strcat in the milliseconds. strcat( szTimeStamp, " and " ) ; strcat( szTimeStamp, szTimeStampNumber ) ; strcat( szTimeStamp, " one thousand sec." ) ; // strcat will put in the last NULL. // Now just TextOut the string! TextOut (hdc, iXpoint, iYheight, szTimeStamp, strlen( szTimeStamp ) ); /********************************* I abandon the following just could never get it to line up right. iDate = (pTD->FetchTimeStampLNR().wDayOfWeek) ; TextOut (hdc, (iXpoint = cxChar * 36), iYheight , szDays[iDate], strlen( szDays[iDate] ) ) ; a = 1 ; iXpoint += cxChar * strlen(szDays[iDate]) ; a = 1 ; // A = (B < 0) ? C : D; // Now iXpoint has the starting position of the last rectangle that TextOut drew in. // Use this iXpoint value as part of off set for next X position for TextOut rectangle. iDate = (pTD->FetchTimeStampLNR().wDay) ; a = 1 ; iXpoint += cxCaps * iDate < 10 ? 3 : 4 ; a = 1 ; TextOut (hdc, iXpoint, iYheight, szBuffer, wsprintf( szBuffer, TEXT("%2d"), iDate ) ) ; iXpoint += cxCaps * (iDate < 10 ? 2 : 3) ; iDate = (pTD->FetchTimeStampLNR().wMonth) - 1 ; TextOut (hdc, iXpoint, iYheight , szMonths[iDate], strlen( szMonths[iDate] ) ) ; iDate = (pTD->FetchTimeStampLNR().wYear) ; TextOut (hdc, cxChar * 65, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%3d"), iDate ) ) ; TextOut (hdc, cxChar * 68, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%1s"), "@" ) ) ; iDate = (pTD->FetchTimeStampLNR().wHour) ; TextOut (hdc, cxChar * 71, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%2d"), iDate ) ) ; TextOut (hdc, cxChar * 72, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%1s"), ":" ) ) ; iDate = (pTD->FetchTimeStampLNR().wMinute) ; TextOut (hdc, cxChar * 75, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%3d"), iDate ) ) ; TextOut (hdc, cxChar * 76, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%1s"), ":" ) ) ; iDate = (pTD->FetchTimeStampLNR().wSecond) ; TextOut (hdc, cxChar * 79, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%3d"), iDate ) ) ; TextOut (hdc, cxChar * 83, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%s"), "and" ) ) ; iDate = (pTD->FetchTimeStampLNR().wMilliseconds) ; TextOut (hdc, cxChar * 87, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%3d"), iDate ) ) ; TextOut (hdc, cxChar * 105, iYheight , szBuffer, wsprintf( szBuffer, TEXT("%s"), "one thousand sec." ) ) ; *********************************/ return ; }