edit window find

master
cast1e 2024-09-25 11:30:45 +08:00
parent 3cab50bf00
commit 4b38706805
6 changed files with 43 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -20,9 +20,9 @@ BOOL APIENTRY DllMain( HMODULE hModule,
playerInstance* player_instance = NULL;
extern "C" __declspec(dllexport) void init(const char* ffpath,const char* videoPath, BOOL mute) {
extern "C" __declspec(dllexport) BOOL init(const char* ffpath,const char* videoPath, BOOL mute) {
player_instance = new playerInstance(conFig(ffpath, videoPath, mute));
player_instance->generate();
return player_instance->generate();
}
extern "C" __declspec(dllexport) void destroy() {

View File

@ -1,5 +1,7 @@
#include "pch.h"
#include "playerInstance.h"
#include <chrono>
#include <thread>
playerInstance::playerInstance(const conFig& config) {
this->config = config;
@ -16,6 +18,33 @@ static BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM Lparam) {
return TRUE;
}
HWND findWindowTimeOut(const wchar_t* name, int timeoutMillis) {
auto start = std::chrono::steady_clock::now();
HWND hwnd = nullptr;
while (true) {
// 使用 FindWindowW 查找窗口
hwnd = FindWindowW(name, 0);
// 如果找到窗口,则返回
if (hwnd != nullptr) {
return hwnd;
}
// 计算当前经过的时间
auto now = std::chrono::steady_clock::now();
int elapsedMillis = std::chrono::duration_cast<std::chrono::milliseconds>(now - start).count();
// 如果超时,则返回 nullptr
if (elapsedMillis > timeoutMillis) {
return nullptr;
}
// 等待一段时间例如100毫秒再尝试查找
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
BOOL playerInstance::showWindow(LPCWSTR lpParameter) {
if (this->hFfplay != NULL) {
DWORD dwPID = 0;
@ -29,10 +58,14 @@ BOOL playerInstance::showWindow(LPCWSTR lpParameter) {
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窗口
//Sleep(600);//等待视频播放器启动完成
//HWND hProgman = FindWindow(L"Progman", 0);// 找到PI窗口
HWND hProgman = findWindowTimeOut(L"Progman",1000);
if (hProgman == nullptr) return FALSE;
SendMessageTimeout(hProgman, 0x052c, 0, 0, 0, 100, 0);// 给它发特殊消息
this->hFfplay = FindWindowW(L"SDL_app", 0);// 找到视频窗口
//this->hFfplay = FindWindowW(L"SDL_app", 0);// 找到视频窗口
this->hFfplay = findWindowTimeOut(L"SDL_app", 1000);
if (this->hFfplay == nullptr) return FALSE;
SetParent(hFfplay, hProgman);// 将视频窗口设苦为PM的子窗口
int systemWidth = GetSystemMetrics(0);
int systemHeight = GetSystemMetrics(1);
@ -49,6 +82,8 @@ BOOL playerInstance::showWindow(LPCWSTR lpParameter) {
MoveWindow(hFfplay, 0, x, cRct.right - cRct.left, cRct.bottom - cRct.top, 0);
}*/
EnumWindows(EnumWindowsProc, 0);// 找到第二个workerw窗口并隐藏它
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return TRUE;
}
CloseHandle(pi.hProcess);
@ -56,7 +91,7 @@ BOOL playerInstance::showWindow(LPCWSTR lpParameter) {
return FALSE;
}
void playerInstance::generate() {
BOOL playerInstance::generate() {
std::wstring fcmd = L" \"";
fcmd += this->config.videoPath + L"\"";
fcmd += L" -noborder -loop 0";
@ -64,7 +99,7 @@ void playerInstance::generate() {
fcmd += L" -an";
}
fcmd += L" -fs";
this->showWindow(fcmd.c_str());
return this->showWindow(fcmd.c_str());
}
void playerInstance::exit() {

View File

@ -9,7 +9,7 @@ private:
public:
playerInstance(const conFig& config);
BOOL showWindow(LPCWSTR lpParameter);
void generate();
BOOL generate();
void exit();
};