1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Unable to see text after scrolling Text

Discussion in 'C' started by kiranbhatter, Sep 9, 2011.

  1. kiranbhatter

    kiranbhatter New Member

    Joined:
    Sep 9, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    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:
    // 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;
    	PAINTSTRUCT ps;
    	TEXTMETRIC	tm;
    	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 );
    			break;
     
    		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 );
    			
    			break;
     
    		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';
    			}
    			break;
     
    		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 );
    			break;
     
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    	}
    	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.



    Thanks
     
    Last edited by a moderator: Sep 9, 2011

Share This Page