CompareWav/Compare.c

228 lines
6.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.

// Compare.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <winuser.h>
#include <psapi.h>
#pragma comment(lib, "Winmm.lib")
//#define DEBUG_PRINTF 1
typedef enum {
REGIM_INIT = 0,
REGIM_COMPARE = 1,
REGIM_RESULT = 2
} eRegim;
typedef struct {
RECT winRect;
eRegim regim;
wchar_t captionWindow[_MAX_PATH];
wchar_t pathWav1[_MAX_PATH];
wchar_t pathWav2[_MAX_PATH];
} tCompareStruct;
static BOOL CALLBACK enum_wnd_proc(HWND hwnd, LPARAM lParam) {
tCompareStruct* compareStruct = (tCompareStruct*)lParam;
wchar_t classText[_MAX_PATH];
RECT Rect;
GetClassName(hwnd, classText, _MAX_PATH);
GetWindowRect(hwnd, &Rect);
LONG LocalTop = Rect.top - compareStruct->winRect.top;
#ifdef DEBUG_PRINTF
printf("HWND = %u, CLASS = %ls, GlobalTop = %d LocallTop = %d\n", hwnd, classText, Rect.top, LocalTop);
#endif
if (compareStruct->regim == REGIM_INIT) {
if ((wcscmp(classText, L"Edit") == 0) && (LocalTop == 37)) {
#ifdef DEBUG_PRINTF
printf("Edit1 found!\n");
#endif
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)compareStruct->pathWav1);
}
if ((wcscmp(classText, L"Edit") == 0) && (LocalTop == 73)) {
#ifdef DEBUG_PRINTF
printf("Edit2 found!\n");
#endif
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)compareStruct->pathWav2);
}
if ((wcscmp(classText, L"ComboBox") == 0) && (LocalTop == 109)) {
#ifdef DEBUG_PRINTF
printf("ComboBox1 found!\n");
#endif
ComboBox_SetCurSel(hwnd, 1);
}
if ((wcscmp(classText, L"ComboBox") == 0) && (LocalTop == 184)) {
#ifdef DEBUG_PRINTF
printf("ComboBox2 found!\n");
#endif
ComboBox_SetCurSel(hwnd, 1);
}
if ((wcscmp(classText, L"Static") == 0) && (LocalTop == 218)) {
#ifdef DEBUG_PRINTF
printf("Static found!\n");
#endif
wchar_t text[_MAX_PATH];
wcscpy_s(text, _MAX_PATH, L" -200.0%");
SetWindowTextW(hwnd, (LPCWSTR)text);
}
}
if (compareStruct->regim == REGIM_COMPARE) {
if ((wcscmp(classText, L"Button") == 0) && (LocalTop == 221)) {
#ifdef DEBUG_PRINTF
printf("Button found!\n");
#endif
LONG lParam = MAKELONG(243, 28);
SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, lParam);
SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, lParam);
SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, lParam);
Sleep(100);
SendMessage(hwnd, WM_LBUTTONUP, MK_LBUTTON, lParam);
SendMessage(hwnd, WM_LBUTTONUP, MK_LBUTTON, lParam);
SendMessage(hwnd, WM_LBUTTONUP, MK_LBUTTON, lParam);
}
}
if (compareStruct->regim == REGIM_RESULT) {
if ((wcscmp(classText, L"Static") == 0) && (LocalTop == 218)) {
#ifdef DEBUG_PRINTF
printf("Static found!\n");
#endif
wchar_t text[_MAX_PATH];
for (int i = 0; i < 50; ++i) {
GetWindowTextW(hwnd, (LPCWSTR)text, _MAX_PATH);
if (wcscmp(text, L" -200.0%") == 0) {
Sleep(100);
}
else {
break;
}
}
printf("Similarity Score:%ls\n", text);
}
}
return TRUE;
}
static void CALLBACK TimerUpdate(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dwl, DWORD dw2) {
tCompareStruct* compareStruct = (tCompareStruct*)dwUser;
HWND hwnd = FindWindowW(NULL, compareStruct->captionWindow);
if (hwnd != NULL) {
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
return;
}
int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) {
tCompareStruct compareStruct;
wchar_t captionWindow[_MAX_PATH];
wcscpy_s(captionWindow, _MAX_PATH, L"Sound-Similar 1.1 (Free Version) by Virtins Technology");
UINT timerUpdate = 0;
if (argc != 3) {
printf("Error: Invalid parameters\n");
return 1;
}
wcscpy_s(compareStruct.pathWav1, _MAX_PATH, argv[1]);
wcscpy_s(compareStruct.pathWav2, _MAX_PATH, argv[2]);
HWND hwnd = FindWindowW(NULL, captionWindow);
if (hwnd == NULL) {
WinExec("Sound-Similar-Free.exe", SW_SHOWNORMAL);
for (int i = 0; i < 500; ++i) {
hwnd = FindWindowW(NULL, captionWindow);
if (IsWindowVisible(hwnd) == TRUE) {
ShowWindow(hwnd, SW_HIDE);
break;
}
Sleep(1);
}
}
if (hwnd != NULL) {
DWORD hprocessId = 0;
GetWindowThreadProcessId(hwnd, &hprocessId);
HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, hprocessId);
GetModuleFileNameExW(processHandle, NULL, compareStruct.captionWindow, _MAX_PATH);
timerUpdate = timeSetEvent(50, 0, (LPTIMECALLBACK)TimerUpdate, (DWORD_PTR)&compareStruct, TIME_PERIODIC);
GetWindowRect(hwnd, &compareStruct.winRect);
compareStruct.regim = REGIM_INIT;
EnumChildWindows(hwnd, enum_wnd_proc, (LPARAM)(&compareStruct));
Sleep(200);
compareStruct.regim = REGIM_COMPARE;
EnumChildWindows(hwnd, enum_wnd_proc, (LPARAM)(&compareStruct));
compareStruct.regim = REGIM_RESULT;
EnumChildWindows(hwnd, enum_wnd_proc, (LPARAM)(&compareStruct));
timeKillEvent(timerUpdate);
//PostMessage(hwnd, WM_CLOSE, 0, 0);
}
else {
printf("Error: Window not found\n");
return 2;
}
}
// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
// Советы по началу работы
// 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
// 2. В окне Team Explorer можно подключиться к системе управления версиями.
// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
// 4. В окне "Список ошибок" можно просматривать ошибки.
// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.