1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
case WM_PAINT: // What to paint on the window.
{
PAINTSTRUCT ps; // Our paint structure.
HDC hDC=BeginPaint(hWnd,&ps); // Start paint scene.
// Display the file in the client area of window.
SetBkColor(hDC,pView->Background);
string Space, Text; // String objects.
for(UINT i=0,iRow=10;i<pView->Height;i++,iRow+=18)
{
// If the string is less than the View.FileWidth, add a space.
if(pView->Text[pView->Offset_Y+i].length()<pView->FileWidth)
Space.assign(pView->FileWidth-pView->Text[pView->Offset_Y+i].length(),' ');
// Note: The only reason I add a space is to prevent left overs from the
// previous lines since I am not redrawing the window to prevent flicker.
// The following assign operation takes the string at at the Y offset
// location starting from Offset_X and up to View.Width. This is what
// allows scrolling left and right using Offset_X (^_^)
Text.assign(pView->Text[pView->Offset_Y+i]+Space,pView->Offset_X,pView->Width);
// Note: Text is not the same as View.Text, these two are different!
// Display the data in the client window.
TxtOut(hDC,5,iRow,Text.c_str(),pView->Foreground);
// This helps identify strings that are bigger in width than the
// window view width. A "»" is drawn to tell the user there is more.
if(pView->Text[pView->Offset_Y+i].length()-pView->Offset_X==pView->Width||
pView->Text[pView->Offset_Y+i].length()-pView->Offset_X<=pView->Width||
pView->Text[pView->Offset_Y+i].length()<pView->Width)
// I normally don't use bracket enclosures for a single line of code
// after an "if" statement but since this example already looks intense,
// the brackets help to read the code a bit.
{
TxtOut(hDC,pView->Width+690,iRow," ",RGB(0,0,200));
}
else // Draw the little arrows.
{
TxtOut(hDC,pView->Width+690,iRow,"»",RGB(255,255,0));
}
// Clear the strings.
Space.clear();Text.clear();
}
EndPaint(hWnd,&ps); // End paint scene.
break;
}
|