I have written a small C program using win32 functions.
I want to basically enable the line buffering. For ex: when the text reaches to the end of the window, i want to scroll the text to one line above then then print the next line to the end of the window.
Problem: I am able to scroll the text up when i reach to the end of the window but i m unable to see the next lines being printed to the end of the window.
Can you please point out the flaw in my code.
Collapse | Copy Code
// code for your reference //
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
	static      cxChar, cyChar, cxClient, cyClient, iVertPos = 0, iCnt = 0;
	HDC			hdc;
	static		RECT rect;
	static      TCHAR cCh, cScrollFlag = 'N';
	TCHAR		szBuffer[30];
	switch( message )
		case WM_CREATE:
			hdc = GetDC( hwnd );
			GetTextMetrics( hdc, &tm );
			cxChar = tm.tmAveCharWidth;
			cyChar = tm.tmHeight;
			ReleaseDC( hwnd, hdc );
		case WM_SIZE:
			cxClient = LOWORD( lParam );
			cyClient = HIWORD( lParam );
			rect.left   = cxChar;
			rect.right  = cxClient;
			rect.top    = cyChar;
			rect.bottom = cyClient;
			InvalidateRect( hwnd, &rect, TRUE );
		case WM_CHAR:
			cCh = wParam;
			iVertPos = ++iCnt * cyChar;
			if( iVertPos >= cyClient )  // reached to the end of the window //
				cScrollFlag = 'Y';
				ScrollWindow( hwnd, 0, -cyChar, &rect, &rect );
			else                        // did not reach to the end of the window //
				InvalidateRect( hwnd, &rect, FALSE );
				cScrollFlag = 'N';
		case WM_PAINT:
			hdc = BeginPaint( hwnd, &ps );
			wsprintf( szBuffer, TEXT("[%2d] Key pressed: %c, current pos: %d"), iCnt, cCh, iVertPos );
			if( iVertPos )
				if( cScrollFlag == 'Y' )  // if scrolling required //
					TextOut( hdc, cxChar, iVertPos, szBuffer, lstrlen( szBuffer ) );
				else                     // scroll not required //
					TextOut( hdc, cxChar, iVertPos, szBuffer, lstrlen( szBuffer ) );
			EndPaint( hwnd, &ps );
		case WM_DESTROY:
	return DefWindowProc( hwnd, message, wParam, lParam );
Note: I wanted to achieve this using raw Win32 functions but not re-implementing the same using MFC or some other advanced concepts.


Last edited by shabbir; 9Sep2011 at 18:02.. Reason: Code blocks