恍兮惚兮 98a5697bcc format
2024-04-02 18:02:06 +08:00

75 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// magpiecmdrunner.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <windows.h>
typedef BOOL (*Initialize)(
UINT logLevel,
const char *logFileName,
int logArchiveAboveSize,
int logMaxArchiveFiles);
typedef const char *(*Run)(
HWND hwndSrc,
const char *effectsJson,
UINT flags,
UINT captureMode,
float cursorZoomFactor, // 负数和 0和源窗口相同正数缩放比例
UINT cursorInterpolationMode, // 0最近邻1双线性
int adapterIdx,
UINT multiMonitorUsage, // 0最近 1相交 2所有
UINT cropLeft,
UINT cropTop,
UINT cropRight,
UINT cropBottom);
int magpiewmain(int argc, wchar_t *wargv[])
{
UINT codepage = GetACP();
char **argv = new char *[argc];
for (int i = 0; i < argc; i++)
{
int length = WideCharToMultiByte(codepage, 0, wargv[i], -1, NULL, 0, NULL, NULL);
argv[i] = new char[length];
WideCharToMultiByte(codepage, 0, wargv[i], -1, argv[i], length, NULL, NULL);
}
FILE *fp;
fopen_s(&fp, argv[1], "r");
if (fp == 0)
return 0;
char cache[4096] = {0};
char magpiepath[4096] = {0};
HWND m_hWnd;
char effect[4096] = {0};
int flags, captureMode, CursorInterpolationMode, AdapterIdx, MultiMonitorUsage;
float CursorZoomFactor;
fgets(magpiepath, 4096, fp);
magpiepath[strlen(magpiepath) - 1] = 0;
fgets(cache, 4096, fp);
sscanf_s(cache, "%lld\n", &m_hWnd);
fgets(effect, 4096, fp);
effect[strlen(effect) - 1] = 0;
fgets(cache, 4096, fp);
sscanf_s(cache, "%d,%d,%f,%d,%d,%d",
&flags, &captureMode, &CursorZoomFactor, &CursorInterpolationMode, &AdapterIdx, &MultiMonitorUsage);
fclose(fp);
/*printf("%s\n%s\n", magpiepath, effect);
printf("%d,%d,%d,%d,%d,%d,%d", m_hWnd, flags, captureMode, CursorInterpolationMode, AdapterIdx, MultiMonitorUsage, CursorZoomFactor);*/
SetForegroundWindow(m_hWnd);
SetCurrentDirectoryA(magpiepath);
SetDllDirectoryA(magpiepath);
HMODULE h = LoadLibrary(L".\\MagpieRT.dll");
// printf("%d\n", h);
if (h == 0)
return 0;
Initialize Initialize_f = (Initialize)GetProcAddress(h, "Initialize");
Run Run_f = (Run)GetProcAddress(h, "Run");
SetProcessDPIAware();
auto _1 = Initialize_f(6, "./Runtime.log", 100000, 1);
auto _2 = Run_f(m_hWnd, effect, flags, captureMode, CursorZoomFactor, CursorInterpolationMode, AdapterIdx, MultiMonitorUsage, 0, 0, 0, 0);
// printf("%d %s\n", _1, _2);
}