Knowledge Base Nr: 00234 windvdpos.cpp - http://www.swe-kaiser.de

Downloads:

Win32: WinDVD Filmposition von C-Programm setzen (Fenster(Slider) suchen und mit Maus fernbedienen)

  
#define DVDPLAYERCLASS "WinDVDClass"
#define DVDPLAYERWNAME "player"

int g_nSearchCount = 0;
HWND g_hwndSearch = 0;

void CCursortestDlg::OnButton2()
{
////windvd-fenster suchen und in den vordergrund schicken
HWND hwnd = ::FindWindow(DVDPLAYERCLASS, DVDPLAYERWNAME);
DoLog("FindWindow = 0x%p", hwnd);
if (!hwnd)
{
ASSERT(FALSE);
return;
}

BOOL bSucc = ::SetForegroundWindow(hwnd);
DoLog("SetForegroundWindow = %d", bSucc);
if (!bSucc)
{
ASSERT(FALSE);
return;
}

///slidercontrol für filmposition suchen (player muss eingeschaltet sein)
g_nSearchCount = 1;
g_hwndSearch = 0;
bSucc = EnumChildWindows(hwnd, MyEnumChildProc, (long)(void*)"AfxOleControl42###");
if (!g_hwndSearch)
{
ASSERT(FALSE);
return;
}

hwnd = g_hwndSearch;
g_nSearchCount = 3;
g_hwndSearch = 0;
bSucc = EnumChildWindows(hwnd, MyEnumChildProc, (long)(void*)"*###CSLDWND");
if (!g_hwndSearch)
{
ASSERT(FALSE);
return;
}

////fenstergröße und position des sliders ermitteln

/*
mit winspy ermittelt:
child: 1.class:"AfxOleControl42"
child: 3.title: "CSLDWND"
54,660,455,670 -> 401,10

WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
bSucc = ::GetWindowPlacement(g_hwndSearch, &wp);
*/

RECT rect;
bSucc = ::GetWindowRect(g_hwndSearch, &rect);
if (!bSucc)
{
ASSERT(FALSE);
return;
}

int nStartPosX = rect.left;
int nMaxPosX = rect.right;
int nStartPosY = rect.top;
int nMaxPosY = rect.bottom;

int nWidthX = nMaxPosX-nStartPosX;
int nPosY = nStartPosY + ((nMaxPosY-nStartPosY)/2);

CString strPosX;
GetDlgItem(IDC_EDIT3)->GetWindowText(strPosX);

int nNewWidth = ((0.0+nWidthX)/100.0) * atoi(strPosX);
int nPosX = nStartPosX + nNewWidth;
if (nPosX >= nMaxPosX)
nPosX = nMaxPosX-1;

////maustaste drücken, gedrückt halten und vorm loslassen leicht versetzen (windvd positioniert sonst nicht absolut)
::SetCursorPos(nPosX, nPosY);

mouse_event(MOUSEEVENTF_LEFTDOWN, // motion and click options
0, // horizontal position or change
0, // vertical position or change
0, // wheel movement
NULL // application-defined information
);

Sleep(100);
::SetCursorPos(nPosX+2, nPosY);

mouse_event(MOUSEEVENTF_LEFTUP, // motion and click options
0, // horizontal position or change
0, // vertical position or change
0, // wheel movement
NULL // application-defined information
);
}

BOOL CALLBACK CCursortestDlg::MyEnumChildProc(HWND hwnd, LPARAM lParam)
{
char szClass[100] = {0};
char szText[100] = {0};

::GetClassName(hwnd, szClass, sizeof(szClass));
::GetWindowText(hwnd, szText, sizeof(szText));
TRACE("\nwnd:0x%p lparam:%s class:%s wndtext:%s", hwnd, lParam, szClass, szText);

char szSearch[200] = {0};
CString str((const char*)lParam);
int nDelim = str.Find("###");
ASSERT(nDelim >= 0);

if (str[0] == '*') //alle klassen
{
if (nDelim+3 >= str.GetLength()) //kein name
sprintf(szSearch, "*###%s", szText);
else if (str[nDelim+3] == '*') //alle namen
sprintf(szSearch, "*###*");
else
sprintf(szSearch, "*###%s", szText);
}
else
{
if (nDelim+3 >= str.GetLength()) //kein name
sprintf(szSearch, "%s###%s", szClass, szText);
else if (str[nDelim+3] == '*') //alle namen
sprintf(szSearch, "%s###*", szClass);
else
sprintf(szSearch, "%s###%s", szClass, szText);
}

if (strcmp((const char*)lParam, szSearch) == 0)
{
TRACE(" ==> hit (%d)!", g_nSearchCount);
if (--g_nSearchCount <= 0)
{
TRACE(" ==> found&exit!", g_nSearchCount);
g_hwndSearch = hwnd;
return FALSE;
}
}

return TRUE;
}