📄 dialogscreen.cpp
字号:
StatusHeader_t StatusHeader;
StatusHeader = GetDlgItem(m_hwnd, IDC_STATUSREGION);
//
// Update the status header with the users requested parameters
//
if (pParameters->pStatusHeader)
{
if (0 == HIWORD(pParameters->pStatusHeader))
{
STATUS_HEADER_PARAMETERS Params = {0};
Params.Instance = m_Instance;
Params.Priority = shpDefault;
Params.ResourceId = LOWORD(pParameters->pStatusHeader);
Params.secTimeout = INFINITE;
SendMessage(
StatusHeader,
WM_STATUSHEADER_ADDSTATUSNOTIFICATION,
sizeof(Params),
(LPARAM)&Params
);
}
else
{
STATUS_HEADER_PARAMETERS_EX ExParams;
ZeroMemory(&ExParams, sizeof(ExParams));
ExParams.Instance = NULL;
ExParams.ResourceId = 0;
ExParams.Priority = shpDefault;
ExParams.secTimeout = INFINITE;
ExParams.pwszDisplayString = pParameters->pStatusHeader;
SendMessage(
StatusHeader,
WM_STATUSHEADER_ADDSTATUSNOTIFICATION,
sizeof(ExParams),
(LPARAM)&ExParams
);
}
}
m_TimerId = SetTimer(
m_hwnd,
c_TimerIdentifier,
c_TimeOutValue,
NULL
);
ASSERT(m_TimerId);
//set buttons
MenuBar_t MenuBar;
MenuBar = GetDlgItem(m_hwnd, IDC_MENUBAR);
MenuBar.SetMenu(m_Instance, pParameters->MenuId);
LRESULT Result = CallHook(
WM_INITDIALOG,
reinterpret_cast<WPARAM>(ControlToReceiveFocus),
reinterpret_cast<LPARAM>(pParameters)
) ? TRUE : FALSE;
if (!(pParameters->Flags & VDF_HIDDEN))
{
ShowWindow(m_hwnd, SW_SHOW);
}
return Result;
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnLButtonDown
Handle clicks on scroll arrows
------------------------------------------------------------------------------*/
LRESULT
DialogScreen_t::OnLButtonDown(
UINT SystemKeys,
short xCoordinate,
short yCoordinate
)
{
LRESULT Result = 1;
RECT ArrowRect;
POINT Click = {xCoordinate, yCoordinate};
ListBox_t ListBox;
ListBox = GetDlgItem(m_hwnd, IDC_LISTBOX);
if (CheckState(VLBN_ITEMS_BELOW_DISPLAY))
{
GetScrollDownRect(ArrowRect);
if (PtInRect(&ArrowRect, Click))
{
SendMessage(ListBox, WM_KEYDOWN, VK_NEXT, 0);
Result = 0;
goto set_focus;
}
}
if (CheckState(VLBN_ITEMS_ABOVE_DISPLAY))
{
GetScrollUpRect(ArrowRect);
if (PtInRect(&ArrowRect, Click))
{
SendMessage(ListBox, WM_KEYDOWN, VK_PRIOR, 0);
Result = 0;
}
}
set_focus:
if ((Result == 0) &&
!CommonUtilities_t::HasParentalFocus(ListBox))
{
SetFocus(ListBox);
}
return Result;
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnNotify
Handle notifications from the children
------------------------------------------------------------------------------*/
LRESULT
DialogScreen_t::OnNotify(
int ControlId,
NMHDR* pNotificationHeader
)
{
if (!pNotificationHeader)
{
return 0;
}
switch (ControlId)
{
case IDC_LISTBOX:
ASSERT(CommonUtilities_t::ControlTypeListbox ==
CommonUtilities_t::GetControlType(pNotificationHeader->hwndFrom));
if ((pNotificationHeader->code == 0) ||
CheckState(
VLBN_ITEMS_ABOVE_DISPLAY,
reinterpret_cast<const DWORD*>(&pNotificationHeader->code)
) ||
CheckState(
VLBN_ITEMS_BELOW_DISPLAY,
reinterpret_cast<const DWORD*>(&pNotificationHeader->code)
)
)
{
RECT TitleRect;
RECT ScrollDown;
//If the state has changed, invalidate the scroll regions
m_State = pNotificationHeader->code;
GetTitleRect(TitleRect);
GetScrollDownRect(ScrollDown);
InvalidateRect(m_hwnd, &TitleRect, TRUE);
InvalidateRect(m_hwnd, &ScrollDown, TRUE);
}
break;
}
return 0;
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnPaint
Handle paint requests for this message box
------------------------------------------------------------------------------*/
LRESULT
DialogScreen_t::OnPaint(
HDC hdc
)
{
HRESULT hr;
WCHAR TextBuffer[100] = TEXT("");
PaintHelper_t paint;
//start the painting operation
hr= paint.Begin(m_hwnd);
if (FAILED(hr))
{
return 0;
}
RECT ClientRect;
GetClientRect(m_hwnd, &ClientRect);
PaintHelper_t& paintToUse = ((HDC)m_BackBuffer == NULL) ? paint : m_BackBuffer;
RECT Dummy;
//Draw the logo
Bitmap_t WindowsLogo;
hr = WindowsLogo.Attach(
GlobalData_t::s_GDICacheObject.LoadCachedBitmap(IDB_LOGO_SMALL)
);
if (FAILED(hr))
{
return 0;
}
RECT LogoRect;
LogoRect.left = ClientRect.right - WindowsLogo.Width() - Layout_t::LogoRightMargin();
LogoRect.top = ClientRect.top + Layout_t::LogoTopMargin();
LogoRect.right = LogoRect.left + WindowsLogo.Width();
LogoRect.bottom = LogoRect.top + WindowsLogo.Height();
if (IntersectRect(&Dummy, &paint.Rect(), &LogoRect))
{
TransparentImage(
paintToUse,
LogoRect.left,
LogoRect.top,
WindowsLogo.Width(),
WindowsLogo.Height(),
WindowsLogo,
0,
0,
WindowsLogo.Width(),
WindowsLogo.Height(),
Colors_t::DefaultTransparentColor()
);
}
// Draw the Title
RECT TitleRect;
GetTitleRect(TitleRect);
if (IntersectRect(&Dummy, &paint.Rect(), &TitleRect))
{
Bitmap_t TitleBar;
hr = TitleBar.Attach(
GlobalData_t::s_GDICacheObject.LoadCachedBitmap(IDB_TITLE_BAR)
);
if (FAILED(hr))
{
return 0;
}
//Draw the title's background
hr = paintToUse.TileBlt(
&TitleBar,
&TitleRect,
NULL,
Layout_t::DialogScreenTitleTileLeft(),
Layout_t::DialogScreenTitleTileTop(),
Layout_t::DialogScreenTitleTileRight(),
Layout_t::DialogScreenTitleTileBottom(),
Colors_t::DefaultTransparentColor()
);
ASSERT(SUCCEEDED(hr));
//Get the window text and draw it
if (GetWindowText(m_hwnd,TextBuffer, _countof(TextBuffer)) > 0)
{
ASSERT(TextBuffer[0] != L'\0');
paintToUse.SetBkMode(TRANSPARENT);
paintToUse.SetFont(Fonts_t::StandardTextBold());
paintToUse.SetTextColor(Colors_t::DialogScreenTitleTextColor());
InflateRect(
&TitleRect,
-Layout_t::DialogScreenTitleTextHorzMargin(),
0
);
hr = paintToUse.DrawText(
TextBuffer,
-1,
&TitleRect,
DT_VCENTER | DT_SINGLELINE | DT_LEFT | DT_NOPREFIX
);
ASSERT(SUCCEEDED(hr));
}
//Draw the "items x-y" text if items are above or below the viewport
if (m_State != 0)
{
WCHAR ItemsText[MAX_PATH] = L"";
ListBox_t ListBox;
ListBox = GetDlgItem(m_hwnd, IDC_LISTBOX);
PREFAST_SUPPRESS(5428, "It is safe to use StringCchPrintfExW (known parameters)");
StringCchPrintfExW(
ItemsText,
_countof(ItemsText),
NULL,
NULL,
STRSAFE_IGNORE_NULLS,
CommonUtilities_t::LoadString(
GlobalData_t::s_ModuleInstance,
IDS_DIALOG_SCREEN_CURRENT_ITEMS
),
ListBox.GetTopIndex() + 1,
ListBox.GetBottomIndex() + 1
);
RECT ScrollUp;
GetScrollUpRect(ScrollUp);
TitleRect.right = ScrollUp.left - 2;
paintToUse.SetFont(Fonts_t::InformationText());
hr = paintToUse.DrawText(
ItemsText,
-1,
&TitleRect,
DT_VCENTER | DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX
);
ASSERT(SUCCEEDED(hr));
}
}
RECT ArrowRect;
//If there are items above the display, draw the up arrow
if (CheckState(VLBN_ITEMS_ABOVE_DISPLAY))
{
GetScrollUpRect(ArrowRect);
Bitmap_t ScrollArrowUp;
hr = ScrollArrowUp.Attach(
GlobalData_t::s_GDICacheObject.LoadCachedBitmap(IDB_SCROLL_ARROW_UP)
);
if (SUCCEEDED(hr))
{
TransparentImage(
paintToUse,
ArrowRect.left,
ArrowRect.top,
ScrollArrowUp.Width(),
ScrollArrowUp.Height(),
ScrollArrowUp,
0,
0,
ScrollArrowUp.Width(),
ScrollArrowUp.Height(),
Colors_t::DefaultTransparentColor()
);
}
}
//If there are items below the display, draw the down arrow
if (CheckState(VLBN_ITEMS_BELOW_DISPLAY))
{
GetScrollDownRect(ArrowRect);
Bitmap_t ScrollArrowDown;
hr = ScrollArrowDown.Attach(
GlobalData_t::s_GDICacheObject.LoadCachedBitmap(IDB_SCROLL_ARROW_DOWN)
);
if (SUCCEEDED(hr))
{
TransparentImage(
paintToUse,
ArrowRect.left,
ArrowRect.top,
ScrollArrowDown.Width(),
ScrollArrowDown.Height(),
ScrollArrowDown,
0,
0,
ScrollArrowDown.Width(),
ScrollArrowDown.Height(),
Colors_t::DefaultTransparentColor()
);
}
}
if (paintToUse == m_BackBuffer)
{
paint = m_BackBuffer;
}
paint.End();
return 0;
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnSetFocus
Sets the focus to the listbox
------------------------------------------------------------------------------*/
LRESULT
DialogScreen_t::OnSetFocus(
HWND OldFocus
)
{
ListBox_t ListBox;
ListBox = GetDlgItem(m_hwnd, IDC_LISTBOX);
SetFocus(ListBox);
return 1;
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnTimer
Forward timer messages to our children controls
------------------------------------------------------------------------------*/
LRESULT
DialogScreen_t::OnTimer()
{
SendDlgItemMessage(
m_hwnd,
IDC_LISTBOX,
WM_TIMER,
0,
0
);
SendDlgItemMessage(
m_hwnd,
IDC_STATUSREGION,
WM_TIMER,
0,
0
);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -