Skip to content

Instantly share code, notes, and snippets.

@Appendme Appendme/Validate.cpp Secret
Created Nov 4, 2019

Embed
What would you like to do?
namespace AIMP
{
ValidateDialog::ValidateDialog(IAIMPServiceUI* uiService)
: _uiService(uiService)
, _form(nullptr)
, _codeEdit(nullptr)
, _codeLabel(nullptr)
, _okButton(nullptr)
, _cancelButton(nullptr)
{
}
ValidateDialog::~ValidateDialog()
{
if (_form)
_form->Release(0);
}
/**
* Throw:
* 1. DialogException
*/
bool ValidateDialog::Execute(HWND hwnd, std::wstring& code)
{
if (!_uiService) throw DialogException(L"ValidateDialog: ServiceUI null");
if (!_form) CreateForm(hwnd);
auto result = _form->ShowModal();
IAIMPString* _code = nullptr;
_codeEdit->GetValueAsObject(AIMPUI_BASEEDIT_PROPID_TEXT, IID_IAIMPString, ref_cast(_code));
if (_code)
{
code = std::wstring(_code->GetData(), _code->GetLength());
_code->Release();
}
return result == AIMPUI_FLAGS_MODALRESULT_OK;
}
void ValidateDialog::CreateForm(HWND hwnd)
{
_uiService->CreateForm(hwnd, 0, String(L"ValidateForm"), nullptr, &_form);
if (!_form) throw DialogException(L"ValidateDialog: CreateForm failed");
_uiService->CreateControl(
_form, _form, String(L"codeEdit"), nullptr, IID_IAIMPUIEdit, ref_cast(_codeEdit));
_uiService->CreateControl(
_form, _form, String(L"codelabel"), nullptr, IID_IAIMPUILabel, ref_cast(_codeLabel));
_uiService->CreateControl(
_form, _form, String(L"okButton"), nullptr, IID_IAIMPUIButton, ref_cast(_okButton));
_uiService->CreateControl(
_form, _form, String(L"cancelButton"), nullptr, IID_IAIMPUIButton, ref_cast(_cancelButton));
if (!_codeEdit || !_codeLabel || !_okButton || !_cancelButton)
throw DialogException(L"ValidateDialog: Some control null");
_form->SetValueAsInt32(AIMPUI_FORM_PROPID_BORDERSTYLE, AIMPUI_FLAGS_BORDERSTYLE_DIALOG);
_codeLabel->SetValueAsInt32(AIMPUI_LABEL_PROPID_AUTOSIZE, 1);
_codeLabel->SetPlacement(TAIMPUIControlPlacement(ualTop, 0, { 3, 50, 3, 3 }));
_codeEdit->SetPlacement(TAIMPUIControlPlacement(ualTop, 0, { 3, 5, 3, 3 }));
_okButton->SetPlacement(TAIMPUIControlPlacement(ualBottom, 25, { 3, 3, 3, 3 }));
_okButton->SetValueAsInt32(AIMPUI_BUTTON_PROPID_MODALRESULT, AIMPUI_FLAGS_MODALRESULT_OK);
_cancelButton->SetPlacement(TAIMPUIControlPlacement(ualBottom, 25, { 3, 3, 3, 3 }));
_cancelButton->SetValueAsInt32(AIMPUI_BUTTON_PROPID_MODALRESULT, AIMPUI_FLAGS_MODALRESULT_CANCEL);
_okButton->SetFocus();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.