codice:
#include <windows.h>
#include <string>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
MSG msg;
HINSTANCE hInst;
HWND form1,scroll1,label21;
SCROLLINFO si ;
char buffer[50];
char buff[5000] = {0};
char buf[70][70];
int nLineMax=0;
bool yTrack=true;
void procedura_thread();
void reg(UINT style,WNDPROC lpfnWndProc,int cbClsExtra,int cbWndExtra,HINSTANCE hInstance,HICON hIcon,HCURSOR hCursor,HBRUSH hbrBackground,LPCTSTR lpszMenuName,LPCTSTR lpszClassName);
LRESULT CALLBACK WinProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow)
{
hInst = hInstance;
reg(CS_HREDRAW | CS_VREDRAW | CS_OWNDC,WinProc,0,0,hInst,LoadIcon(NULL,IDI_WINLOGO),LoadCursor(NULL,IDC_ARROW),(HBRUSH)(COLOR_BTNFACE+0),NULL,"principale");
form1 = CreateWindow("principale","Finestra",WS_MINIMIZEBOX | WS_SIZEBOX | WS_CAPTION | WS_MAXIMIZEBOX | WS_POPUP | WS_SYSMENU,600,300,600,440,NULL,(HMENU)NULL,hInst,NULL);
//label21 = CreateWindow("Edit","",WS_CHILD | ES_LEFT | WS_BORDER | WS_VISIBLE | ES_READONLY | ES_MULTILINE | WS_VSCROLL,1,1,583,203,form1,(HMENU)NULL,hInst,NULL);
ShowWindow(form1,SW_SHOWNORMAL);
UpdateWindow(form1);
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&procedura_thread,NULL,0,NULL);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxChar, cxCaps, cyChar, cxClient, cyClient, iMaxWidth;
HDC hdc ;
int i, x, y, iVertPos, iHorzPos, iPaintBeg, iPaintEnd;
PAINTSTRUCT ps ;
TEXTMETRIC tm ;
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 ;
si.cbSize = sizeof (si) ;
si.fMask = SIF_RANGE;
si.nMin = 0 ;
si.nMax = nLineMax ;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
si.cbSize = sizeof (si) ;
si.fMask = SIF_RANGE;
si.nMin = 0 ;
si.nMax = 2 + iMaxWidth / cxChar ;
SetScrollInfo (hwnd, SB_HORZ, &si, TRUE) ;
ReleaseDC (hwnd, hdc) ;
// Save the width of the three columns
iMaxWidth = 40 * cxChar + 22 * cxCaps ;
break ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
// Set vertical scroll bar range and page size
si.cbSize = sizeof (si) ;
si.fMask = SIF_PAGE ;
si.nPage = cyClient / cyChar ;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
// Set horizontal scroll bar range and page size
si.cbSize = sizeof (si) ;
si.fMask = SIF_PAGE ;
si.nPage = cxClient / cxChar ;
SetScrollInfo (hwnd, SB_HORZ, &si, TRUE) ;
break ;
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_ALL;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
GetScrollInfo (hwnd, SB_VERT, &si) ;
if (si.nPos==(si.nMax-si.nPage)+1){yTrack=true;}else{yTrack=false;}
if (si.nPos != iVertPos)
{
ScrollWindow (hwnd, 0, cyChar * (iVertPos - si.nPos), NULL, NULL) ;
UpdateWindow (hwnd) ;
}
break ;
case WM_HSCROLL:
si.cbSize = sizeof (si) ;
si.fMask = SIF_ALL ;
GetScrollInfo (hwnd, SB_HORZ, &si) ;
iHorzPos = si.nPos ;
switch (LOWORD (wParam))
{
case SB_LINELEFT:
si.nPos -= 1 ;
break ;
case SB_LINERIGHT:
si.nPos += 1 ;
break ;
case SB_PAGELEFT:
si.nPos -= si.nPage ;
break ;
case SB_PAGERIGHT:
si.nPos += si.nPage ;
break ;
case SB_THUMBPOSITION:
si.nPos = si.nTrackPos ;
break ;
default :
break ;
}
si.fMask = SIF_POS ;
SetScrollInfo (hwnd, SB_HORZ, &si, TRUE) ;
GetScrollInfo (hwnd, SB_HORZ, &si) ;
// If the position has changed, scroll the window
if (si.nPos != iHorzPos)
{
ScrollWindow (hwnd, cxChar * (iHorzPos - si.nPos), 0, NULL, NULL) ;
UpdateWindow(hwnd);
}
break ;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
// Get vertical scroll bar position
si.cbSize = sizeof (si) ;
si.fMask = SIF_POS ;
GetScrollInfo (hwnd, SB_VERT, &si) ;
iVertPos = si.nPos ;
// Get horizontal scroll bar position
GetScrollInfo (hwnd, SB_HORZ, &si) ;
iHorzPos = si.nPos ;
// Find painting limits
iPaintBeg = max (0, (int)(iVertPos + ps.rcPaint.top / cyChar)) ;
iPaintEnd = min (nLineMax,(int)(iVertPos + ps.rcPaint.bottom / cyChar)) ;
for (i = iPaintBeg ; i <= iPaintEnd ; i++)
{
x = cxChar * (1 - iHorzPos) ;
y = cyChar * (i - iVertPos) ;
TextOut (hdc, 0, y,buf[i],lstrlen (buf[i])) ;
}
EndPaint (hwnd, &ps) ;
break ;
case WM_DESTROY :
PostQuitMessage (0) ;
break ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
void procedura_thread()
{
char Text[50];
while(nLineMax<60)
{
SetScrollRange(form1, SB_VERT, 0, nLineMax,FALSE);
si.fMask = SIF_ALL;
GetScrollInfo (form1, SB_VERT, &si);
if (yTrack){SetScrollPos(form1, SB_VERT, (si.nMax-si.nPage)+1,FALSE);}
SendMessage(form1,WM_SIZE,0,0);
UpdateWindow(form1);
sprintf(Text,"%d Prova purova prova prova", nLineMax);
strcpy(buf[nLineMax],Text);
Sleep(700);
nLineMax++;
}
}
void reg(UINT style,WNDPROC lpfnWndProc,int cbClsExtra,int cbWndExtra,HINSTANCE hInstance,HICON hIcon,HCURSOR hCursor,HBRUSH hbrBackground,LPCTSTR lpszMenuName,LPCTSTR lpszClassName)
{
WNDCLASS wc;
wc.style = style;
wc.lpfnWndProc = lpfnWndProc;
wc.cbClsExtra = cbClsExtra;
wc.cbWndExtra = cbWndExtra;
wc.hInstance = hInstance;
wc.hIcon = hIcon;
wc.hCursor = hCursor;
wc.hbrBackground = hbrBackground;
wc.lpszMenuName = lpszMenuName;
wc.lpszClassName = lpszClassName;
RegisterClass(&wc);
}