Code:
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
TEXTMETRIC TextMetrics;
static int CharWidth,CharHeight,CharCaps;
static int ClientX,ClientY;
char Buffer[20];
static SCROLLINFO si;
static int iVscrollPos;
static int iHscrollPos;
static Client Cliente;
RECT Rect ;
switch (message)
{
case WM_SIZE:
{
ClientX = LOWORD (lParam) ;
ClientY = HIWORD (lParam) ;
// Set vertical scroll bar range and page size
si.cbSize = sizeof (si) ;
si.fMask = SIF_ALL|SIF_DISABLENOSCROLL ;
si.nMin = 0 ;
si.nMax = NUMLINES - 1 ;
si.nPage = NUMLINES-5 ;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_SAVE:
if(SaveClientInfo(NewClientWindowHandle)!=Success)
{
MessageBox(hwnd,"did not save right","asflkasfdlkdf!!!",MB_OK);
}
break;
case ID_NEW:
NewClientWindowHandle = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_DIALOGNEW), hwnd, ClienteProc);
ShowWindow(NewClientWindowHandle,SW_SHOW);
GetClientRect(hwnd,&Rect);
InvalidateRect(hwnd,&Rect,TRUE);
break;
case ID_PRINT:
//MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
Print=TRUE;
break;
case ID_PAGARENOSHOW:
ViewPagare=FALSE;
InvalidateRect(hwnd,NULL,TRUE);
break;
case ID_COPYRIGHT:
DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG1),hwnd, CopyRightNotice) ;
break;
case ID_EXIT:
SendMessage (hwnd, WM_CLOSE, 0, 0) ;
break ;
}
case WM_CREATE:
{
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&TextMetrics);
CharWidth=TextMetrics.tmAveCharWidth;
CharHeight=TextMetrics.tmHeight+TextMetrics.tmExternalLeading;
CharCaps=(TextMetrics.tmPitchAndFamily & 1 ? 3 : 2) * CharWidth / 2 ;
si.cbSize = sizeof (si) ;
si.fMask = SIF_RANGE | SIF_PAGE|SIF_DISABLENOSCROLL ;
si.nMin = 0 ;
si.nMax = NUMLINES - 1 ;
si.nPage = NUMLINES-5 ;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
ReleaseDC(hwnd,hdc);
AddToolBar(hwnd,IDC_TOOLBAR);
//initialize the save as and open dialog structure
SaveDialog(hwnd);
return 0;
}
case WM_PAINT:
{
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect(hwnd,&Rect);
FillRect(hdc,&Rect,WHITE_BRUSH);
if (ViewPagare)
{
/* Get the current scroll bar information
Initialize the beginning of the line */
si.cbSize=sizeof si;
si.fMask=SIF_ALL;
GetScrollInfo(hwnd,SB_VERT,&si);
int Line;
int Position;
Position=si.nPos;
/* We multiply by negative one to make sure
that we paint the line at the oposite of where the
scroll bar is going and the line is displayed at a ratio of
CharHeight meaning that it will increment one line of text
at the time or CharHeight*/
Line=(Position*-1)*CharHeight;
Line+=60;//to make sure the text is not displayed
//directly at the top of the window.
int i;
for (i=0;i<NUMLINES;i++)
//displaying pagare on the screen
{
char string[]="hi";
TextOut(hdc,20,Line,PagareLines[i].Array,lstrlen(PagareLines[i].Array));
Line+=15;
SetTextAlign(hdc,TA_LEFT);
SetBkMode(hdc, TRANSPARENT);
}
}
//print pagare
//if Print has been se to true print pagare
if(Print)
{
PrintingState=PrintPagare(hwnd,Print);
Print=PrintingState;
}
EndPaint (hwnd, &ps) ;
return 0 ;
}
case WM_VSCROLL:
// Get all the vertical scroll bar information
si.cbSize = sizeof (si) ;
si.fMask = SIF_ALL ;
iVscrollPos=si.nPos;
GetScrollInfo (hwnd, SB_VERT, &si) ;
switch (LOWORD (wParam))
{
case SB_LINEUP:
iVscrollPos -=1;
break ;
case SB_LINEDOWN:
iVscrollPos +=1;
break;
}
si.nPos=iVscrollPos;
si.fMask = SIF_POS ;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
GetScrollInfo (hwnd, SB_VERT, &si) ;
//scroll our window by one text line
//and call InvalidateRect
ScrollWindowEx(hwnd,NULL,CharHeight*(si.nPos-iVscrollPos),NULL,NULL,NULL,NULL,SW_ERASE);
UpdateWindow (hwnd) ;
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}