📄 hwnavigation.cpp
字号:
sidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
sidi.hDlg = hDlg;
SHInitDialog(&sidi);
bRet = TRUE;
}
break;
case WM_PAINT:
hdc = BeginPaint(hDlg, &ps);
EndPaint(hDlg, &ps);
bRet = TRUE;
break;
case WM_CLOSE:
DestroyWindow(hDlg);
break;
case WM_DESTROY:
CommandBar_Destroy(g_hWndMenuBar);
PostQuitMessage(0);
break;
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hDlg, wParam, lParam, &s_sai, FALSE);
bRet = TRUE;
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hDlg, wParam, lParam, &s_sai);
bRet = TRUE;
break;
}
return FALSE;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
}
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return TRUE;
#ifdef _DEVICE_RESOLUTION_AWARE
case WM_SIZE:
{
DRA::RelayoutDialog(
g_hInst,
hDlg,
DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX));
}
break;
#endif
}
return (INT_PTR)FALSE;
}
// The HWNavControl class is intended to showcase some hardware navigation concepts
// and is not very flexible. It only supports exactly 2 items, laid out horizontally.
// It responds to keyboard interaction but not to mouse/stylus events. A full-featured
// custom control would also respond to mouse/stylus.
// In addition, the control items have a predetermined size and separation.
#define HWNC_NUMITEMS 2
#define HWNC_ITEMWIDTH (DRA::SCALEX(40))
#define HWNC_ITEMHEIGHT (DRA::SCALEY(40))
#define HWNC_ITEMSEP (DRA::SCALEX(2))
// Message handler for windows of "HWNavControl" class
LRESULT CALLBACK HWNavWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rcClient;
int iCurItem;
LRESULT lRet = 0;
static HIMAGELIST s_himlBell = NULL;
switch (message)
{
case WM_CREATE:
rcClient.left = 0;
rcClient.top = 0;
rcClient.right = 2*HWNC_ITEMWIDTH + HWNC_ITEMSEP;
rcClient.bottom = HWNC_ITEMHEIGHT;
// Keep track of focus state, FALSE on creation
SetProp(hWnd, c_szHWNavCtlFocusProp, (HANDLE)FALSE);
// Keep track of current item, 0 on creation
SetProp(hWnd, c_szHWNavCtlPosProp, (HANDLE)0);
break;
case WM_SETFOCUS:
// Keep track of focus state
SetProp(hWnd, c_szHWNavCtlFocusProp, (HANDLE)TRUE);
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_KILLFOCUS:
// Keep track of focus state
SetProp(hWnd, c_szHWNavCtlFocusProp, (HANDLE)FALSE);
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_GETDLGCODE:
{
// We want to process arrow messages unless we detect
// that arrow key would take focus out of control.
// In that case, let system take care of message.
LONG code = DLGC_WANTARROWS;
if (lParam)
{
MSG *pMsg = (MSG*)lParam;
if (WM_KEYDOWN == pMsg->message)
{
iCurItem = (int)GetProp(hWnd, c_szHWNavCtlPosProp);
switch (pMsg->wParam)
{
case VK_UP:
case VK_DOWN:
// Vertical motion always takes focus away from control,
// so we let system take care of these keypresses.
code &= ~DLGC_WANTARROWS;
break;
case VK_LEFT:
// Horizontal motion to the left takes focus away from
// control if focus is currently on first item, so we
// let system take care of these keypresses.
if (iCurItem <= 0)
{
code &= ~DLGC_WANTARROWS;
}
break;
case VK_RIGHT:
// Horizontal motion to the right takes focus away from
// control if focus is currently on last item, so we
// let system take care of these keypresses.
if (iCurItem >= HWNC_NUMITEMS - 1)
{
code &= ~DLGC_WANTARROWS;
}
break;
case VK_RETURN:
// We always want control to process return key
code |= DLGC_WANTMESSAGE;
break;
}
}
}
lRet = code;
}
break;
case WM_KEYDOWN:
{
iCurItem = (int)GetProp(hWnd, c_szHWNavCtlPosProp);
switch (wParam)
{
case VK_LEFT:
// Change currently focused item down towards first one
iCurItem = max(0, iCurItem - 1);
SetProp(hWnd, c_szHWNavCtlPosProp, (HANDLE)iCurItem);
break;
case VK_RIGHT:
// Change currently focused item up towards last one
iCurItem = min(HWNC_NUMITEMS - 1, iCurItem + 1);
SetProp(hWnd, c_szHWNavCtlPosProp, (HANDLE)iCurItem);
break;
case VK_RETURN:
{
// Perform action with currently focused item
TCHAR szMsg[200];
_stprintf(szMsg, TEXT("Item %i has focus"),iCurItem);
MessageBox(hWnd, szMsg, TEXT("Custom Control Focus"), MB_OK);
break;
}
}
InvalidateRect(hWnd, NULL, TRUE);
break;
}
case WM_PAINT:
{
int i;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rcClient);
FillRect(hdc, &rcClient, GetSysColorBrush(COLOR_WINDOW));
iCurItem = (int)GetProp(hWnd, c_szHWNavCtlPosProp);
if ((BOOL)GetProp(hWnd, c_szHWNavCtlFocusProp))
{
// If control has focus, draw themed focus rect around
// focused item.
RECT rcFocus = rcClient;
rcFocus.left = iCurItem*HWNC_ITEMWIDTH +
max(0, iCurItem-1)*HWNC_ITEMSEP;
rcFocus.right = rcFocus.left + HWNC_ITEMWIDTH;
DrawFocusRectColor(hdc, &rcFocus, DFRC_FOCUSCOLOR);
}
if (!s_himlBell)
{
s_himlBell = DRA::ImageList_LoadImage(g_hInst,
MAKEINTRESOURCE(IDB_IMAGES),
HWNC_ITEMWIDTH,
0,
RGB(255,255,255),
IMAGE_BITMAP,
0);
}
for (i = 0; i < HWNC_NUMITEMS; i++)
{
// Draw the image corresponding to each item
ImageList_Draw(s_himlBell, i, hdc,
i*HWNC_ITEMWIDTH + max(0, i-1)*HWNC_ITEMSEP,
rcClient.top,
ILD_NORMAL);
}
EndPaint(hWnd, &ps);
break;
}
}
return lRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -