VC++


Windowのフォアグラウンド化

void SetForegroundWindow(CWnd *cwn)
{
    int fid,tid;
    DWORD flt;

    fid = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
    tid = GetWindowThreadProcessId(cwn->m_hWnd, NULL);
    AttachThreadInput(tid, fid, TRUE);
    SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &flt, 0);
    SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (PVOID)0, 0);
    cwn->ShowWindow(SW_RESTORE);
    cwn->SetForegroundWindow();
    SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (PVOID)flt, 0);
    AttachThreadInput(tid, fid, FALSE);
}