API编写的滚动条程序SB_PAGEUP和SB_PAGEDOWN不起作用,而且程序结束后,进程如何结束不了
API编写的滚动条程序SB_PAGEUP和SB_PAGEDOWN不起作用,而且程序结束后,进程怎么结束不了?
#define WINVER 0x0500
#include<windows.h>
#include"sysmets.h"
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT message, // 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, // pointer to command line
int nCmdShow // show state of window
)
{
MSG msg;
WNDCLASS wndclass;
HWND hwnd;
static TCHAR szAppName[]=TEXT("sysmet");
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName=szAppName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("窗口注册失败!"),TEXT("错误"),MB_OK);
}
hwnd=CreateWindow(szAppName,TEXT("第二次尝试做"),WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT message, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
int i,y,x,iVertPos,iHorzPos,iPaintBeg,iPaintEnd;
PAINTSTRUCT ps;
TEXTMETRIC tm;
SCROLLINFO si;
static int cxChar,cyChar,cxCaps,cyClient,cxClient,iMaxWidth;
TCHAR szBuffer[10];
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
cxChar=tm.tmAveCharWidth;
cxCaps=(tm.tmPitchAndFamily & 1 ? 3 :2 )*cxChar/2;
cyChar=tm.tmHeight+tm.tmExternalLeading;
ReleaseDC(hwnd,hdc);
iMaxWidth=22*cxCaps+40*cxChar;
return 0;
case WM_SIZE:
cxClient=LOWORD (lParam);
cyClient=HIWORD(wParam);
si.cbSize=sizeof(si);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMin=0;
si.nMax=NUMLINES-1;
si.nPage=cyClient/cyChar;
SetScrollInfo(hwnd,SB_VERT,&si,TRUE);
si.cbSize=sizeof(si);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMax=2+iMaxWidth/cxChar;
si.nMin=0;
si.nPage=cxClient/cxChar;
SetScrollInfo(hwnd,SB_HORZ,&si,TRUE);
return 0;
case WM_VSCROLL:
si.cbSize=sizeof(si);
si.fMask=SIF_ALL;
GetScrollInfo(hwnd,SB_VERT,&si);
iVertPos=si.nPos;
switch(LOWORD(wParam))
{
case SB_TOP:
si.nPos=si.nMin;
break;
case SB_BOTTOM:
si.nPos=si.nMax;
break;
case SB_LINEUP:
si.nPos-=1;
break;
case SB_LINEDOWN:
si.nPos+=1;
break;
case SB_PAGEUP:
si.nPos-=si.nPage;
break;
case SB_PAGEDOWN:
si.nPos+=si.nPage;
break;
case SB_THUMBTRACK:
si.nPos=si.nTrackPos;
break;
default:
break;
}
si.fMask=SIF_POS;
SetScrollInfo(hwnd,SB_VERT,&si,TRUE);
GetScrollInfo(hwnd,SB_VERT,&si);
if(si.nPos!=iVertPos)
{
ScrollWindow(hwnd,0,cyChar*(iVertPos-si.nPos),NULL,NULL);
UpdateWindow(hwnd);
#define WINVER 0x0500
#include<windows.h>
#include"sysmets.h"
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT message, // 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, // pointer to command line
int nCmdShow // show state of window
)
{
MSG msg;
WNDCLASS wndclass;
HWND hwnd;
static TCHAR szAppName[]=TEXT("sysmet");
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName=szAppName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("窗口注册失败!"),TEXT("错误"),MB_OK);
}
hwnd=CreateWindow(szAppName,TEXT("第二次尝试做"),WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT message, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
int i,y,x,iVertPos,iHorzPos,iPaintBeg,iPaintEnd;
PAINTSTRUCT ps;
TEXTMETRIC tm;
SCROLLINFO si;
static int cxChar,cyChar,cxCaps,cyClient,cxClient,iMaxWidth;
TCHAR szBuffer[10];
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
cxChar=tm.tmAveCharWidth;
cxCaps=(tm.tmPitchAndFamily & 1 ? 3 :2 )*cxChar/2;
cyChar=tm.tmHeight+tm.tmExternalLeading;
ReleaseDC(hwnd,hdc);
iMaxWidth=22*cxCaps+40*cxChar;
return 0;
case WM_SIZE:
cxClient=LOWORD (lParam);
cyClient=HIWORD(wParam);
si.cbSize=sizeof(si);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMin=0;
si.nMax=NUMLINES-1;
si.nPage=cyClient/cyChar;
SetScrollInfo(hwnd,SB_VERT,&si,TRUE);
si.cbSize=sizeof(si);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMax=2+iMaxWidth/cxChar;
si.nMin=0;
si.nPage=cxClient/cxChar;
SetScrollInfo(hwnd,SB_HORZ,&si,TRUE);
return 0;
case WM_VSCROLL:
si.cbSize=sizeof(si);
si.fMask=SIF_ALL;
GetScrollInfo(hwnd,SB_VERT,&si);
iVertPos=si.nPos;
switch(LOWORD(wParam))
{
case SB_TOP:
si.nPos=si.nMin;
break;
case SB_BOTTOM:
si.nPos=si.nMax;
break;
case SB_LINEUP:
si.nPos-=1;
break;
case SB_LINEDOWN:
si.nPos+=1;
break;
case SB_PAGEUP:
si.nPos-=si.nPage;
break;
case SB_PAGEDOWN:
si.nPos+=si.nPage;
break;
case SB_THUMBTRACK:
si.nPos=si.nTrackPos;
break;
default:
break;
}
si.fMask=SIF_POS;
SetScrollInfo(hwnd,SB_VERT,&si,TRUE);
GetScrollInfo(hwnd,SB_VERT,&si);
if(si.nPos!=iVertPos)
{
ScrollWindow(hwnd,0,cyChar*(iVertPos-si.nPos),NULL,NULL);
UpdateWindow(hwnd);