Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Scroll Bar

bodhi2016bodhi2016 Member Posts: 50
Guys can you please check out the problem the problem with the scroll bar ,when i am pressing the thumb or the arrow it is working perfectly but when i am clicking between the regions of the arrow and the thumb or pressing page up or page down it is heading in wrong direction.
[code]LRESULT CALLBACK WndProc (HWND hwnd , UINT message, WPARAM wparam, LPARAM lparam)
{
static int cxChar, cxCaps, cyChar, cyClient, iVscrollPos ;
HDC hdc ;
int i, y ;
PAINTSTRUCT ps ;
TCHAR szBuffer[10] ;
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;
ReleaseDC (hwnd,hdc);
SetScrollRange(hwnd,SB_VERT,0,NUMLINES-1,FALSE);
SetScrollPos(hwnd,SB_VERT,iVscrollPos,TRUE);
return 0;
case WM_SIZE:
cyClient=HIWORD(lparam);
case WM_VSCROLL:
// switch (LOWORD (wParam))
switch LOWORD (wparam)
{
case SB_LINEUP:
iVscrollPos -= 1;
break;
case SB_LINEDOWN:
iVscrollPos += 1;
case SB_PAGEUP:
iVscrollPos += cyClient/cyChar;
break;
case SB_PAGEDOWN:
iVscrollPos -= cyClient/cyChar;
case SB_THUMBPOSITION:
iVscrollPos =HIWORD(wparam);
default :
break;
}
iVscrollPos=max(0,min(iVscrollPos,NUMLINES-1));


if (iVscrollPos != GetScrollPos(hwnd,SB_VERT))
{SetScrollPos (hwnd,SB_VERT,iVscrollPos,TRUE);
InvalidateRect(hwnd,NULL,TRUE );
}
return 0;
case WM_KEYDOWN:
switch LOWORD (wparam);
{
case VK_PRIOR:
SendMessage (hwnd, WM_VSCROLL, SB_PAGEUP, 0) ;
break ;
case VK_NEXT:
SendMessage (hwnd, WM_VSCROLL, SB_PAGEDOWN, 0) ;
break ;
}
return 0;
case WM_PAINT:
hdc=BeginPaint (hwnd,&ps);
for(i=0; i<NUMLINES; i++)
{
y=cyChar*(i-iVscrollPos);

TextOut(hdc,0,y,sysmetrics[i].szLabel,
lstrlen(sysmetrics[i].szLabel));
TextOut(hdc,22*cxCaps,y,sysmetrics[i].szDesc,
lstrlen(sysmetrics[i].szDesc));
SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;
TextOut (hdc, 22 * cxCaps + 40 * cxChar, y, szBuffer,
wsprintf (szBuffer, TEXT ("%5d"),
GetSystemMetrics (sysmetrics[i].iIndex))) ;

SetTextAlign (hdc, TA_LEFT | TA_TOP );
}
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
}
return DefWindowProc (hwnd, message, wparam, lparam) ;
}[/code]
I know it is same as in the book by charles petzold
I have attached a whole project of my sysmetrics in a notepad
Thank You.

Comments

  • bodhi2016bodhi2016 Member Posts: 50
    Off topic post removed.

    Please stick to C/C++ related topics on these boards.
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Guys can you please check out the problem the problem with the
    : scroll bar ,when i am pressing the thumb or the arrow it is working
    : perfectly but when i am clicking between the regions of the arrow
    : and the thumb or pressing page up or page down it is heading in
    : wrong direction.
    : [code]: LRESULT CALLBACK WndProc (HWND hwnd , UINT message, WPARAM wparam, LPARAM lparam)
    : {
    : static int cxChar, cxCaps, cyChar, cyClient, iVscrollPos ;
    : HDC hdc ;
    : int i, y ;
    : PAINTSTRUCT ps ;
    : TCHAR szBuffer[10] ;
    : 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;
    : ReleaseDC (hwnd,hdc);
    : SetScrollRange(hwnd,SB_VERT,0,NUMLINES-1,FALSE);
    : SetScrollPos(hwnd,SB_VERT,iVscrollPos,TRUE);
    : return 0;
    : case WM_SIZE:
    : cyClient=HIWORD(lparam);
    [color=Red]Was that your intention to skip to
    WM_VSCROLL every time WM_SIZE is received?[/color]
    : case WM_VSCROLL:
    : // switch (LOWORD (wParam))
    : switch LOWORD (wparam)
    : {
    : case SB_LINEUP:
    : iVscrollPos -= 1;
    : break;
    : case SB_LINEDOWN:
    : iVscrollPos += 1;
    : case SB_PAGEUP:
    : iVscrollPos += cyClient/cyChar;
    : break;
    : case SB_PAGEDOWN:
    : iVscrollPos -= cyClient/cyChar;
    : case SB_THUMBPOSITION:
    : iVscrollPos =HIWORD(wparam);
    : default :
    : break;
    : }
    : iVscrollPos=max(0,min(iVscrollPos,NUMLINES-1));
    :
    :
    : if (iVscrollPos != GetScrollPos(hwnd,SB_VERT))
    : {SetScrollPos (hwnd,SB_VERT,iVscrollPos,TRUE);
    : InvalidateRect(hwnd,NULL,TRUE );
    : }
    : return 0;
    : case WM_KEYDOWN:
    : switch LOWORD (wparam);
    : {
    : case VK_PRIOR:
    : SendMessage (hwnd, WM_VSCROLL, SB_PAGEUP, 0) ;
    : break ;
    : case VK_NEXT:
    : SendMessage (hwnd, WM_VSCROLL, SB_PAGEDOWN, 0) ;
    : break ;
    : }
    : return 0;
    : case WM_PAINT:
    : hdc=BeginPaint (hwnd,&ps);
    : for(i=0; i<NUMLINES; i++)
    : {
    : y=cyChar*(i-iVscrollPos);
    :
    : TextOut(hdc,0,y,sysmetrics[i].szLabel,
    : lstrlen(sysmetrics[i].szLabel));
    : TextOut(hdc,22*cxCaps,y,sysmetrics[i].szDesc,
    : lstrlen(sysmetrics[i].szDesc));
    : SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;
    : TextOut (hdc, 22 * cxCaps + 40 * cxChar, y, szBuffer,
    : wsprintf (szBuffer, TEXT ("%5d"),
    : GetSystemMetrics (sysmetrics[i].iIndex))) ;
    :
    : SetTextAlign (hdc, TA_LEFT | TA_TOP );
    : }
    : EndPaint(hwnd,&ps);
    : return 0;
    : case WM_DESTROY:
    : PostQuitMessage (0);
    : }
    : return DefWindowProc (hwnd, message, wparam, lparam) ;
    : }[/code]:
    : I know it is same as in the book by charles petzold
    : I have attached a whole project of my sysmetrics in a notepad
    : Thank You.
    :
    :
Sign In or Register to comment.