From 290b8b0a7acab272cdbe878d83d1bcf56fadf53f Mon Sep 17 00:00:00 2001 From: cast1e Date: Tue, 24 Sep 2024 20:34:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conFig.cpp | 22 +++++ conFig.h | 13 +++ dllmain.cpp | 31 +++++++ framework.h | 5 ++ pch.cpp | 5 ++ pch.h | 13 +++ playerInstance.cpp | 78 ++++++++++++++++ playerInstance.h | 15 ++++ wallitor-core.sln | 31 +++++++ wallitor-core.vcxproj | 161 ++++++++++++++++++++++++++++++++++ wallitor-core.vcxproj.filters | 45 ++++++++++ 11 files changed, 419 insertions(+) create mode 100644 conFig.cpp create mode 100644 conFig.h create mode 100644 dllmain.cpp create mode 100644 framework.h create mode 100644 pch.cpp create mode 100644 pch.h create mode 100644 playerInstance.cpp create mode 100644 playerInstance.h create mode 100644 wallitor-core.sln create mode 100644 wallitor-core.vcxproj create mode 100644 wallitor-core.vcxproj.filters diff --git a/conFig.cpp b/conFig.cpp new file mode 100644 index 0000000..e15e7a7 --- /dev/null +++ b/conFig.cpp @@ -0,0 +1,22 @@ +#include "pch.h" +#include "conFig.h" + +conFig::conFig(const char* ffpath,const char* videoPath, BOOL mute) { + std::string tmp =ffpath; + this->ffpath = std::wstring(tmp.begin(), tmp.end()); + tmp = videoPath; + this->videoPath = std::wstring(tmp.begin(), tmp.end()); + this->mute = mute; +} + +conFig::conFig(const conFig& config) { + this->ffpath = config.ffpath; + this->mute = config.mute; + this->videoPath = config.videoPath; +} + +conFig::conFig() { + this->ffpath = L""; + this->mute = TRUE; + this->videoPath = L""; +} diff --git a/conFig.h b/conFig.h new file mode 100644 index 0000000..f4c77fb --- /dev/null +++ b/conFig.h @@ -0,0 +1,13 @@ +#pragma once +#include +class conFig +{ +public: + std::wstring ffpath; + std::wstring videoPath; + BOOL mute; + conFig(const char* ffpath, const char* videoPath,BOOL mute); + conFig(const conFig& config); + conFig(); +}; + diff --git a/dllmain.cpp b/dllmain.cpp new file mode 100644 index 0000000..67fdab4 --- /dev/null +++ b/dllmain.cpp @@ -0,0 +1,31 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" +#include "playerInstance.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + +playerInstance* player_instance = NULL; + + extern "C" __declspec(dllexport) void init(const char* ffpath,const char* videoPath, BOOL mute) { + player_instance = new playerInstance(conFig(ffpath, videoPath, mute)); + player_instance->generate(); +} + + extern "C" __declspec(dllexport) void destory() { + player_instance->exit(); + delete player_instance; + } diff --git a/framework.h b/framework.h new file mode 100644 index 0000000..80cbbc9 --- /dev/null +++ b/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/pch.cpp b/pch.cpp new file mode 100644 index 0000000..b6fb8f4 --- /dev/null +++ b/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: 与预编译标头对应的源文件 + +#include "pch.h" + +// 当使用预编译的头时,需要使用此源文件,编译才能成功。 diff --git a/pch.h b/pch.h new file mode 100644 index 0000000..9660927 --- /dev/null +++ b/pch.h @@ -0,0 +1,13 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +// 添加要在此处预编译的标头 +#include "framework.h" + +#endif //PCH_H diff --git a/playerInstance.cpp b/playerInstance.cpp new file mode 100644 index 0000000..690ed91 --- /dev/null +++ b/playerInstance.cpp @@ -0,0 +1,78 @@ +#include "pch.h" +#include "playerInstance.h" + +playerInstance::playerInstance(const conFig& config) { + this->config = config; + this->hFfplay = NULL; +} + +static BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM Lparam) { + HWND hDefView = FindWindowEx(hwnd, 0, L"SHELLDLL_DefView", 0); + if (hDefView != 0) { + HWND hWorkerw = FindWindowEx(0, hwnd, L"WorkerW", 0); + ShowWindow(hWorkerw, SW_HIDE); + return FALSE; + } + return TRUE; +} + +BOOL playerInstance::showWindow(LPCWSTR lpParameter) { + if (this->hFfplay != NULL) { + DWORD dwPID = 0; + GetWindowThreadProcessId(hFfplay, &dwPID); + char strCmd[MAX_PATH] = { 0 }; + sprintf_s(strCmd, "taskkill /pid %d -f", dwPID); + system(strCmd); + } + STARTUPINFO si{ 0 }; + //si.dwFlags = STARTF_USESHOWWINDOW; + si.wShowWindow = SW_HIDE; + PROCESS_INFORMATION pi{ 0 }; + if (CreateProcess(this->config.ffpath.c_str(), (LPWSTR)lpParameter, 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &si, &pi)) { + Sleep(600);//ȴƵ + HWND hProgman = FindWindow(L"Progman", 0);// ҵPI + SendMessageTimeout(hProgman, 0x052c, 0, 0, 0, 100, 0);// Ϣ + this->hFfplay = FindWindowW(L"SDL_app", 0);// ҵƵ + SetParent(hFfplay, hProgman);// ƵΪPMӴ + int systemWidth = GetSystemMetrics(0); + int systemHeight = GetSystemMetrics(1); + RECT cRct; + GetWindowRect(hFfplay, &cRct); + //if (horw) { + int width = cRct.right - cRct.left; + int x = (systemWidth - width) / 2; + MoveWindow(hFfplay, x, 0, cRct.right - cRct.left, cRct.bottom - cRct.top, 1); + /* } + else { + int height = cRct.bottom - cRct.top; + int x = (sheight - height) / 2; + MoveWindow(hFfplay, 0, x, cRct.right - cRct.left, cRct.bottom - cRct.top, 0); + }*/ + EnumWindows(EnumWindowsProc, 0);// ҵڶworkerwڲ + return TRUE; + } + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + return FALSE; +} + +void playerInstance::generate() { + std::wstring fcmd = L" \""; + fcmd += this->config.videoPath + L"\""; + fcmd += L" -noborder -loop 0"; + if (this->config.mute) { + fcmd += L" -an"; + } + fcmd += L" -fs"; + this->showWindow(fcmd.c_str()); +} + +void playerInstance::exit() { + if (this->hFfplay != NULL) { + DWORD dwPID = 0; + GetWindowThreadProcessId(this->hFfplay, &dwPID); + char strCmd[MAX_PATH] = { 0 }; + sprintf_s(strCmd, "taskkill /pid %d -f", dwPID); + system(strCmd); + } +} \ No newline at end of file diff --git a/playerInstance.h b/playerInstance.h new file mode 100644 index 0000000..f3c9434 --- /dev/null +++ b/playerInstance.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include "conFig.h" +class playerInstance +{ +private: + HWND hFfplay; + conFig config; +public: + playerInstance(const conFig& config); + BOOL showWindow(LPCWSTR lpParameter); + void generate(); + void exit(); +}; + diff --git a/wallitor-core.sln b/wallitor-core.sln new file mode 100644 index 0000000..4497a46 --- /dev/null +++ b/wallitor-core.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wallitor-core", "wallitor-core.vcxproj", "{36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}.Debug|x64.ActiveCfg = Debug|x64 + {36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}.Debug|x64.Build.0 = Debug|x64 + {36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}.Debug|x86.ActiveCfg = Debug|Win32 + {36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}.Debug|x86.Build.0 = Debug|Win32 + {36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}.Release|x64.ActiveCfg = Release|x64 + {36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}.Release|x64.Build.0 = Release|x64 + {36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}.Release|x86.ActiveCfg = Release|Win32 + {36591862-6F9C-4A1D-BBAD-4B1CBB1EC24B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0AC7BD09-A02A-48D9-93B8-2DD23902B6AC} + EndGlobalSection +EndGlobal diff --git a/wallitor-core.vcxproj b/wallitor-core.vcxproj new file mode 100644 index 0000000..a40ccaf --- /dev/null +++ b/wallitor-core.vcxproj @@ -0,0 +1,161 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {36591862-6f9c-4a1d-bbad-4b1cbb1ec24b} + wallitorcore + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;WALLITORCORE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + + + + + Level3 + true + true + true + WIN32;NDEBUG;WALLITORCORE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + + + + + Level3 + true + _DEBUG;WALLITORCORE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + + + + + Level3 + true + true + true + NDEBUG;WALLITORCORE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + \ No newline at end of file diff --git a/wallitor-core.vcxproj.filters b/wallitor-core.vcxproj.filters new file mode 100644 index 0000000..bff130d --- /dev/null +++ b/wallitor-core.vcxproj.filters @@ -0,0 +1,45 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + \ No newline at end of file