Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

carriage return

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm just learning C++ and would like to know How ,in a window ,in which, i have successfully input keystrokes, can i make a carriage return. Here some of my code

/////////////////////////////////////////////////////////////////////////////
// CKeystrokesView message handlers

void CKeystrokesView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CKeystrokesDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->StringData += nChar;
Invalidate();
if (CKeystrokesDoc->StringData ='\r')
{
CRect rect;
GetWindowRect(&rect);
int y = rect.Height() - 1;
}
CView::OnChar(nChar, nRepCnt, nFlags);
}
 
looks like you have a typo:

if (CKeystrokesDoc->StringData = '\r')

should be:

if (CKeystrokesDoc->StringData == '\r')

I don't know MFC so I can't help you too much. However, as to your linebreaks question, the Windows standard for line breaks in text controls (like EDIT and richEdit2.0 and 3.2) is \r\n. That means that if you are manually processing keystrokes, you should probably interpret an input of \r as \r\n (or 13, 10). If you just add \r you won't generally get a linebreak but rather a black bar or a character that looks like a black square with a hollow circle. Likewise, a newline character \n not preceded by a \r will give you a character which looks like a musical note instead of a linebreak. This all doesn't hold true exactly for static controls which seem to process standalone \r as linebreaks for some reason.
If you are processing keyboard input from a win32 message loop be sure to get you're character input with the WM_CHAR message NOT the WM_KEYDOWN (except for virtual keys) and use the TranslateMessage(&msg) call in your message loop so that combination keys will work.
Of course if you are manually drawing the text into the window with whatever the MFC equivalents of TextOut() or DrawText() are, you can use whatever you wan't as long as you process the output accordingly (but it won't look right in other Windows editors).

Hope this helps.
--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top