我写的滚动列怎么跳回来了。
#include <WINDOWS.H>#define NUMILNES 1000
LRESULT CALLBACK myproc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
){
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=HBRUSH(COLOR_WINDOWTEXT);
wndclass.hCursor=LoadCursor(hInstance,IDC_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=myproc;
wndclass.lpszClassName="winclass";
wndclass.lpszMenuName="NULL";
wndclass.style=CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wndclass);
HWND hwnd=CreateWindow("winclass","myfirst",WS_OVERLAPPEDWINDOW|WS_VSCROLL,0,0,500,500,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK myproc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){
HDC hdc,hDC;
PAINTSTRUCT ps;
int ipos;
switch(uMsg){
case WM_PAINT:
int i;
int x,y;
CHAR xyz[40];
TEXTMETRIC tx;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"hello.",strlen("hello."));
i=GetTextMetrics(hdc,&tx);
x=tx.tmAveCharWidth ;
y=tx.tmHeight + tx.tmExternalLeading ;
TextOut(hdc,0,17,xyz,wsprintf(xyz,"字体的宽是:%d,字体的高是:%d",x,y));
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SIZE:
int xi,yi;
char xyi[40];
hDC=GetDC(hwnd);
xi=LOWORD(lParam);
yi=HIWORD(lParam);
ReleaseDC(hwnd,hDC);
break;
case WM_CREATE:
SetScrollRange(hwnd,SB_VERT,0,NUMILNES-1,FALSE);
SetScrollPos(hwnd,SB_VERT,ipos,TRUE);
break;
case WM_VSCROLL:
switch(LOWORD(wParam)){
case SB_LINEUP:
ipos=-1;
break;
case SB_LINEDOWN:
ipos=+1;
break;
case SB_PAGEUP:
ipos -= yi / y ;
break ;
case SB_PAGEDOWN:
ipos += yi/ y ;
break ;
case SB_THUMBTRACK:
ipos=HIWORD(wParam);
break;
default:
break;
}
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);}
return 0;}
我处理了SB_THUMBTRACK:消息啊。
[ 本帖最后由 々NARUTO 于 2011-12-27 15:34 编辑 ]