edit window find
parent
3cab50bf00
commit
4b38706805
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -20,9 +20,9 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
||||||
|
|
||||||
playerInstance* player_instance = NULL;
|
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 = new playerInstance(conFig(ffpath, videoPath, mute));
|
||||||
player_instance->generate();
|
return player_instance->generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" __declspec(dllexport) void destroy() {
|
extern "C" __declspec(dllexport) void destroy() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "playerInstance.h"
|
#include "playerInstance.h"
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
playerInstance::playerInstance(const conFig& config) {
|
playerInstance::playerInstance(const conFig& config) {
|
||||||
this->config = config;
|
this->config = config;
|
||||||
|
|
@ -16,6 +18,33 @@ static BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM Lparam) {
|
||||||
return TRUE;
|
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) {
|
BOOL playerInstance::showWindow(LPCWSTR lpParameter) {
|
||||||
if (this->hFfplay != NULL) {
|
if (this->hFfplay != NULL) {
|
||||||
DWORD dwPID = 0;
|
DWORD dwPID = 0;
|
||||||
|
|
@ -29,10 +58,14 @@ BOOL playerInstance::showWindow(LPCWSTR lpParameter) {
|
||||||
si.wShowWindow = SW_HIDE;
|
si.wShowWindow = SW_HIDE;
|
||||||
PROCESS_INFORMATION pi{ 0 };
|
PROCESS_INFORMATION pi{ 0 };
|
||||||
if (CreateProcess(this->config.ffpath.c_str(), (LPWSTR)lpParameter, 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &si, &pi)) {
|
if (CreateProcess(this->config.ffpath.c_str(), (LPWSTR)lpParameter, 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &si, &pi)) {
|
||||||
Sleep(600);//等待视频播放器启动完成
|
//Sleep(600);//等待视频播放器启动完成
|
||||||
HWND hProgman = FindWindow(L"Progman", 0);// 找到PI窗口
|
//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);// 给它发特殊消息
|
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的子窗口
|
SetParent(hFfplay, hProgman);// 将视频窗口设苦为PM的子窗口
|
||||||
int systemWidth = GetSystemMetrics(0);
|
int systemWidth = GetSystemMetrics(0);
|
||||||
int systemHeight = GetSystemMetrics(1);
|
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);
|
MoveWindow(hFfplay, 0, x, cRct.right - cRct.left, cRct.bottom - cRct.top, 0);
|
||||||
}*/
|
}*/
|
||||||
EnumWindows(EnumWindowsProc, 0);// 找到第二个workerw窗口并隐藏它
|
EnumWindows(EnumWindowsProc, 0);// 找到第二个workerw窗口并隐藏它
|
||||||
|
CloseHandle(pi.hProcess);
|
||||||
|
CloseHandle(pi.hThread);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
|
|
@ -56,7 +91,7 @@ BOOL playerInstance::showWindow(LPCWSTR lpParameter) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void playerInstance::generate() {
|
BOOL playerInstance::generate() {
|
||||||
std::wstring fcmd = L" \"";
|
std::wstring fcmd = L" \"";
|
||||||
fcmd += this->config.videoPath + L"\"";
|
fcmd += this->config.videoPath + L"\"";
|
||||||
fcmd += L" -noborder -loop 0";
|
fcmd += L" -noborder -loop 0";
|
||||||
|
|
@ -64,7 +99,7 @@ void playerInstance::generate() {
|
||||||
fcmd += L" -an";
|
fcmd += L" -an";
|
||||||
}
|
}
|
||||||
fcmd += L" -fs";
|
fcmd += L" -fs";
|
||||||
this->showWindow(fcmd.c_str());
|
return this->showWindow(fcmd.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void playerInstance::exit() {
|
void playerInstance::exit() {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ private:
|
||||||
public:
|
public:
|
||||||
playerInstance(const conFig& config);
|
playerInstance(const conFig& config);
|
||||||
BOOL showWindow(LPCWSTR lpParameter);
|
BOOL showWindow(LPCWSTR lpParameter);
|
||||||
void generate();
|
BOOL generate();
|
||||||
void exit();
|
void exit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue