为windows32窗体加入滚动条,代码如下:
#include<windows.h>
LRESULT CALLBACK WindowProc(
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
)
{
static TCHAR szAppName[]=TEXT("AppName");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
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("This program requires Windows NT"),szAppName,MB_ICONERROR);
}
hwnd=CreateWindow(
szAppName, // registered class name
TEXT("This is title"), // window name
WS_OVERLAPPEDWINDOW|WS_VSCROLL, // window style
CW_USEDEFAULT, // horizontal position of window
CW_USEDEFAULT, // vertical position of window
CW_USEDEFAULT, // window width
CW_USEDEFAULT, // window height
NULL, // handle to parent or owner window
NULL, // menu handle or child identifier
hInstance, // handle to application instance
NULL // window-creation data
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static int cxClient,cyClient,cxChar,cyChar,iVscrollPos;
HDC hdc;
PAINTSTRUCT ps;
int i=50,j=20;
TCHAR szBuffer[20];
TEXTMETRIC tm;
int numberline=30;
switch(uMsg){
case WM_CREATE:
//hdc=GetDC(hwnd);
//TextOut(hdc,0,0,TEXT("hello,world"),strlen("hello,world"));
//ReleaseDC(hwnd,hdc);
hdc=BeginPaint(hwnd,&ps);
GetTextMetrics(hdc,&tm);
SetScrollRange(hwnd,SB_VERT,0,numberline-1,FALSE);
SetScrollPos(hwnd,SB_VERT,iVscrollPos,TRUE);
cyChar=(tm.tmHeight+tm.tmExternalLeading);
EndPaint(hwnd,&ps);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetTextMetrics(hdc,&tm);
TextOut(hdc,iVscrollPos,iVscrollPos,szBuffer,wsprintf(szBuffer,TEXT("%d"),tm.tmAveCharWidth));//字符宽度
TextOut(hdc,iVscrollPos+30,iVscrollPos+40,szBuffer,wsprintf(szBuffer,TEXT("%d"),tm.tmHeight+tm.tmExternalLeading));//字符长度
EndPaint(hwnd,&ps);
return 0;
#include<windows.h>
L