/********** 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(0,0,0) ); hdc = GetDC(hwnd) ; FillRect(hdc, &rectA, hBrush) ; ReleaseDC(hwnd, hdc) ; DeleteObject(hBrush); SetRect(&rectA, cxChar * 36, cyChar * (27 + iVertPos), cxChar * (36+iNumMemLeft), cyChar * (28 + iVertPos) ); hBrush = CreateSolidBrush( RGB(255,0,0) ); hdc = GetDC(hwnd) ; FillRect(hdc, &rectA, hBrush) ; ReleaseDC(hwnd, hdc) ; DeleteObject(hBrush); /*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 wcscat_s. The 'if' and 'while's are use to convert day of month, year and time int // values into 'const char*' so wcscat_s can work on them. void PrintTimeStamp(HDC hdc, TreeData* pTD, int& cxChar, int& cyChar, int& cxCaps) { TCHAR *szMonths[12] = {{L" January \0"},{L" February \0"},{L" March \0"},{L" April \0"},{L" May \0"},{L" June \0"},{L" July \0"}, {L" August \0"},{L" September \0"},{L" October \0"},{L" November \0"},{L" December \0"}} ; TCHAR *szDays[7] = {{L"Sunday \0"},{L"Monday \0"},{L"Tuesday \0"},{L"Wednesday \0"},{L"Thursday \0"},{L"Friday \0"},{L"Saturday \0"}} ; // Just a bunch of TCHAR buffs. TCHAR szTimeStamp[256] ; // Will hold the built up date/time string. szTimeStamp[0] = NULL ;// TCHAR szTimeStampNumber[128] ; // 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. // wcscat_s in day of week to szTimetamp. iDate = (pTD->FetchTimeStampLNR().wDayOfWeek) ; wcscat_s( szTimeStamp, szDays[iDate] ) ; // Now convert day short int to TCHARs and wcscat_s 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. wcscat_s( szTimeStamp, szTimeStampNumber ) ; // cat the date. wcscat_s( szTimeStamp, szMonths[ pTD->FetchTimeStampLNR().wMonth - 1] ) ; // Now cat the month name. // Now convert year short int to TCHARs and wcscat_s 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 wcscat_s in the year. wcscat_s( szTimeStamp, szTimeStampNumber ) ; // Now convert hour short int to TCHARs and wcscat_s it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wHour ; if(iDate<10) { szTimeStampNumber[0] = L'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 wcscat_s. // Now wcscat_s in the hour. wcscat_s( szTimeStamp, L" @ " ) ; wcscat_s( szTimeStamp, szTimeStampNumber ) ; // Now convert minute short int to TCHARs and wcscat_s it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wMinute ; if(iDate<10) { szTimeStampNumber[0] = L'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 wcscat_s. // Now wcscat_s in the minutes. wcscat_s( szTimeStamp, L":" ) ; wcscat_s( szTimeStamp, szTimeStampNumber ) ; // Now convert second short int to TCHARs and wcscat_s it into szTimeStamp. iDate = pTD->FetchTimeStampLNR().wSecond ; if(iDate<10) { szTimeStampNumber[0] = L'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 wcscat_s. // Now wcscat_s in the seconds. wcscat_s( szTimeStamp, L":" ) ; wcscat_s( szTimeStamp, szTimeStampNumber ) ; // Now convert the 1,000ths of a second short int to TCHARs and wcscat_s 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 wcscat_s in the milliseconds. wcscat_s( szTimeStamp, L" and " ) ; wcscat_s( szTimeStamp, szTimeStampNumber ) ; wcscat_s( szTimeStamp, L" one thousand sec." ) ; // wcscat_s will put in the last NULL. // Now just TextOut the string! TextOut (hdc, iXpoint, iYheight, szTimeStamp, wcslen( 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 ; }