#include <bits/stdc++.h>
#include <windows.h>
#include <thread>
#include <random>
using namespace std;
mt19937 rnd(random_device{}());
HHOOK hhook;
LRESULT CALLBACK MsgBoxHook(int n,WPARAM w,LPARAM l)
{
    if(n==HCBT_ACTIVATE)
    {
        HWND hDlg=(HWND)w;
        RECT rcDesktop;
        GetWindowRect(GetDesktopWindow(),&rcDesktop);
        uniform_int_distribution<int> dx(0,rcDesktop.right-150);
        uniform_int_distribution<int> dy(0,rcDesktop.bottom-200);
        SetWindowPos(hDlg,NULL,dx(rnd),dy(rnd),0,0,SWP_NOSIZE|SWP_NOZORDER);
        UnhookWindowsHookEx(hhook);
    }
    return CallNextHookEx(hhook,n,w,l);
}
void error()
{
    hhook=SetWindowsHookEx(WH_CBT,MsgBoxHook,NULL,GetCurrentThreadId());
    MessageBox(NULL,"ERROR","错误",MB_OK|MB_ICONEXCLAMATION);
}
int main()
{
    system("mode con cols=20 lines=10");
    vector<thread> ths;
    int cnt=500;
    for(int i=1;i<=cnt;i++)
	{
        ths.emplace_back(error);
    }
    for(auto& t: ths) t.join();
    return 0;
}