[Dev-C++] Control Bar problems in Win32
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Richard P. E. <ev...@ma...> - 2001-02-20 03:08:58
|
I am studying from a book titled "Windows 98 Programming from the Ground
Up" by Herbert Schildt and seem to be running into an unusual problem. I
have entered the source code for the scroll bar examples and they work when
compiled but not totally. When I grab the slider in the horizontal scroll
bar it will move to where I want it and my position readout registered the
movement but when I release the mouse button it snaps back to the zero
position. Also, when I do a control scroll bar, in this case a vertical
one, I can not drag the slider with the mouse. If I click on the down
arrowed button the position readout registers movement but the slider just
sits there and "blinks". I can't find any mistakes in my code as I typed it
but maybe some one else has experienced similar problems and can tell me
what they found to solve these problems. I have included the portions of
the resource file and source code where these are entered.
Can some one help? Thanks.
Richard P. Evans
from the resource file:
MyDB DIALOG 18, 18, 142, 92
CAPTION "Adding a Control Scroll Bar"
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
| WS_VSCROLL | WS_HSCROLL
{
GROUPBOX "Slider Positions", ID_GB1, 2, 2, 100, 60
SCROLLBAR ID_SB1, 110, 10, 10, 70, SBS_VERT | WS_TABSTOP
}
from my source code:
/* Dialog Function */
BOOL CALLBACK DialogFunc(HWND hdwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
char str[255];
static int vpos = 0; /* vertical slider box position */
static int hpos = 0; /* horizontasl slider box position */
static int cntlpos = 0; /* control slider box position */
static SCROLLINFO si; /* scroll bar info structure */
HDC hdc;
PAINTSTRUCT paintstruct;
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hdwnd, 0);
return 1;
}
break;
case WM_INITDIALOG:
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_RANGE;
si.nMin = 0; si.nMax = VERTRANGEMAX;
/* set range of standard vertical scroll bar */
SetScrollInfo(hdwnd, SB_VERT, &si, 1);
/* set range of scroll bar control */
SetScrollInfo(GetDlgItem(hdwnd, ID_SB1), SB_CTL, &si, 1);
si.nMax = HORZRANGEMAX;
/* set range of standard horizontal scroll bar */
SetScrollInfo(hdwnd, SB_HORZ, &si, 1);
vpos = hpos = 0;
return 1;
case WM_PAINT:
hdc = BeginPaint(hdwnd, &paintstruct);
sprintf(str, "Vertical: %d", vpos);
TextOut(hdc, 20, 30, str, strlen(str));
sprintf(str, "Horizontal: %d", hpos);
TextOut(hdc, 20, 60, str, strlen(str));
sprintf(str, "Scroll Bar Control: %d ", cntlpos);
TextOut(hdc, 20, 90, str, strlen(str));
EndPaint(hdwnd, &paintstruct);
return 1;
case WM_VSCROLL:
/* Now we must determine whether the control
scroll bar or the standard scroll bar generated
the message. */
switch(LOWORD(wParam))
{
case SB_LINEDOWN:
if ((HWND)lParam == GetDlgItem(hdwnd, ID_SB1))
{
/* is control scroll bar */
cntlpos++;
if(cntlpos>VERTRANGEMAX) cntlpos = VERTRANGEMAX;
}
else /* is window scroll bar */
{
vpos++;
if(vpos>VERTRANGEMAX) vpos = VERTRANGEMAX;
}
break;
case SB_LINEUP:
if((HWND)lParam == GetDlgItem(hdwnd, ID_SB1))
{
/* is control bar scroll */
cntlpos--;
if(cntlpos<0) cntlpos = 0;
}
else
{
/* is window scroll bar */
vpos--;
if(vpos<0) vpos = 0;
}
break;
case SB_THUMBPOSITION:
if((HWND)lParam == GetDlgItem(hdwnd, ID_SB1))
{
/* is control scroll bar */
cntlpos = HIWORD(wParam); /* get current position */
}
else
{
/* is window scroll bar */
vpos = HIWORD(wParam); /* get current position */
}
break;
case SB_THUMBTRACK:
if((HWND)lParam == GetDlgItem(hdwnd, ID_SB1))
{
/* is control scroll bar */
cntlpos = HIWORD(wParam); /* get current position */
}
else
{
/* is window scroll bar */
vpos = HIWORD(wParam); /* get current position */
}
break;
case SB_PAGEDOWN:
if((HWND)lParam == GetDlgItem(hdwnd, ID_SB1))
{
/* is control scroll bar */
cntlpos += 5;
if(cntlpos>VERTRANGEMAX) cntlpos = VERTRANGEMAX;
}
else
{
/* is window scroll bar */
vpos += 5;
if(vpos>VERTRANGEMAX) vpos = VERTRANGEMAX;
}
break;
case SB_PAGEUP:
if((HWND)lParam == GetDlgItem(hdwnd, ID_SB1))
{
/* is control scroll bar */
cntlpos -= 5;
if(cntlpos<0) cntlpos = 0;
}
else
{
/* is window scroll bar */
vpos -= 5;
if(vpos<0) vpos = 0;
}
break;
}
if((HWND)lParam == GetDlgItem(hdwnd, ID_SB1))
{
/* update standard scroll bar position */
si.fMask = SIF_POS;
si.nPos = vpos;
SetScrollInfo(hdwnd, SB_VERT, &si, 1);
hdc = GetDC(hdwnd);
sprintf(str, "Scroll Bar Control: %d ", cntlpos);
TextOut(hdc, 20, 90, str, strlen(str));
ReleaseDC(hdwnd, hdc);
}
else
{
/* update standard scroll bar position */
si.fMask = SIF_POS;
si.nPos = vpos;
SetScrollInfo(hdwnd, SB_VERT, &si, 1);
hdc = GetDC(hdwnd);
sprintf(str, "Vertical: %d ", vpos);
TextOut(hdc, 20, 30, str, strlen(str));
ReleaseDC(hdwnd, hdc);
}
return 1;
case WM_HSCROLL:
switch(LOWORD(wParam))
{
/* Try adding the other event handling code
for the horizontal scroll bar here. */
case SB_LINERIGHT:
hpos++;
if(hpos>HORZRANGEMAX) hpos = HORZRANGEMAX;
break;
case SB_LINELEFT:
hpos--;
if(hpos<0) hpos = 0;
}
/* update horizontal bar position */
si.fMask = SIF_POS;
si.nPos = hpos;
SetScrollInfo(hdwnd, SB_HORZ, &si, 1);
hdc = GetDC(hdwnd);
sprintf(str, "Horizontal: %d ", hpos);
TextOut(hdc, 20, 60, str, strlen(str));
ReleaseDC(hdwnd, hdc);
return 1;
}
return 0;
}
|