滚动条无法按要求工作. [英] scrollbar does not work as required.

查看:96
本文介绍了滚动条无法按要求工作.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

老年人,
我已经成功实现了基于用户输入在运行时启用垂直滚动条的功能.它确实向下滚动,但垂直条滚动时我看不到页面向下滚动.有什么建议.很久以来一直在尝试解决此问题.

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;
	// 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 );
}

推荐答案

您的程序中没有任何滚动代码.您需要捕获影响垂直滚动的各种键和鼠标消息,并调整绘画代码的起点以考虑新位置.有关更多信息,请参见此处.
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.


这篇关于滚动条无法按要求工作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆