📄 dialog.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "Dialog.hpp"
#include "ControlDefinitions.h"
#include "Common.hpp"
#include "Resource.h"
#include "InfoApp.hpp"
DialogScreen_t::DialogScreen_t()
{
m_Dialog = NULL;
m_ErrorDialog = NULL;
m_HelpDialog = NULL;
m_ExitAfterError = false;
}
DialogScreen_t::~DialogScreen_t()
{
if (m_Dialog != NULL)
{
DestroyWindow(m_Dialog);
}
if (m_ErrorDialog)
{
DestroyWindow(m_ErrorDialog);
}
if (m_HelpDialog)
{
DestroyWindow(m_HelpDialog);
}
}
BOOL
DialogScreen_t::s_HookProc(
HWND hwnd,
UINT Message,
WPARAM wParam,
LPARAM lParam,
VOID* pvData
)
{
if (! pvData)
{
return FALSE;
}
DialogScreen_t* pDialog = reinterpret_cast<DialogScreen_t*>(pvData);
switch (Message)
{
case WM_INITDIALOG:
pDialog->m_Dialog = hwnd;
pDialog->m_StatusRegion = GetDlgItem(hwnd, IDC_STATUSREGION);
pDialog->m_Listbox = GetDlgItem(hwnd, IDC_LISTBOX);
pDialog->m_MenuBar = GetDlgItem(hwnd, IDC_MENUBAR);
break;
case WM_HELP:
pDialog->OnHelp();
break;
case WM_NOTIFY:
switch(wParam)
{
case IDC_ERRORMSG_OK:
DestroyWindow(pDialog->m_ErrorDialog);
pDialog->m_ErrorDialog = NULL;
if (pDialog->m_ExitAfterError)
{
pDialog->Exit();
}
break;
case IDC_HELPMSG_OK:
DestroyWindow(pDialog->m_HelpDialog);
pDialog->m_HelpDialog = NULL;
break;
}
break;
case WM_DESTROY:
if (pDialog != NULL)
{
delete pDialog;
}
return FALSE;
}
return pDialog->HookProc(hwnd, Message, wParam, lParam);
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnBackspace
Handle a backspace request from the user
------------------------------------------------------------------------------*/
HRESULT
DialogScreen_t::OnBackspace()
{
SendMessage(
GetFocus(),
WM_CHAR,
L'\b',
0
);
return S_OK;
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnVKeyToItem
Change the focus to the first element in the Listbox, filter element.
Since this message only delivers the Virtual Key code(always A when a is typed)
and NOT the actual character, we drop the first character instead of adding it
to the filter element.
------------------------------------------------------------------------------*/
HRESULT
DialogScreen_t::SetFocusToFirstItem()
{
//
// Change the focus to the first element in the Listbox, filter element.
//
SendMessage(
m_Listbox,
LB_SETCURSEL,
0,
0
);
//
// Since we are only concerned about setting the focus to the first element
// always return E_FAIL.
//
return E_FAIL;
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnHelp
Handle WM_HELP and show the context sensitive help for this screen
------------------------------------------------------------------------------*/
void
DialogScreen_t::OnHelp()
{
if (IsWindow(m_ErrorDialog) || IsWindow(m_HelpDialog))
{
return;
}
PH_MESSAGE_BOX_PARAMETERS Params = {0};
Params.StructSize = sizeof(Params);
Params.Flags = VDF_TYPE_MODELESS;
Params.IconId = IDB_HELP;
Params.Instance = GlobalData_t::s_ModuleInstance;
Params.Owner = m_Dialog;
Params.MenuId = IDMB_MSGBOX_HELP;
Params.pText = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, GetHelpStringId());
Params.pTitle = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_LABEL_HELP);
if (! PHMessageBox(&Params))
{
ASSERT(FALSE);
}
m_HelpDialog = Params.result.Dialog;
return;
}
/*------------------------------------------------------------------------------
DialogScreen_t::OnExit
Handle a cancel request from the user
------------------------------------------------------------------------------*/
HRESULT
DialogScreen_t::Exit()
{
return PhInfoGlobalData_t::pPhInfoApp->GoBackToPreviousScreen();
}
HRESULT
DialogScreen_t::CreateDialogScreen(
UINT DialogId,
UINT MenuId,
const WCHAR* pTitle,
const WCHAR* pStatusHeader
)
{
PH_DIALOG_SCREEN_PARAMETERS DialogScreenParameters = {0};
DialogScreenParameters.StructSize = sizeof(DialogScreenParameters);
DialogScreenParameters.Flags = VDF_TYPE_MODELESS;
DialogScreenParameters.pDialogHook = s_HookProc;
DialogScreenParameters.pUserData = (VOID*)this;
DialogScreenParameters.Instance = GlobalData_t::s_ModuleInstance;
DialogScreenParameters.MenuId = MenuId;
DialogScreenParameters.Id = DialogId;
DialogScreenParameters.pStatusHeader = pStatusHeader;
DialogScreenParameters.pTitle = pTitle;
if (! PHDialogScreen(&DialogScreenParameters))
{
return CommonUtilities_t::GetErrorFromWin32();
}
m_Dialog = DialogScreenParameters.result.Dialog;
return S_OK;
}
/*------------------------------------------------------------------------------
DialogScreen_t::ShowError
Show an error screen for the subclass
------------------------------------------------------------------------------*/
HRESULT
DialogScreen_t::ShowError(
int ErrorString,
UINT MenuId,
bool ExitOnError
)
{
if (IsWindow(m_ErrorDialog) || IsWindow(m_HelpDialog))
{
return S_FALSE;
}
m_ExitAfterError = ExitOnError;
PH_MESSAGE_BOX_PARAMETERS Params = {0};
Params.StructSize = sizeof(Params);
Params.Flags = VDF_TYPE_MODELESS;
Params.IconId = IDB_HELP;
Params.Instance = GlobalData_t::s_ModuleInstance;
Params.Owner = m_Dialog;
Params.MenuId = MenuId;
Params.pText = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, ErrorString);
Params.pTitle = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_LABEL_ERROR);
if (! PHMessageBox(&Params))
{
ASSERT(FALSE);
if (m_ExitAfterError)
{
Exit();
}
return E_FAIL;
}
m_ErrorDialog = Params.result.Dialog;
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -