1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
HHOOK WndMessageBox::cbt_proc;
WndMessageBox::WndMessageBox(HWND owner, LPCWSTR text, LPCWSTR caption, UINT type) :
owner_{ owner },
text_{ text },
caption_{ caption },
type_{ type }
{
}
INT WndMessageBox::show()
{
if (owner_ != nullptr)
{
cbt_proc = ::SetWindowsHookExW(WH_CBT, CBTProc, nullptr, ::GetCurrentThreadId());
}
return ::MessageBoxW(owner_, text_, caption_, type_);
}
LRESULT CALLBACK WndMessageBox::CBTProc(INT code, WPARAM wparam, LPARAM lparam)
{
if (code == HCBT_ACTIVATE)
{
WndCenter(HWND(wparam), ::GetParent(HWND(wparam)));
::UnhookWindowsHookEx(cbt_proc);
}
return ::CallNextHookEx(nullptr, code, wparam, lparam);
}
|