75 lines
2.3 KiB
C++
Raw Normal View History

2024-01-08 23:37:00 +08:00
// magpiecmdrunner.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
2024-04-02 15:36:52 +08:00
#include <windows.h>
2024-01-08 23:37:00 +08:00
typedef BOOL (*Initialize)(
UINT logLevel,
2024-04-02 15:36:52 +08:00
const char *logFileName,
2024-01-08 23:37:00 +08:00
int logArchiveAboveSize,
2024-04-02 15:36:52 +08:00
int logMaxArchiveFiles);
typedef const char *(*Run)(
2024-01-08 23:37:00 +08:00
HWND hwndSrc,
2024-04-02 15:36:52 +08:00
const char *effectsJson,
2024-01-08 23:37:00 +08:00
UINT flags,
UINT captureMode,
2024-04-02 15:36:52 +08:00
float cursorZoomFactor, // 负数和 0和源窗口相同正数缩放比例
UINT cursorInterpolationMode, // 0最近邻1双线性
2024-01-08 23:37:00 +08:00
int adapterIdx,
2024-04-02 15:36:52 +08:00
UINT multiMonitorUsage, // 0最近 1相交 2所有
2024-01-08 23:37:00 +08:00
UINT cropLeft,
UINT cropTop,
UINT cropRight,
2024-04-02 15:36:52 +08:00
UINT cropBottom);
int magpiewmain(int argc, wchar_t *wargv[])
2024-01-08 23:37:00 +08:00
{
UINT codepage = GetACP();
2024-04-02 15:36:52 +08:00
char **argv = new char *[argc];
2024-01-08 23:37:00 +08:00
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);
}
2024-04-02 15:36:52 +08:00
FILE *fp;
2024-01-08 23:37:00 +08:00
fopen_s(&fp, argv[1], "r");
2024-04-02 15:36:52 +08:00
if (fp == 0)
return 0;
char cache[4096] = {0};
char magpiepath[4096] = {0};
2024-01-08 23:37:00 +08:00
HWND m_hWnd;
2024-04-02 15:36:52 +08:00
char effect[4096] = {0};
2024-01-08 23:37:00 +08:00
int flags, captureMode, CursorInterpolationMode, AdapterIdx, MultiMonitorUsage;
float CursorZoomFactor;
fgets(magpiepath, 4096, fp);
2024-04-02 15:36:52 +08:00
magpiepath[strlen(magpiepath) - 1] = 0;
2024-01-08 23:37:00 +08:00
fgets(cache, 4096, fp);
2024-04-02 15:36:52 +08:00
sscanf_s(cache, "%lld\n", &m_hWnd);
2024-01-08 23:37:00 +08:00
fgets(effect, 4096, fp);
2024-04-02 15:36:52 +08:00
effect[strlen(effect) - 1] = 0;
2024-01-08 23:37:00 +08:00
fgets(cache, 4096, fp);
sscanf_s(cache, "%d,%d,%f,%d,%d,%d",
2024-04-02 15:36:52 +08:00
&flags, &captureMode, &CursorZoomFactor, &CursorInterpolationMode, &AdapterIdx, &MultiMonitorUsage);
2024-01-08 23:37:00 +08:00
2024-04-02 15:36:52 +08:00
fclose(fp);
2024-01-08 23:37:00 +08:00
/*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");
2024-04-02 15:36:52 +08:00
// printf("%d\n", h);
if (h == 0)
return 0;
2024-01-08 23:37:00 +08:00
Initialize Initialize_f = (Initialize)GetProcAddress(h, "Initialize");
Run Run_f = (Run)GetProcAddress(h, "Run");
SetProcessDPIAware();
2024-04-02 15:36:52 +08:00
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);
2024-01-08 23:37:00 +08:00
}