How to detect the control text's line number?
The dialog contains the static text control. When intializing the dialog the application sets a custom text to this static text control:
HWND hWnd = Ge开发者_开发百科tDlgItem(IDC_MY_STATIC_TEXT);
::SetWindowText(hWnd, szMyCustomText);
I need to know the number of the lines that the specified text will be broken into and this text width when it is displayed in UI. Could you please share your idea?
This will depend on the font, DPI and other settings. I recommend looking up static text controls which says:
The system displays as much text as it can in the static control and clips whatever does not fit. To calculate an appropriate size for the control, retrieve the font metrics for the text. For more information about fonts and font metrics, see Fonts and Text.
Combined with this post about calculating the size of the resulting text should get you on your way to calculating the text width (and with knowledge of the text height the number of lines).
精彩评论