1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include "windows.h"
#define SIZE 20
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
struct size_char
{
int x,y,capx;
};
struct size
{
int x,y;
};
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SysMets3") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_VREDRAW ;
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 = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("error!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Get System Metrics No. 3"),
WS_OVERLAPPEDWINDOW | WS_VSCROLL ,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
TEXTMETRIC main_ziti;//Storage system font size
size_char size_char;
size windowssize;
int i,VscollPos;
char name[SIZE][20]={"12","34","56","ly0516","C++","@","hi!","hellow windows!","?","!"};
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
SCROLLINFO set;
int start;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE://Window initialization
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&main_ziti);//Get font size
ReleaseDC(hwnd,hdc);
size_char.y=main_ziti.tmHeight+main_ziti.tmExternalLeading;//Characters height (relative height + baseline level)
ReleaseDC(hwnd,hdc);
return 0;//Exit message handling
case WM_SIZE://Window size change
windowssize.x=LOWORD(lParam);
windowssize.y=HIWORD(lParam);//Store window size
set.cbSize=sizeof(set);
set.fMask=SIF_RANGE|SIF_PAGE;//Set pattern
set.nMax=SIZE*size_char.y,set.nMin=0;//Set the maximum and minimum values
set.nPage=windowssize.y;
SetScrollInfo(hwnd,SB_VERT,&set,1);
return 0;
case WM_VSCROLL:
set.cbSize=sizeof(set);
set.fMask=SIF_ALL;
GetScrollInfo(hwnd,SB_VERT,&set);
start=set.nPos;
switch(LOWORD(wParam))
{
case SB_TOP:
set.nPos=0;break;
case SB_BOTTOM:
set.nPos=set.nMax;break;
case SB_LINEUP:
set.nPos=set.nPos-(size_char.y)/2;break;
case SB_LINEDOWN:
set.nPos=set.nPos+(size_char.y)/2;break;
case SB_PAGEUP:
set.nPos=set.nPos-(size_char.y)/2;break;
case SB_PAGEDOWN:
set.nPos=set.nPos+(size_char.y)/2;break;
case SB_THUMBTRACK:
set.nPos=set.nTrackPos;break;
default:
break;
}
set.fMask=SIF_POS;
SetScrollInfo(hwnd,SB_VERT,&set,1);
GetScrollInfo(hwnd,SB_VERT,&set);
ScrollWindow(hwnd,0,size_char.y*(start-set.nPos),0,0);
UpdateWindow(hwnd);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
set.cbSize=sizeof(set);
set.fMask=SIF_POS;
GetScrollInfo(hwnd,SB_VERT,&set);//Get the scroll bar position
SetTextAlign(hdc,TA_LEFT|TA_TOP);
for(i=set.nPos/size_char.y;i<(set.nPos+windowssize.y)/size_char.y+1&&i<SIZE;i++)
TextOut(hdc,0,(i*(size_char.y))-set.nPos,name[i],lstrlen(name[i]));
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
|