BOOL CSudokuView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CFormView::PreTranslateMessage(pMsg);
}
if(pMsg->message == WM_KEYDOWN)
{
bool bMove = false; //an arrow key - don't use default behaviour
int iFocus = 999;
switch(pMsg->wParam)
{
case VK_UP:
iFocus = GetBtnFocused() - 9; //'up' one row of the grid
bMove = true;
break;
case VK_DOWN:
iFocus = GetBtnFocused() + 9; //'down' one row of the grid
bMove = true;
break;
case VK_LEFT:
iFocus = GetBtnFocused() - 1; //'left' one column of the grid
bMove = true;
break;
case VK_RIGHT:
iFocus = GetBtnFocused() + 1; //'right' one column of the grid
bMove = true;
break;
}
if((iFocus >= 0) && (iFocus < 81))
m_arWndButtons[iFocus].SetFocus();
if(bMove)
return TRUE;
}
protected:
int GetBtnFocused();
int CSudokuView::GetBtnFocused()
{
CWnd* pFocus = GetFocus();
if(pFocus == NULL)
return 999;
for(int i = 0; i < 81; i++)
{
if(&m_arWndButtons[i] == pFocus)
return i;
}
return 999;
}
BOOL CGridButton::PreTranslateMessage(MSG* pMsg)
{
if(!m_bLock && (pMsg->message == WM_KEYDOWN)) //if locked then can't change the value
{
int iKey = -1;
switch(pMsg->wParam)
{
case VK_NUMPAD0:
case VK_NUMPAD1:
case VK_NUMPAD2:
case VK_NUMPAD3:
case VK_NUMPAD4:
case VK_NUMPAD5:
case VK_NUMPAD6:
case VK_NUMPAD7:
case VK_NUMPAD8:
case VK_NUMPAD9:
iKey = (int)pMsg->wParam - VK_NUMPAD0;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
iKey = (int)pMsg->wParam - '0';
break;
case VK_SPACE:
case VK_DELETE:
case VK_BACK:
iKey = 0;
break;
}
if(iKey >= 0)
{
SetValue(iKey);
GetParent()->SendMessage(SUD_SETVALUE, (WPARAM)this, (LPARAM)iKey);
return TRUE;
}
}
return CButton::PreTranslateMessage(pMsg);
}
#define SUD_SETVALUE (WM_USER+101)
GetParent()->SendMessage(SUD_SETVALUE, (WPARAM)this, (LPARAM)iKey);
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)