mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
92 lines
No EOL
1.8 KiB
C++
92 lines
No EOL
1.8 KiB
C++
// DllMain.cpp : Runtime.dll 的入口点。
|
|
//
|
|
|
|
|
|
#include "pch.h"
|
|
#include "MagWindow.h"
|
|
|
|
|
|
HINSTANCE hInstance = NULL;
|
|
|
|
|
|
// DLL 入口
|
|
BOOL APIENTRY DllMain(
|
|
HMODULE hModule,
|
|
DWORD ul_reason_for_call,
|
|
LPVOID lpReserved
|
|
) {
|
|
switch (ul_reason_for_call) {
|
|
case DLL_PROCESS_ATTACH:
|
|
hInstance = hModule;
|
|
break;
|
|
case DLL_PROCESS_DETACH:
|
|
break;
|
|
case DLL_THREAD_ATTACH:
|
|
break;
|
|
case DLL_THREAD_DETACH:
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
API_DECLSPEC BOOL WINAPI CreateMagWindow(
|
|
UINT frameRate,
|
|
const wchar_t* effectsJson,
|
|
bool noDisturb
|
|
) {
|
|
try {
|
|
HWND hwnd = GetForegroundWindow();
|
|
Debug::ThrowIfWin32Failed(
|
|
hwnd,
|
|
L"GetForegroundWindow 返回 NULL"
|
|
);
|
|
|
|
MagWindow::CreateInstance(hInstance, hwnd, frameRate, effectsJson, noDisturb);
|
|
} catch(const magpie_exception&) {
|
|
return FALSE;
|
|
} catch (...) {
|
|
Debug::WriteErrorMessage(L"创建全屏窗口发生未知错误");
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
API_DECLSPEC BOOL WINAPI HasMagWindow() {
|
|
return MagWindow::$instance != nullptr;
|
|
}
|
|
|
|
API_DECLSPEC void WINAPI DestroyMagWindow() {
|
|
MagWindow::$instance = nullptr;
|
|
}
|
|
|
|
|
|
API_DECLSPEC const WCHAR* WINAPI GetLastErrorMsg() {
|
|
return Debug::GetLastErrorMessage().c_str();
|
|
}
|
|
|
|
|
|
API_DECLSPEC HWND WINAPI GetSrcWnd() {
|
|
if (MagWindow::$instance == nullptr) {
|
|
return NULL;
|
|
}
|
|
|
|
return MagWindow::$instance->GetSrcWnd();
|
|
}
|
|
|
|
API_DECLSPEC UINT32 WINAPI GetSrcPID() {
|
|
HWND hwndSrc = GetSrcWnd();
|
|
DWORD pid = 0;
|
|
GetWindowThreadProcessId(hwndSrc, &pid);
|
|
|
|
return pid;
|
|
}
|
|
|
|
API_DECLSPEC HWND WINAPI GetHostWnd() {
|
|
if (MagWindow::$instance == nullptr) {
|
|
return NULL;
|
|
}
|
|
|
|
return MagWindow::$instance->GetHostWnd();
|
|
} |