Tham khảo tài liệu 'software solution for engineers and scientist episode 7', kỹ thuật - công nghệ, cơ khí - chế tạo máy phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 514 Chapter 20 case WM_PAINT hdc BeginPaint hwnd ps Initialize variables cyScreen cyChar screen row counter startptr TextMsg start position pointe endptr TextMsg end position pointer j 0 length of string i 0 characters since last space Text line display loop ị ị INVARIANT i characters since last space j length of current string startptr pointer to substring start endptr pointer to substring end while startptr if startptr 0x20 if character is space GetTextExtentPoint32 hdc endptr j textsize ASSERT is the current length of the string cxClient is the abscissa of the client area both in logical units Test for line overflow condition. If so adjust substring to preceding space and display if cxClient - 2 cxChar j j - i startptr startptr - i TextOut hdc cxChar cyScreen endptr j cyScreen cyScreen cyChar endptr startptr j 0 End of space character processing. Reset chars-to-previous-space counter whether or not string was displayed i 0 End of processing for any text character Update substring pointer and counters startptr j i End of while loop Display last text substring j j - i TextOut hdc cxChar cyScreen endptr j EndPaint hwnd ps return 0 case WM_DESTROY PostQuitMessage 0 return 0 return DefWindowProc hwnd iMsg wParam lParam Text Display 515 In Figure there are two screen snapshots of the TEX1_DEMO program in the Text Demo No 1 project folder. The first one shows the text line as originally displayed in our system. The second one shows them after the client area has been resized. before resizing after resizing Figure Two Screen Snapshots of the TEX1_DEMO Program Notice that the TEX1_DEMO program uses a variable j to store the total size of the substring see Figure . In C it is valid to subtract two pointers in order to determine the number of elements between them. The code in the TEX1_DEMO program could have calculated the number of elements in the substring by performing pointer subtraction. The DrawText Function Another .