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.
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;
TCHAR szTmp[50];
switch( message )
{
case WM_CREATE:
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:
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 ) );
}
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 );
}