Пример #1
0
UINT __stdcall Module::ThreadProc(void* dllModPtr)
{
    Module* dllMod = (Module*)dllModPtr;

#if defined(MSVC_DEBUG)
    LPCTSTR pszFileName = PathFindFileName(dllMod->m_wzLocation.c_str());
    DbgSetCurrentThreadName(WCSTOMBS(pszFileName));
#endif

    dllMod->CallInit();

    // We must use a copy of our event, and hope no one has closed it before
    // waiting for it to be signaled.  See: TakeThread() member function.
    SetEvent(dllMod->m_hInitCopyEvent);

    MSG msg;

    while (GetMessage(&msg, 0, 0, 0) > 0)
    {
        if (msg.hwnd == NULL)
        {
            // Thread message
            HandleThreadMessage(msg);
        }
        else
        {
            // Window message
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return 0;
}
Пример #2
0
//
// LSThreadThunk
// for use LSCreateThread
//
DWORD WINAPI LSThreadThunk(LPVOID pParam)
{
    LS_THREAD_DATA* pData = (LS_THREAD_DATA*)pParam;
    ASSERT(pData != NULL);

    // create local copy
    LS_THREAD_DATA data = *pData;

    if (data.pszName)
    {
        DbgSetCurrentThreadName(data.pszName);
    }

    SetEvent(data.hEvent);
    return data.fnOrigFunc(data.pOrigParam);
}
//
// ThreadProc
//
void FullscreenMonitor::ThreadProc()
{
    
#if defined(_DEBUG)
    DbgSetCurrentThreadName("LS FullscreenMonitor Service");
#endif

    //
    struct FSWindow {
        FSWindow(HWND hWnd, HMONITOR hMonitor) {
            this->hWnd = hWnd;
            this->hMonitor = hMonitor;
        }
        HWND hWnd;
        HMONITOR hMonitor;
    };

    // List of all currently living known fullscreen windows
    std::list<FSWindow> fullscreenWindows;

    // The monitors which currently have modules hidden
    std::unordered_multiset<HMONITOR> hiddenMonitors;

    DWORD dwLiteStepProcID;
    GetWindowThreadProcessId(GetLitestepWnd(), &dwLiteStepProcID);

    // On startup, find any existing fullscreen windows.
    EnumDesktopWindows(nullptr, [] (HWND hWnd, LPARAM lParam) -> BOOL
    {
        HMONITOR hMonitor = IsFullscreenWindow(hWnd);
        std::list<FSWindow> *fullscreenWindows = (std::list<FSWindow>*)lParam;
        if (hMonitor)
        {
            // And add it to the list of fullscreen windows.
            fullscreenWindows->push_back(FSWindow(hWnd, hMonitor));
        }
        return TRUE;
    }, (LPARAM)&fullscreenWindows);

    // Hide modules on any monitor we found
    for (FSWindow window : fullscreenWindows)
    {
        hiddenMonitors.insert(window.hMonitor);
        if (hiddenMonitors.count(window.hMonitor) == 1)
        {
            HideModules(window.hMonitor, window.hWnd);
        }
    }

    // Main Loop
    while (m_bRun.load())
    {
        HWND hwndForeGround = GetForegroundWindow();
        bool bCheckedForeGround = false;

        // Re-Hide modules on all monitors
        if (m_bReHide.load())
        {
            hiddenMonitors.clear();
            for (FSWindow window : fullscreenWindows)
            {
                hiddenMonitors.insert(window.hMonitor);
                if (hiddenMonitors.count(window.hMonitor) == 1)
                {
                    HideModules(window.hMonitor, window.hWnd);
                }
            }
        }

        // Verify that all currently known fullscreen windows are still fullscreen.
        std::list<FSWindow>::iterator iter = fullscreenWindows.begin();
        while (iter != fullscreenWindows.end())
        {
            HMONITOR hNewMonitor = IsFullscreenWindow(iter->hWnd);

            // If we already checked the foreground window, don't bother doing it again.
            if (iter->hWnd == hwndForeGround)
            {
                bCheckedForeGround = true;
            }

            // 
            if (hNewMonitor != iter->hMonitor)
            {
                hiddenMonitors.erase(iter->hMonitor);

                // If there are no fullscreen windows left on the monitor, show the modules
                if (hiddenMonitors.count(iter->hMonitor) == 0)
                {
                    ShowModules(iter->hMonitor);
                }

                // Check if the window moved to another monitor (and stayed fullscreen)
                if (hNewMonitor)
                {
                    iter->hMonitor = hNewMonitor;
                    hiddenMonitors.insert(hNewMonitor);
                    if (hiddenMonitors.count(hNewMonitor) == 1)
                    {
                        HideModules(hNewMonitor, iter->hWnd);
                    }
                }
                else
                {
                    iter = fullscreenWindows.erase(iter);
                    continue;
                }
            }

            ++iter;
        }

        // Check if the currently active window is a fullscreen window.
        if (!bCheckedForeGround)
        {
            // If the currently active window belongs to litestep, show all modules.
            DWORD dwProcID;
            GetWindowThreadProcessId(hwndForeGround, &dwProcID);
            if (dwProcID == dwLiteStepProcID)
            {
                if (!hiddenMonitors.empty())
                {
                    for (HMONITOR hMonitor : hiddenMonitors)
                    {
                        ShowModules(hMonitor);
                    }
                    hiddenMonitors.clear();
                    fullscreenWindows.clear();
                }
            }
            else
            {
                HMONITOR hMonitor = IsFullscreenWindow(hwndForeGround);
                if (hMonitor)
                {
                    // Add the window to the list of known foreground windows.
                    fullscreenWindows.push_back(FSWindow(hwndForeGround, hMonitor));
                    hiddenMonitors.insert(hMonitor);

                    // If we didn't know about any fullscreen windows on this monitor before, hide the modules on it.
                    if (hiddenMonitors.count(hMonitor) == 1)
                    {
                        HideModules(hMonitor, hwndForeGround);
                    }
                }
            }
        }

        // Avoid using excesive amounts of CPU time
        std::this_thread::sleep_for(m_workerSleepDuration);
    }
}