110 lines
2.4 KiB
C++
110 lines
2.4 KiB
C++
#include "4J_Storage.h"
|
|
#include "INP_MessageUI.h"
|
|
|
|
CMessageUI::CMessageUI()
|
|
{
|
|
bCancel = false;
|
|
}
|
|
|
|
C4JStorage::EMessageResult CMessageUI::RequestMessageBox(LPCWSTR uiTitle, LPCWSTR uiText, LPCWSTR *uiButtons, UINT uiButtonCount, DWORD dwPad, int(*Func)(LPVOID, int, const C4JStorage::EMessageResult), LPVOID lpParam, DWORD dwFocusButton)
|
|
{
|
|
if (eState == C4JStorage::EMessage_Pending)
|
|
return C4JStorage::EMessage_Busy;
|
|
|
|
eState = C4JStorage::EMessage_Pending;
|
|
|
|
for (UINT i = 0; i < uiButtonCount; i++)
|
|
this->uiButtons[i] = uiButtons[i];
|
|
this->uiTitle = uiTitle;
|
|
this->uiText = uiText;
|
|
this->uiButtonCount = uiButtonCount;
|
|
this->dwPad = dwPad;
|
|
this->dwFocusButton = dwFocusButton;
|
|
this->Func = Func;
|
|
this->lpParam = lpParam;
|
|
|
|
CreateThread(NULL, 0, CreateMessageBoxUIFn, this, 0, NULL);
|
|
|
|
return eState;
|
|
}
|
|
|
|
DWORD WINAPI CMessageUI::CreateMessageBoxUIFn(LPVOID lpParam)
|
|
{
|
|
CMessageUI *self = (CMessageUI *)lpParam;
|
|
|
|
XOVERLAPPED MessageBoxOverlap;
|
|
ZeroMemory(&MessageBoxOverlap, sizeof(XOVERLAPPED));
|
|
|
|
MESSAGEBOX_RESULT MessageResult;
|
|
ZeroMemory(&MessageResult, sizeof(MESSAGEBOX_RESULT));
|
|
|
|
bool bShown = true;
|
|
do
|
|
{
|
|
DWORD result = XShowMessageBoxUI(self->dwPad, self->uiTitle, self->uiText, self->uiButtonCount, self->uiButtons, self->dwFocusButton, 0, &MessageResult, &MessageBoxOverlap);
|
|
if (result != ERROR_ACCESS_DENIED)
|
|
break;
|
|
Sleep(250);
|
|
if (self->bCancel)
|
|
bShown = false;
|
|
} while (bShown);
|
|
|
|
C4JStorage::EMessageResult state;
|
|
|
|
if (!bShown)
|
|
{
|
|
state = C4JStorage::EMessage_Cancelled;
|
|
}
|
|
else
|
|
{
|
|
while (MessageBoxOverlap.InternalLow == ERROR_IO_PENDING)
|
|
{
|
|
Sleep(250);
|
|
if (self->bCancel)
|
|
{
|
|
XCancelOverlapped(&MessageBoxOverlap);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (self->bCancel || XGetOverlappedResult(&MessageBoxOverlap, NULL, TRUE) == ERROR_CANCELLED)
|
|
{
|
|
state = C4JStorage::EMessage_Cancelled;
|
|
}
|
|
else switch (MessageResult.dwButtonPressed)
|
|
{
|
|
case 0:
|
|
state = C4JStorage::EMessage_ResultAccept;
|
|
break;
|
|
case 1:
|
|
state = C4JStorage::EMessage_ResultDecline;
|
|
break;
|
|
case 2:
|
|
state = C4JStorage::EMessage_ResultThirdOption;
|
|
break;
|
|
case 3:
|
|
state = C4JStorage::EMessage_ResultFourthOption;
|
|
break;
|
|
default:
|
|
state = C4JStorage::EMessage_Cancelled;
|
|
break;
|
|
}
|
|
}
|
|
|
|
self->eState = state;
|
|
|
|
if (self->Func)
|
|
self->Func(self->lpParam, self->dwPad, state);
|
|
|
|
ExitThread(0);
|
|
}
|
|
|
|
void CMessageUI::CancelMessageBoxRequest()
|
|
{
|
|
bCancel = true;
|
|
}
|
|
|
|
C4JStorage::EMessageResult CMessageUI::GetMessageBoxResult()
|
|
{
|
|
return eState;
|
|
} |