Mouse and keyboard do not work together
I have a dialog window (it is a child window). This dialog window has a vertical scrollbar. It should be possible to handle the scrollbar by mouse clicks as well as keyboard input (up-arrow, down-arrow, page-up, page-down, home, end). The dialog window also has at its end the default pushbutton "OK". It should be possible that the window is closed in case the OK pushbutton is clicked with the mouse. But this is exactly the problem. What I understood is that I need the SetFocus(BezugDialog) so that all my keyboard inputs are considered. But with the SetFocus(...) it is no more possible to click on the OK pushbutton with the mouse - clicking on OK doesn't have any effect at all. On the other hand, without the SetFocus(...) I can click on the scrollbar and on the OK pushbutton and it works fine - but no keyboard input is considered for the scrollbar.
What I want is that the scrollbar works with mouse clicks and with keyboard input and that I can close the window by clicking on OK with the mouse.
Can anybody help, please? This is the code of the dialog window. Thanks!!! Ciao, Tabler. :confused:
Code:
=========================================================
BOOL FAR PASCAL AbkuerzungsFunktion (HWND BezugDialog , UINT message ,
WPARAM wParam , LPARAM lParam)
{
static const int Zeilenhoehe = 16 ;
static RECT rect ;
SetFocus (BezugDialog) ;
switch (message)
{
case WM_INITDIALOG :
{
SCROLLINFO siScrollInfo ;
rect.left = 0 ;
rect.top = 0 ;
rect.right = LOWORD(lParam) - 0 ;
rect.bottom = HIWORD(lParam) ;
siScrollInfo .cbSize = sizeof (siScrollInfo) ;
siScrollInfo .fMask = SIF_RANGE | SIF_PAGE ;
siScrollInfo .nMin = 0 ;
siScrollInfo .nMax = 25 ;
siScrollInfo .nPage = 12 ;
SetScrollInfo (BezugDialog , SB_VERT , &siScrollInfo , TRUE) ;
break ;
}
case WM_COMMAND :
switch (wParam)
{
case IDOK :
EndDialog (BezugDialog , 0) ;
break ;
case IDCANCEL :
EndDialog (BezugDialog , 0) ;
break ;
}
case WM_VSCROLL :
{
SCROLLINFO siScrollInfo ;
int iPosition ;
siScrollInfo .cbSize = sizeof(siScrollInfo) ;
siScrollInfo .fMask = SIF_ALL ;
GetScrollInfo (BezugDialog , SB_VERT , &siScrollInfo) ;
iPosition = siScrollInfo .nPos ;
switch (LOWORD(wParam))
{
case SB_TOP :
siScrollInfo .nPos = siScrollInfo.nMin;
ScrollWindow (BezugDialog , 0 , Zeilenhoehe*(iPosition - siScrollInfo.nPos) , NULL , NULL) ;
break ;
case SB_BOTTOM :
siScrollInfo .nPos = siScrollInfo.nMax + 1 - siScrollInfo.nPage;
ScrollWindow (BezugDialog , 0 , Zeilenhoehe*(iPosition - siScrollInfo.nPos) , NULL , NULL) ;
break ;
case SB_LINEUP :
if (siScrollInfo .nPos > 0)
{
siScrollInfo .nPos -= 1 ;
ScrollWindow (BezugDialog , 0 , Zeilenhoehe , NULL , NULL) ;
}
break ;
case SB_LINEDOWN :
if (siScrollInfo .nPos < (siScrollInfo .nMax + 1 - siScrollInfo .nPage) )
{
siScrollInfo.nPos += 1 ;
ScrollWindow (BezugDialog , 0 , -Zeilenhoehe , NULL , NULL) ;
}
break ;
case SB_PAGEUP :
if (siScrollInfo .nPos >= siScrollInfo .nPage )
{
siScrollInfo .nPos -= siScrollInfo .nPage ;
ScrollWindow (BezugDialog , 0 , (siScrollInfo .nPage * Zeilenhoehe) , NULL , NULL) ;
}
else
{
ScrollWindow (BezugDialog , 0 , (siScrollInfo .nPos * Zeilenhoehe) , NULL , NULL) ;
siScrollInfo .nPos = siScrollInfo .nMin ;
}
break ;
case SB_PAGEDOWN :
if (siScrollInfo .nPos < (siScrollInfo .nMax + 1 - 2 * siScrollInfo .nPage) )
{
siScrollInfo .nPos += siScrollInfo .nPage ;
ScrollWindow (BezugDialog , 0 , (-siScrollInfo .nPage * Zeilenhoehe) , NULL , NULL) ;
}
else
{
ScrollWindow (BezugDialog , 0 , (-(siScrollInfo .nMax + 1 - siScrollInfo .nPage - siScrollInfo .nPos) * Zeilenhoehe) , NULL , NULL) ;
siScrollInfo .nPos = siScrollInfo .nMax + 1 - siScrollInfo .nPage ;
}
break ;
case SB_THUMBPOSITION :
{
ScrollWindow (BezugDialog , 0 , (-(siScrollInfo .nTrackPos - siScrollInfo .nPos) * Zeilenhoehe) , NULL , NULL) ;
siScrollInfo .nPos = siScrollInfo .nTrackPos ;
}
else
{
ScrollWindow (BezugDialog , 0 , ((siScrollInfo .nPos - siScrollInfo .nTrackPos) * Zeilenhoehe) , NULL , NULL) ;
siScrollInfo .nPos = siScrollInfo .nTrackPos ;
}
break ;
default :
break ;
}
siScrollInfo.fMask = SIF_POS ;
SetScrollInfo (BezugDialog , SB_VERT , &siScrollInfo , TRUE) ;
break ;
}
case WM_KEYDOWN :
{
switch (wParam)
{
case VK_HOME :
PostMessage (BezugDialog , WM_VSCROLL , MAKEWORD(SB_TOP , 0) , 0L) ;
return 0 ;
case VK_END :
PostMessage (BezugDialog , WM_VSCROLL , MAKEWORD(SB_BOTTOM , 0) , 0L) ;
return 0 ;
case VK_PRIOR :
PostMessage (BezugDialog , WM_VSCROLL , MAKEWORD(SB_PAGEUP , 0) , 0L) ;
return 0 ;
case VK_NEXT :
PostMessage (BezugDialog , WM_VSCROLL , MAKEWORD(SB_PAGEDOWN , 0) , 0L) ;
return 0 ;
}
break ;
}
case WM_GETDLGCODE :
{
switch (wParam)
{
case VK_DOWN :
PostMessage (BezugDialog , WM_VSCROLL , MAKEWORD(SB_LINEDOWN , 0) , 0L) ;
return 0 ;
case VK_UP :
PostMessage (BezugDialog , WM_VSCROLL , MAKEWORD(SB_LINEUP , 0) , 0L) ;
return 0 ;
}
break ;
}
}
return FALSE ;
}
Edit: Added 'code' tags for code readibility - Hack