帮忙调试个程序啊,有源码
#include <windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE yY,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szWndClassName[]=TEXT("yy");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground= CreateSolidBrush ( RGB(212,208,200) ) ;
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szWndClassName;
if(!RegisterClass(&wndclass)){
MessageBox(NULL,TEXT("This program requires Windows NT!"),szWndClassName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szWndClassName,
TEXT("ScrollWindow()函数"),
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
300,
300,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while( GetMessage(&msg,NULL,0,0) ){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
static RECT rectScroll;
rectScroll.left=50;
rectScroll.top=50;
rectScroll.right=220;
static RECT clipRectScroll;
TCHAR text[1000];
static LOGFONT lf; static HFONT hFont; static int cxText, cyText ;
switch(message){
case WM_CREATE:
//字体:
lf.lfWeight=FW_LIGHT;
lf.lfCharSet=GB2312_CHARSET;
lf.lfHeight=13;
hFont=CreateFontIndirect(&lf);
hdc=GetDC(hwnd);
SelectObject (hdc, GetStockObject(NULL_BRUSH));
SelectObject(hdc,hFont);
SetBkMode (hdc, TRANSPARENT) ;
TEXTMETRIC tm ;
GetTextMetrics (hdc, &tm) ;
cxText=tm.tmAveCharWidth ;cyText=tm.tmHeight ;//+ tm.tmExternalLeading ;
rectScroll.bottom=rectScroll.top+12*cyText;
clipRectScroll.top=rectScroll.top+3*cyText;
clipRectScroll.bottom=rectScroll.top+9*cyText;
clipRectScroll.left=rectScroll.left+2*cxText;
clipRectScroll.right=rectScroll.right-2*cxText;
ReleaseDC(hwnd,hdc);
return 0;
case WM_KEYUP:
//ScrollWindow (hwnd, 0, -cyText, &rectScroll ,&clipRectScroll) ;//测试一
//ScrollWindow (hwnd, 0, -cyText, &rectScroll ,0) ;//测试二
ScrollWindow (hwnd, 0, -cyText, &rectScroll ,&rectScroll) ;//测试三
return 0 ;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
static int tt,xx,yy,zz;//ScrollWindow的确产生了WM_PAINT消息!
TextOut(hdc,0,0,text,wsprintf (text, TEXT ("BOOL ScrollWindow( //tt:%d次"),++tt) );
TextOut(hdc,0,cyText,text,wsprintf (text, TEXT (" HWND hWnd,int XAmount,int YAmount," ) ) );
TextOut(hdc,0,2*cyText,text,wsprintf (text, TEXT (" const RECT *lpRect,const RECT *lpClipRect" ) ) );
TextOut(hdc,0,3*cyText,text,wsprintf (text, TEXT (");" ) ) );
Rectangle(hdc,rectScroll.left-1 , rectScroll.top-1, rectScroll.right+1, rectScroll.bottom+1) ;
Rectangle(hdc,clipRectScroll.left-1,clipRectScroll.top-1,clipRectScroll.right+1,clipRectScroll.bottom+1) ;
DrawText (hdc, text, wsprintf (text, TEXT ("
111111111111 222222222222222222222222
333333333333333333333333
444444444444444444444444
555555555555555555555555
666666666666666666666666
777777777777777777777777
888888888888888888888888
999999999999999999999999
10 10 10 10 10 10 10 10
11 11 11 11 11 11 xx:%d次
12 12 12 12 12 12 yy:%d次
测试三:lpRect是外框,lpClipRect是外框
任意键测试滚动效果 zz:%d次"),++xx,++yy,++zz),
&rectScroll,DT_NOCLIP);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
DeleteObject (hFont);
return 0;
}
return DefWindowProc(hwnd,message,wParam, lParam) ;
}