Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Seniors,
i have successfully implemented enabling vertical scroll bar during the run time based on user input. It does scroll down but i dont see the page scrolling down when the vertical bar is scrolling. Any suggestions. Trying since long time to fix this situation.
C++
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	static int	cxCharWidth, cyCharHeight, cxClient, cyClient;
	static int	ChrCnt, iVertPos;
	int			i;
	HDC			hdc;
	PAINTSTRUCT ps;
	TEXTMETRIC	tm;
	static PMSG pmsg;
	SCROLLINFO	si;
	RECT		rect;
	// temp string //
	TCHAR	szTmp[50];
	// //
	
	switch( message )
	{
		case WM_CREATE:
			// get char width and height //
			hdc = GetDC( hwnd );
			GetTextMetrics( hdc, &tm );
			cxCharWidth  = tm.tmAveCharWidth;
			cyCharHeight = tm.tmHeight;
			ReleaseDC( hwnd, hdc );
			if( pmsg )
				free( pmsg );
			pmsg = malloc( 1000 * sizeof( MSG ) );
			break;

		case WM_SIZE:
			// get the screen size //
			cxClient = LOWORD( lParam );
			cyClient = HIWORD( lParam );
			break;

		case WM_CHAR:
			pmsg[ChrCnt++].wParam = wParam;
			InvalidateRect(hwnd, NULL, TRUE );
			break;

		case WM_PAINT:
			hdc = BeginPaint( hwnd, &ps );
			for( i = 0; i < ChrCnt; i++ )
			{
				wsprintf( szTmp, TEXT("Key pressed %c, times pressed: %2d"), pmsg[i].wParam, i );
				TextOut( hdc, 0, cyCharHeight * i, szTmp, lstrlen( szTmp ) );
			}
			// set vertical scroll bar position //
			si.cbSize = sizeof( si );
			si.fMask  = SIF_POS | SIF_RANGE | SIF_PAGE;
			si.nMin   = 0;
			si.nMax   = ChrCnt - 1;
			si.nPage  = cyClient / cyCharHeight;
			SetScrollInfo( hwnd, SB_VERT, &si, TRUE );
			// //
			EndPaint( hwnd, &ps );
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;
	}
	return DefWindowProc( hwnd, message, wParam, lParam );
}
Posted
Updated 17-Aug-11 0:22am
v2
Comments
Prerak Patel 17-Aug-11 6:23am    
Use code block to highlight the code.
[no name] 17-Aug-11 6:37am    
i am using vc++. Will do it next time but do you have any suggestions for the logic

1 solution

You do not have any scrolling code in your program. You need to capture the various keys and mouse messages that affect vertical scrolling and adjust the start point of your paint code to take account of the new position. See here for further information.
 
Share this answer
 
Comments
[no name] 18-Aug-11 1:29am    
thank you but do you want me to send a message to WM_VSCROLL explicitly through WM_PAINT messaging ? Please suggest.
Richard MacCutchan 18-Aug-11 4:32am    
No, you need to add code to handle the WM_VSCROLL message. Scrolling does not happen by magic, you have to make it happen by writing code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900