Changing The Active Tab using PageUp/PageDown






2.44/5 (6 votes)
Nov 20, 1999

127731
I produce a custom database application, that has some windows with lots of tabs / CPropertyPages within them. My customer wanted a way to quickly and easily change the selected tab, without using the mouse. He said "In the old DOS version we changed the current window using Page-Up and Page-Down....". Ahh those were the days! So what the customer wants, the customer gets, and here is the result : Page-Up / Page-Down will select the next / previous tab. It's so easy, it's simple...
Basically sub-class your CPropertySheet. Then using the class wizard, create the PreTranslateMessage() function, and insert the text below...
if (pMsg->message == WM_KEYUP && pMsg->wParam == VK_NEXT) { if(GetPageCount() > 1) // Ignore if only one CPropertyPage { if(GetActiveIndex() == 0) //If first page active, select last page SetActivePage(GetPageCount() - 1); else SetActivePage(GetActiveIndex() - 1); //else select the previous page } } if (pMsg->message == WM_KEYUP && pMsg->wParam == VK_PRIOR) { if(GetPageCount() > 1) // Ignore if only one CPropertyPage { if(GetActiveIndex() == (GetPageCount() - 1)) //If last page active, select the first page SetActivePage(0); else SetActivePage(GetActiveIndex() + 1); //else select the next page } }