Knowledge Base Nr: 00268 wmppos.cpp - http://www.swe-kaiser.de

Downloads:

Win32: Windows Media Player 9 Filmposition mit C-Programm setzen (Fenster(Slider) suchen und mit Maus fernbedienen)

  
int CMySocketServer::DoWMPPos(int nNewPosX) //ACHTUNG funzt nur für Windows Media Player!!!!
{
HWND hwnd = ::FindWindow("WMP Skin Host", "Windows Media Player");
TRACE("FindWindow = 0x%p\n", hwnd);
if (!hwnd)
{
ASSERT(FALSE);
return -1;
}

//falls noch nicht geschehen und kein anderes fenster (z.b. debugger):
HWND hwndOrg = ::GetForegroundWindow();

BOOL bSucc = ::SetForegroundWindow(hwnd);
TRACE("SetForegroundWindow = %d\n", bSucc);

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

/*
//slider-offsets für kleinste fensterdarstellung mit spy++ ermittelt!
int nStartPosX = rect.left + 300;
int nMaxPosX = rect.left + 550;
int nStartPosY = rect.top + 285;
int nMaxPosY = rect.top + 295;
*/
//slider-offsets für beliebige fensterdarstellung mit spy++ ermittelt!
int nStartPosX = rect.left + 304;
int nMaxPosX = rect.right - 305;
int nStartPosY = rect.bottom - 180;
int nMaxPosY = rect.bottom - 174;

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

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

POINT ptOrg;
::GetCursorPos(&ptOrg);

TRACE("SetCursorPos(%d, %d", nPosX, nPosY);
::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);

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
);
Sleep(100);

//alten zustand wiederherstellen
::SetForegroundWindow(hwndOrg);
::SetCursorPos(ptOrg.x, ptOrg.y);

return 0;
}